Monday, February 18, 2008

Is it Basic or is it C? Its SEABASS

Personally, I like to program in C. Luckily, there is pretty good C language support for most modern microprocessors. However, if you don't know C, its a pretty steep learning curve. Sometimes you just want to bang something out quick.

If your processor wants you to use C but you want to use Basic, you might try Seabass. Seabass is a BASIC compiler that outputs C code. So anywhere you can compile a C program (even on Linux or Windows) you can write BASIC programs. Even better, Seabass integrates with existing C libraries and you can even embed C code in your program.

The link shows an entire article about using Seabass to produce some Morse code on an Atmel AVR and a PIC. Here's the first part of the AVR program:

include "avrio.bh"       ` get I/O routines
cinclude "app4delay.h" ` get delay routines (from C)
#link "app4delay.c" ` include C library
` Define a string type
deftype string char *
` Speed of a dot in milliseconds
Const speed=200

The first line includes a basic header file (by convention, these files have a .bh extension). This is a SeaBass file (included on the CDROM) that provides some common I/O routines for the APP-IV (the target board). This line allows us to use things like HIGH and LOW to affect the I/O pins.

The second line includes a C file, not a SeaBass file. This file is one that the APP-IV kit supplies and provides an easy way to write delays. Notice the line just under this tells the compiler where to find the associated C file. If you are manually compiling SeaBass' output, this isn't necessary, but if SeaBass controls the build process, this will allow it to automatically bring in the correct C code that your program needs.

Type names in SeaBass have to be a single word. However, many C types use multiple words (or even symbols). For example, if you want to deal with a string, in C you use a character pointer represented by "char *". The SeaBass DefType statement allows you to make a SeaBass type that represents a complex C type:

` Define a string type
deftype string char *

The final part of the initial part of the program sets a constant using Const. In this case, the speed value is set to 200 (this will be the number of milliseconds to delay for a dot).

Now it is very simple to understand the main code:

` Main program
function main() as int
dim text as string
dim i
text="-.-. --.-" ` message to send
` Set LED to output
OUTPUT(B,0)

The first two lines in the function define variables (notice one of them is a string).

Here's the main loop:

` Main code
top:
for i=0 to strlen(text)-1 ` walk through text
` do the right thing
if text[i]='.' then
dot()
end if
if text[i]='-' then
dash()
end if
if text[i]=' ' then
space()
end if
next

Notice that the program uses the C library call strlen to find the length of the string. Of course, you could write a version of strlen in SeaBass, but since the C compiler already has this function, why not use it?


You can read the whole article or look at an example with an LCD library. You can also play with a demo of Seabass online.

Labels: , ,

Submit to:   book mark Is it Basic or is it C? Its SEABASS in del.icio.usDel.icio.us  |   submit Is it Basic or is it C? Its SEABASS to digg.comDigg  |   submit Is it Basic or is it C? Its SEABASS to slashdot.comSlashdot  |  diigo itDiigo

Sunday, February 03, 2008

An Easy Robot



This little robot is made with two perf boards from Radio Shack (one of them cut into two for the sides). This board is easy to work with because it has a grid of holes. It is very easy to make nice straight cuts (or even just score and snap). It is also perfect for drilling exact holes. Basswood and polyurethane glue holds it all together (along with a few screws).

The drive consists of two Futuba RC servos modified for continuous rotation and a caster wheel from Home Depot in the rear. The tires are 2.25" RC aircraft tires.

A 4xAA holder under the top deck powers the motors. The 9V battery on the top is just for the electronics.

The electronics is the GP3 board which has been programmed by the GP3EZ software so programming the robot is simple point and click.

The sensor is a Panasonic IR sensor tuned for about 38kHz. The IR LED is pulsed through a 2N2222 with the GP3's PWM at 32kHz which is close enough that it works. A piece of antistatic foam pushed into a pin header blocks the sensor from seeing the LED directly. When something is in front of the bot, it sees the IR bounce off of it. It would be easy to add more LEDs (for example, two on the corners). The sensors could be paralleled or just connected to more I/O pins.

Here's the software (dumped out to HTML by GP3EZ; the real software is all constructed using GP3EZ's point and click interface):


Step #TagConditionActionNextNotes
1StartAlways
LED Off
PWM: 200 freq=32766
 Start IR and reset LED (for when we finish turning)
2MainLoopInput: XXXXXXX0LED OnobjectCheck IR sensor
3 AlwaysPulse: pin 7 2000 Drive forward
4 
Always
Pulse: pin 6 1000 Drive forward
5 After 20 ms MainLoopServo delay (20ms)
6objectAlways 
back (set bookmark)We detected something, so back up a little.
7turnAlwaysSet Loop A to 20

 Start turning (just under 1/2 second)
8turn0Always
Pulse: pin 7 2000 pulse motors the same way
9 AlwaysPulse: pin 6 2000
 
Inserted step
10 
After 20 ms
 turn0 (Loop A)Pause and loop for 2 seconds
11 Input: XXXXXXX1
 
StartIf sensor shows clear (high) then go back to forward motion
12 Always
 
turnSensor wasn't clear so do some more turns
13backAlwaysSet Loop A to 100
 
Back up for about 2 seconds
14back0
Always
Pulse: pin 7 1000 Turn motors in reverse
15 Always
Pulse: pin 6 2000
  
16 After 20 ms 
back0 (Loop A)
Delay and loop
17 
Always
 {last bookmark}Go back to caller



The table is easy to understand. The step number should be obvious. The "Tag" is a label that names a particular step so you can refer to it later. Each step has 3 major parts:


  1. Condition - This must be true for the step to execute. Many of the steps are marked "always" and some are marked "After xxx milliseconds". These will always execute, of course. Note the lines that work with the IR sensor, however. They only execute when a specific condition is true.
  2. Action - When the condition occurs, this is what will happen. The GP3EZ can output digital values, PWM, pulses, and do a variety of other tasks as part of the action. If you are connected to a PC (the robot isn't) you can write data to a file or execute external commands.
  3. Next - When a step executes, this column tells the program where to go next (which is usually the next step).

The note field is just a comment and is ignored by GP3EZ.

Note that the GP3EZ supports looping and subroutines. For example, at the "object" tag, there is a transfer (in the next field) to the tab "back". The notation says that a "bookmark" is set. If you find the back label, you'll see it does several steps and then goes to the "last bookmark." This is nothing more than a subroutine call and return. You can see examples of looping in the object and back routines which generate a specific number of motor pulses.

Labels: , , , ,

Submit to:   book mark An Easy Robot in del.icio.usDel.icio.us  |   submit An Easy Robot to digg.comDigg  |   submit An Easy Robot to slashdot.comSlashdot  |  diigo itDiigo

Sunday, March 11, 2007

Working with Surface Mount CPUs


Over at AWC you can find a neat board called a GPMPU40 that allows you to work with just about any DIP CPU ranging from tiny 8 pin CPUs to big 40 pin CPUs (yes, I know the title is about working with surface mount -- I'm getting there).

The board has two patterns of holes -- one for .3 inch chips and one for .6 inch chips. In addition there is a place for a regulated power supply, a ceramic resonator or crystal, a reset circuit and switch (active or passive reset), and the ubiquitous RS232 port with a MAX232. There's also a 40 pin header that brings each pin out to the board edge for interconnect. If you install an upside down header there, you can plug the whole board into a solderless breadboard.

Each section of the board has holes so you connect the sections as you see fit. So if your processor has power on pin 1 and ground on pins 8, 9, and 22, that's how you wire it up. If you put headers everywhere, you can use jumpers to make the connections quickly and non-permanently. If you aren't using a 40 pin chip, you can use the leftover space for a EEPROM or a serial A/D or any other small support chip you might need.

I've used these boards to wire up just about every Microchip PIC you can imagine, 8051 chips from Maxim and Dallas, Zilog Z8s, Ubicom/Scenix/Parallax SX chips, Basic Stamps, Motorola chips, Atmel ATMega chips -- and many more. But lately, more of the interesting CPUs are in surface mount packaging.

The picture above shows the board which is now available with a 28 pin SSOP footprint (the processor is a 50MIPs Ubicom SX). You still have enough room for an 8 pin DIP underneath, although in the picture I used the extra space for jumpers to select an internal clock (the blue resonator) or an external one from an SX-Key (connected to the 4 pins in the top left corner). I didn't install the RS232 components, although they are part of the kit.

If you are wanting to work with surface mount, this is a good way to dip your toe in the water. Even with a regular soldering iron you shouldn't have any trouble with a 28 pin SSOP. You just need a fine tip (I like to use a screwdriver tip on its side) and fine solder or blob solder all along the edge and wick up the excess (use plenty of liquid flux like that from a flux pen). If you use the blob method, you can use an embarrassingly large iron and thick solder!

Of course, there are other ways to solder surface mount. Hot air and paste is good for doing lots of parts at once -- especially ceramic capacitors where sudden heating might crack the component. But for 28 IC pins, I'd just stick with a good old fashioned contact iron and fine solder. If you want to practice get an old board (like a PC network card) that you don't care about anymore. You want a good source of heat like a pencil torch or an embossing gun (get these at a hobby store like Hobby Lobby for less than $20). Heat up the area around a chip until the solder starts to melt and then with tweezers just lift the chip. This is a throwaway, so you don't really care if you damage the chip or not (although with practice you can use either of these tools to do this reliably). Now with a regular iron, flux, and either a wick or a "solder sucker" clean up the pads and IC pins. Now practice putting the chip back where it went. Kind of like being in the Army and digging a hole and then filling it back in! But practice makes perfect.

So don't be afraid of surface mount. You can find the board at the bottom of this page (which mostly talks about the DIP version).

Labels: , ,

Submit to:   book mark Working with Surface Mount CPUs in del.icio.usDel.icio.us  |   submit Working with Surface Mount CPUs to digg.comDigg  |   submit Working with Surface Mount CPUs to slashdot.comSlashdot  |  diigo itDiigo

Friday, February 09, 2007

Add a USB Host to your Microcontroller

Wow, this looks interesting: http://www.ghielectronics.com/details.php?id=5. For about $30 (chip) or $60 (board) you can get a device that allows you to connect USB devices including storage, printers, and HID devices to any microcontroller that can so serial I/O, SPI, or I2C. It also has a hook up for flash cards. I haven't tried it (yet) but if it works as advertised, its amazing!

Labels: , ,

Submit to:   book mark Add a USB Host to your Microcontroller in del.icio.usDel.icio.us  |   submit Add a USB Host to your Microcontroller to digg.comDigg  |   submit Add a USB Host to your Microcontroller to slashdot.comSlashdot  |  diigo itDiigo

Sunday, February 04, 2007

A Simple Cheap Robot Platform


















I'm not very mechanical, so here's a simple robot chassis I built while teaching a robot class at a local school. The top and sides are Radio Shack perf board. This is great because you can easily cut straight lines in it by just cutting along the holes in the grid. The parts:

  • The motors are modified RC servos that rotate all the way around.
  • The angle brackets came from Home Depot in the cabinent section.
  • There is a brace at the rear made of some scrap lumber.
  • The front brace is part of an IC tube cut off and hot glued for support.
  • You can't see it, but Home Depot also provided a small caster at the front (or back depending on your point of view; it is mounted on the wooden brace).
  • The wheels are actually landing gear for model planes.
  • The screws at the top are holding a 4xAA battery holder under the chassis and a 9V battery clip. The 9V battery runs the computer and the AA batteries run the motors.
  • The breadboard is secured with doublestick tape. That's an APP-II running the monster.
If I can make this, anyone can make it. You can connect a Basic Stamp or just about any old processor to the breadboard. Plenty of room to hook up other things too. Let me know if you build anything similar.

Labels: , ,

Submit to:   book mark A Simple Cheap Robot Platform in del.icio.usDel.icio.us  |   submit A Simple Cheap Robot Platform to digg.comDigg  |   submit A Simple Cheap Robot Platform to slashdot.comSlashdot  |  diigo itDiigo

Tuesday, July 11, 2006

Uncommon Nonvolatile Memory Powers 8051

The 8051 is a popular microcontroller core. In the "old" days we used external EPROMs. Modern versions have onboard EPROM or EEPROM (like flash).

Ramtron recently announced their new 8051 with onboard FRAM (8K worht). FRAM is a nonvolatile memory that is fast to write, byte-writeable, and has virtually unlimited read/write cycles. So you get the advantages of nonvolatile memory without the disadvantages of flash.

FRAM is a ferroelectric-based technology that does not require battery backup like SRAM. Of course, you can get FRAM to include with a traditional microprocessor, but this is the first microcontroller I know of that has FRAM right in the device.

Link: http://www.ramtron.com/VRS3xxx/default.asp

Labels: ,

Submit to:   book mark Uncommon Nonvolatile Memory Powers 8051 in del.icio.usDel.icio.us  |   submit Uncommon Nonvolatile Memory Powers 8051 to digg.comDigg  |   submit Uncommon Nonvolatile Memory Powers 8051 to slashdot.comSlashdot  |  diigo itDiigo