Archive

Archive for February, 2010

ZephyrEye Rev2: Call for Schematic Reviewers

24 February 2010 3 comments

There are a few inevitable truths in this world.  Taxes will rise, Wookies shed all over the furniture, Luke and Leia are related, and there is no such thing as a perfect first draft schematic.

The Rev2 circuit is nearly complete.  It looks AMAZING if I do say so myself.  That’s the problem, though:  I’m inundated with excitement and therefore am unable to find things that are wrong because I don’t want to find any reason that might delay getting the circuit boards back as soon as possible.

I’m calling out for a few extra set of eyes to look over the schematic   If anyone could please go to the Google code, download the Eagle CAD files and take a look, I’d really appreciate it.  If you want to make changes, let me know so I can arrange for them to be merged back in properly.  Even if you’ve never looked at schematics before, take a look and as always, feel free to ask what’s going on in the comments.

This is also a great chance to give suggestions on functionality.  I should add, it may be your LAST chance!  Please give some comments if you think you might ever build one, if nothing else just to say you think it works for what you’d like to use it for.

If you’re not familiar with CAD schematics and circuit board layouts, it might be interesting to look at the history of the .sch and .brd files in the Google Code repository.  By looking at older revisions, you can see the steps taken along the way chronologically.  I commit changes at least at the end of almost every day I work on the project.

The current Bill of Materials can also be found at this Google Docs spreadsheet.  It includes estimated pricing – it currently comes in at just under $200.  A little bit higher than I was hoping, but about the same cost as Rev1 and Chuck Norris (adverbicized) packed with new extra features!

The schematic is hopefully organized well enough for someone not intimately familiar with this project to try and understand one section of the schematic at a time.  The capacitive touch schematic is separate, because it will be a separate board.  The way it works is you put copper pads on the board, glue it to the inside of your enclosure, and it senses you touching it on the outside of the enclosure.  Pretty nifty, and a great way to avoid milling the enclosure.

Please post comments below, or add to the Google Groups discussion page.

ZephyrEye: XBee Bootloader

19 February 2010 Leave a comment

A bootloader is like a program inside of a program.  Almost just like a supervisory program.  Normally, when a microcontroller starts up, it boots to what’s called the “Reset Vector”, which is at address $0000 (the dollar sign means it’s a hex number).  The Mega128 has 128KB, or $FFFF bytes, of program flash, so what we want to do with the bootloader is section out a chunk of program space that works separately from the main program.  That way, the bootloader can wipe out the main program, copy a new program in its place, without wiping itself out at the same time.

The Mega128 has fuse bits that allows you to boot to a different address than $0000 at startup.  So say, for example, you set the fuse bits to boot to $FC00 on powerup.  This points the processor to the program space at 2KB before the end of your memory.  You can put a program here that does whatever it feels like, and then given certain conditions, it will “jump” program execution to the main program, which is found at $0000.

So, in our case, we want the ZephyrEye to have a simple program that waits for a period of time before starting the main program.  Two things can happen during this wait period:

  1. If it detects a particular serial pattern during the wait period, then it knows to expect an incoming program transmission, initiates a reply, and begins downloading the new program.  The new program is written to flash, starting at address $0000.  Once the program reception is complete, the bootloader program jumps to $0000, which starts the main program.
  2. If the bootloader program doesn’t detect the correct serial pattern, then after the timeout it simply jumps to the reset vector at$0000.

Pretty straightforward, right?  A major advantage of using a bootloader is that it allows you to program your device anywhere.  In the case of the ZephyrEye, it also means you don’t have to plug in a serial programmer cable to it, or even own a serial programmer to reprogram it.  This easily cut the development time in half!  It makes it so much easier and quicker to test your code.

BASCOM-AVR provides sample bootloader code.  You can modify this to make it work however you want it to, which I did.  On the ZephyrEye Rev1, I decided to use a 38400 baud rate for the XBee, and I had it connected to UART1.  The BASCOM bootloader uses the XModem protocol, which checks to ensure program integrity during transit.  I won’t dive into that part of it (see repository for full bootloader code), but here are a few excerpts.

This first chunk sets up the bootloader with a few of its settings.

$crystal = 8000000
$baud = 38400

...

$regfile = "m128def.dat"
Const Loaderchip = 128

...

#if Loaderchip = 128                                     ' Mega128
 $loader = &HFC00                                        ' 1024 words
 Const Maxwordbit = 7                                    'Z7 is maximum bit                                   '
 Open "COM1:" For Binary As #1
 Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
#endif

...

Disable Interrupts                                          'we do not use ints

So, now we’ve got a serial port open on channel #1, with the UART correctly configured to communicate with the XBee modem.  Notice that interrupts MUST be disabled.  You can’t use interrupts in the bootloader, because the interrupt vectors are near the reset vector $0000, and will cause you to haphazardly enter certain routines in the main program.  Bad news bears.

$timeout = 200000                          'we use a timeout

Bretries = 5                               'we try 5 times
Testfor123:
Bstatus = Waitkey(#1)                      'wait for the loader to send a byte

Print #1 , Chr(bstatus);                   'return the received byte to confirm reception

If Bstatus = 123 Then                      'did we received value 123 ?
  Bkind = 0                                'prepare to receive flash program
  Goto Loader
Elseif Bstatus = 124 Then                  ' EEPROM
  Bkind = 1                                ' prepare to receive EEPROM data
  Goto Loader
Elseif Bstatus <> 0 Then
  Decr Bretries
  If Bretries <> 0 Then Goto Testfor123    'we test again
End If

For J = 1 To 10                            'blink LED to indicate start of normal program
 Toggle Portb.2 : Waitms 100
Next

Goto _reset                                'goto the normal reset vector at address 0

There’s a string or two of spaghetti code in there, but it’s pretty straightforward.  We’re going to try to get a byte 5 times (Bretries).  Each time we check, we’re going to call Waitkey(#1), which is blocking code.  It won’t go any further until it either receives a byte, or the timeout is reached.  You’ve also probably noticed that this bootloader program will accept EEPROM data, I won’t dive into that either but it’s not hard to figure out.

If it got the correct byte to expect flash program data (decimal value 123, also the ASCII character “{“), then it will jump to the “Loader:” label, and begin XModem reception.

If it didn’t get the right byte, then it retries.  After five retries, it blinks an led 5 times quickly to let the user know that the normal program is starting, and then jumps to the reset vector.

BASCOM has an internal programming option that lets you transmit the binary file via the bootloader directly from the IDE.  However, you can use other terminal emulators (such as HyperTerminal) to send the “{” character, wait for the response, and then use the “Send File” menu option.  After running into some trouble using Linux terminal emulators to communicate with the bootloader (I’m not sure why, has to do with lrzsz…), I wrote a C program (that I will soon add to the repository) that can be called from a Makefile to send the program as well.

You could make the bootloader initiation signal be something other than a character coming over the UART: a button held down at startup, another serial signal, or even read an EEPROM value.

Another cool way to use the bootloader is to call it from the main program.  Since we know the address of our bootloader, we could put a bootloader menu option in the main program.  When selected, all we have to do is jump from normal main program flow to the bootloader program location $FC00.  This is pretty handy, too, because then you don’t even have to power cycle to reload your program!

Hopefully this sheds some light onto how bootloaders work, and why they’re so nice.  As I always say, if you have the chance to choose between regular heaven and bootloader heaven, choose bootloader heaven.  It may be a joke, but if not, mmmm boy!

Categories: General

ZephyrEye: Rev1 vs Rev2

11 February 2010 7 comments

OK folks, I’ve received quite a few requests so here’s what’s up with the circuit boards I have available.  They are Revision 1, and have some hardware bugs (all of which can be corrected with a scalpel, soldering iron, and a fair amount of skill).  I’d like to go through the rundown once here so everyone understands what’s up.

The plan is to get started with Revision 2 soon.  There are quite a few feature improvements that would make the ZephyrEye work a lot better, and I’d like to list them.  I’m not trying to talk anyone out of a Rev1 board, I will gladly send them (without charge but unpopulated) to anyone until I run out, but I would like to avoid anyone having false expectations of what it can do.  That being said, it will probably be at least a few months before Revision 2 is ready.

If you are thinking about building a ZephyrEye, please use this post to consider your options.  Remember, it really can’t do much of anything by itself – it only tracks other ZephyrEyes, so think in pairs.  And Rev2 is very unlikely to be backwards compatible with Rev1.

Revision 1

I feel kind of like I’m hanging out my dirty laundry, these are some pretty silly mistakes:

  • LCD connector is missing two traces, which requires hand soldering wires to this connector.
  • Traces ran too close under the LCD connector, so installing the connector requires bending the pins down at an angle and soldering them without the connector having full flush contact with the board.  This bug proudly brought to you by the autorouter.
  • An extra voltage regulator needs to get patched in for the XBee, which outdid the current supply capabilities of the original regulator.

Hardware that is still untested:

  • Microphone to ADC
  • ADC channel for voltage monitoring
  • Charging indicator from LiPoly chip

State of Software:

  • Has a bootloader for easy, wireless program updates
  • Can do simple system setup
  • Can play King of the Hill, but currently limited to 2 players (I currently only have two ZephyrEyes to play with ;)
  • Still has a few bugs, graphic artifacts, etc.
  • Still needs other games programmed into it.

I only have unpopulated circuit boards (e.g., bare as the day they were born), so it’s up to you to have the tools, AVR programmer, XBees, GPS module, and pretty much every other part if you are considering putting one of these together.  Alternately, if enough people request it and are interested, I might put together some kits.  Email me or leave a comment if interested.

Revision 2

On top of the features Revision 1 already has, I would like to add the following features.  Note that some of these are crucial to be successful in playing paintball with a ZephyrEye.

  • Clear epoxy filled case that can take direct paintball impact and other abuse
  • Capacitive touch buttons, which would enable the above feature.  These would replace the tact switch buttons for the menu, zoom, and power buttons.
  • Digital compass for heading compensation.  This way the “radar” is oriented the direction you’re facing, rather than just pointing north, which is a little confusing if you aren’t a well-oriented person.
  • Helical GPS antenna, for better reception when near other objects (like your arm, body, or hopper)
  • GPS module (or chipset) with higher sensitivity and output frequency (> 1Hz)
  • Swap out the Series 1 XBee for either a 900MHz XBee or a MeshNetics ZigBit module, which have longer range and more complete, ZigBee compliant firmware.
  • If possible, an optional external ZigBee antenna for better transmissions in, say, densely forested or urban arenas.
  • Use the newer, faster XMega256.  More peripherals, and runs at a blazing 32MHz.  She’s fast enough for you, old man.

Make sure and post comments here or join the Google Code project if you’d like to have input on what Version 2 will be able to do.

Edit: I’ve also just created a Google Group for project development discussions.  If you think you’d ever be interested in using a ZephyrEye, for paintball or other, please join the group and put your thoughts up.  Revision 2 hardware development will begin in earnest soon, so now is the time to ask for features.  I’m torn between adding a can-opener or laser pointer … surely your ideas are better.

Follow

Get every new post delivered to your Inbox.