Search This Blog

Thursday, March 31, 2011

Forward with the Mouse and Bootloader

Java Bootloader
  I took quite a break from microcontrollers towards the end of winter.  I ended up working on a translator, using Antlr.  I ended up shelving it for now, but I learned quite a lot.  For instance, I am pretty good at parsing, but I am an horrible lexer!  Also, 4th generation languages based on Cobol are not a good place to start for language compilers/translators.  Moving on...

   I picked up the robotics itch again last weekend.  I completed the first version of my Java bootloader for the Pic 18F2455.  It looks pretty good.  Remember, the 18F series erases in aligned-only 64 byte blocks and writes in aligned-only 32 byte blocks.  For one thing, that means I have to waste 64 bytes of space at the end of the program space for the insertion of the user's first 8 bytes.

   I do this because I want the user code to be virtually ignorant of the presence of the bootloader.  They need to know ( and will be reminded by the bootloader if they goof ) that the last ~192 bytes are reserved by the bootloader.  I want the loader to be small and efficient.  I know it will not be very fast.  The erase procedure I insist on will always erase the entire program space but for the bootloader area.  My experience with the smaller 16F chips tells me that this will be slow ( but safe ).  I'll take it.

   Now, the asm  compiler creates lines in the hex file of arbitrary length and starting address.  The Pic wants to write blocks in 32 bit aligned blocks.  The Java code creates a Program Object that has a list of "Chunks."  Each chunk holds an array of 32 bytes.  The code has an HexFileParser that pulls out each line, determines if it is a data line, and the starting address.  It asks the program to place the line into the correct Chunks.  The program looks up the correct Chunk for each address and asks the Chunk to record the data byte String representation as a byte in its array.  Simple.  The Program can retrieve a List of all the Chunks that have real data to send to the Pic.

   Now the wrinkles.  First, we have to start the erase and write blocks at instruction zero.  This means it will overwrite the bootloader's instructions that send the program counter to the loader on reset.  So, I generated a test file and looked at the hex.  I have the Parser put the bootloaders first few instruction in the first 8 bytes of Chunk zero.  The Parser and Program do not allow the user's first eight bytes in this space.  Instead, they are diverted to a special Chunk called the RewriteChunk.  This has a calculated address at the end of the bootloader, 64 bytes before the end of the program space on the chip.  This Chunk is returned with the other writeable Chunks.

   Then it was a simple matter of creating a start sequence dialog with the chip and a write sequence for the bytes.  I hope to see if it works, soon.  All the JUnit test for parsing run fine.  I just don't know how the serial communication with the Pic will go.

Robot Design
   Saw a great preliminary design by Patrick McCabe on LMR for a line following type mousebot.  Two things I really liked about his approach.  He cut out his chassis from 2 pieces of acrylic.  His chips are little, single function modules.  I decided to blatantly steal both ideas.  I have zero experience working in plastic.  I bought a very thin sheet from the Domed Hippo ( Home Depot).  I'm hoping the ol' Dremel can get through it with good results.  I took a set of Radio Shack proto boards and sliced them up.  One is a regulator to take 6V and make it an evened 5V.  The next is for the dual H-Bridge motor driver.  That board was tough!  The pin out challenges you to get the breakout pins where you need them without making a mess.  The next board is for the microcontroller.  I like the idea of this board.  It is simple a breakout of the controller, with pins for input 5V and output of 5V and all the I/O.  And it has three pins to put in a resonator.  This way, I can swap out any resonator I like.  I plan to start with a 20 MHz one.  With this chip, I can replace it with a 4 MHz clock.  The cool thing is, with PLL, the chip turns this into 96 MHz!  The chip can run at 48 MHz with this.

   I haven't even designed anything around the mouse's sensors yet.  The current board will have a cut-out on the top layer for a servo body to hang down.  I'll put a Sharp IR array on that for the first build.  I want to work on continuous PID with PWM motor driving.  Once that works, I'll change the sensors to a line follower.  When that works, I'll start working on the mouse's sensors.  I want to get some rotary encoders, too.  I need odometery for this to even look like a real micromouse.

Rough sketch:

Mini Boards:


   That's all for now.  Better pics to come.