October 12 progress:
I got the AVRLib i2c library test working and then molded in into what I needed. To do this, I created a i2cLCDsendbyte function to replace the uartsendbyte in rprintf. Now I’ll remount the processor, the new power supply, then new LCD (122x32 or 4x20 with the option of using a 240x64 model I have), the servos and an interface board (when my parts order arrive). If I have time tonight I will modify the SRF04 and encoder programs to use the i2cLCD functions.
Onward,
Jay
My journal of creating and experimenting with circuits, CNC, programming, and robotics
Wednesday, October 11, 2006
October 11, 2006 progress:
Microcontroller: The replacement parts have arrived from Brian but looking at how small they still are I’m a bit hesitant to try and solder them in just yet. Besides, it’s working fine without them. In truth I’m going to wait till this weekend when I have some free time at home.
As for programming, I now have quadrature encoding working flawlessly between ARVlib and my 1000PPR encoder. The nice thing about the encoder lib is that it keeps track of the position of the wheel (signed number of ticks) either forward or backward. Next step I2C to graphic LCD. That and I plan to modify my SRF04 code to be standalone from AVRLib for posting on AVRfreaks.net
Voice: I pulled the trigger and ordered a Soundgin (backordered according to the vendor I ordered it from) and the parts to build up a protoboard circuit (amplifier, low pass filter, etc…) most of the parts I found at www.hobbyengineering.com
Odds and ends: Connectors is always something in the back of my mind. Therefore I also made a order from www.action-electronics.com for some Molex KK shrouds, pins, and headers. I won’t have to worry about connectors ever again :)
Onward,
Jay
Microcontroller: The replacement parts have arrived from Brian but looking at how small they still are I’m a bit hesitant to try and solder them in just yet. Besides, it’s working fine without them. In truth I’m going to wait till this weekend when I have some free time at home.
As for programming, I now have quadrature encoding working flawlessly between ARVlib and my 1000PPR encoder. The nice thing about the encoder lib is that it keeps track of the position of the wheel (signed number of ticks) either forward or backward. Next step I2C to graphic LCD. That and I plan to modify my SRF04 code to be standalone from AVRLib for posting on AVRfreaks.net
Voice: I pulled the trigger and ordered a Soundgin (backordered according to the vendor I ordered it from) and the parts to build up a protoboard circuit (amplifier, low pass filter, etc…) most of the parts I found at www.hobbyengineering.com
Odds and ends: Connectors is always something in the back of my mind. Therefore I also made a order from www.action-electronics.com for some Molex KK shrouds, pins, and headers. I won’t have to worry about connectors ever again :)
Onward,
Jay
Monday, October 09, 2006
October 8, 2006 progress
Sunday was 4 hours of yard work and a very unhappy little boy so minimal progress was made. I decided to research speech chips and got off on all kinds of tangents. Makezine.com BLOG is addictive and I was up way too late Saturday night reading it.
So anyway, in a former life I was a midnight engineer for a buddy’s fledgling company. I had designed and programmed a device to translate the clock synchronization signal of one master clock to that of a tower clock controller. This was going to be a big product for his company so he had several PCB’s manufactured along with several sets of parts. Unfortunately the company went bust. I was contacted by the major investor and asked if I wanted the leftover electronics stock before it was “tossed”. Long story short I have a surplus of PCB’s, LCD’s, relays, etc… The reason I explain all this is because I had designed the system to use a switching power supply and had designed the 5V DC supply in one corner of the board. A few minutes with a hack saw and I had a nice PCB for a 5V DC switching PS. I also had all the parts to stuff it and as luck would have it, the diode bridge layout matched the .156” power header part. So, now I have a very stable high current PS (5A IIRC) that I can power from my stock of RC batteries (LiPo and NiMh up to 18VDC IIRC). I will go back any look at my notes to see what the design criteria were, but the system was capable for switching 4 relays at the same time if need be.
Back to the speech chips. Devantech’s is too expensive (at least for now) so it’s down to the SpeakJet or the new (and as far as I can tell not yet released) Savage Innovations Soundgin. Interestingly Magnevation which makes the SpeakJet is a partner in some fashion with Savage and both chips are very similar in that they use phonemes to generate speech. They are the same price but the Soundgin’s manual and software have given it a very strong lead on my score sheet. I’ll have to hack together a demo board with amp, but the schematic is presented. Since both use RS232 communications, I will most likely switch to a I2C LCD (a good excuse to play with I2C again) maybe even a graphic one I have laying around.
So, I think I will spend lunch making a parts order for a speech circuit J
Onward,
Jay
Sunday was 4 hours of yard work and a very unhappy little boy so minimal progress was made. I decided to research speech chips and got off on all kinds of tangents. Makezine.com BLOG is addictive and I was up way too late Saturday night reading it.
So anyway, in a former life I was a midnight engineer for a buddy’s fledgling company. I had designed and programmed a device to translate the clock synchronization signal of one master clock to that of a tower clock controller. This was going to be a big product for his company so he had several PCB’s manufactured along with several sets of parts. Unfortunately the company went bust. I was contacted by the major investor and asked if I wanted the leftover electronics stock before it was “tossed”. Long story short I have a surplus of PCB’s, LCD’s, relays, etc… The reason I explain all this is because I had designed the system to use a switching power supply and had designed the 5V DC supply in one corner of the board. A few minutes with a hack saw and I had a nice PCB for a 5V DC switching PS. I also had all the parts to stuff it and as luck would have it, the diode bridge layout matched the .156” power header part. So, now I have a very stable high current PS (5A IIRC) that I can power from my stock of RC batteries (LiPo and NiMh up to 18VDC IIRC). I will go back any look at my notes to see what the design criteria were, but the system was capable for switching 4 relays at the same time if need be.
Back to the speech chips. Devantech’s is too expensive (at least for now) so it’s down to the SpeakJet or the new (and as far as I can tell not yet released) Savage Innovations Soundgin. Interestingly Magnevation which makes the SpeakJet is a partner in some fashion with Savage and both chips are very similar in that they use phonemes to generate speech. They are the same price but the Soundgin’s manual and software have given it a very strong lead on my score sheet. I’ll have to hack together a demo board with amp, but the schematic is presented. Since both use RS232 communications, I will most likely switch to a I2C LCD (a good excuse to play with I2C again) maybe even a graphic one I have laying around.
So, I think I will spend lunch making a parts order for a speech circuit J
Onward,
Jay
Saturday, October 07, 2006
October 7, 2006 Updates
Wow what progress! Slowly but surely I was able to get the SRF04 sonar module working. Not without a lot of lost time on false starts, dead batteries and general ignorance on my part. I have created some notes for you to consider if you are going down the same path.
* The SRF04 outputs a pulse whose width in us = the distance. To scale it to cm divide by 58 and to get inches divide by 148 per the instructions.
* You can use an external interrupt to measure this pulse by storing the timer count on the rising edge and then subtracting the second time on the falling edge.
* External INT0-3 do not allow “Any Edge” triggers (i.e. both rising and falling edges trigger the interrupt) 4-7 do.
* A 16 bit timer has fewer overflows and helps limit erroneous readings
* The timer counts you use are in CPU ticks not us. Depending on how you configure your prescaler a tick can represent .0625us up to 64us. Since your measurement is in us you will need to convert your ticks to us.
* The SRF04 has a 3cm minimum distance (100us) and measurements start at the element, not the PCB
So using Pascal’s AVRLib I chose to use Counter/Timer1 which he configures with a prescale of 64 (each tick = 4us with a 16MHz clock). I also chose to use INT4 which is on PORTE pin4 configured for both rising and falling edges. IN my ISR I check to see if it is the rising edge (PINE PE4 =1). If so, I capture the current tick count (SonarDistance = TCNT1). Otherwise, I set the SonarDistance = TCNT1 – SonarDistance because the TCNT1 is set to count down.
Now all I need to do is write a function that will ping the sonar X times and return the average.
Depending on how much more time I’ll have today, I’ll start on the encoders.
Onward,
Jay
Wow what progress! Slowly but surely I was able to get the SRF04 sonar module working. Not without a lot of lost time on false starts, dead batteries and general ignorance on my part. I have created some notes for you to consider if you are going down the same path.
* The SRF04 outputs a pulse whose width in us = the distance. To scale it to cm divide by 58 and to get inches divide by 148 per the instructions.
* You can use an external interrupt to measure this pulse by storing the timer count on the rising edge and then subtracting the second time on the falling edge.
* External INT0-3 do not allow “Any Edge” triggers (i.e. both rising and falling edges trigger the interrupt) 4-7 do.
* A 16 bit timer has fewer overflows and helps limit erroneous readings
* The timer counts you use are in CPU ticks not us. Depending on how you configure your prescaler a tick can represent .0625us up to 64us. Since your measurement is in us you will need to convert your ticks to us.
* The SRF04 has a 3cm minimum distance (100us) and measurements start at the element, not the PCB
So using Pascal’s AVRLib I chose to use Counter/Timer1 which he configures with a prescale of 64 (each tick = 4us with a 16MHz clock). I also chose to use INT4 which is on PORTE pin4 configured for both rising and falling edges. IN my ISR I check to see if it is the rising edge (PINE PE4 =1). If so, I capture the current tick count (SonarDistance = TCNT1). Otherwise, I set the SonarDistance = TCNT1 – SonarDistance because the TCNT1 is set to count down.
Now all I need to do is write a function that will ping the sonar X times and return the average.
Depending on how much more time I’ll have today, I’ll start on the encoders.
Onward,
Jay
Friday, October 06, 2006
Update for October 05, 2006
Well on the physical front things aren’t so good. I have had chronic back issues (muscle spasms) ever since 7th grade (maybe even before) where I am somewhat debilitated and unable to stand. Yesterday I woke and was not able to stand up without a lot of pain. It’s hard to concentrate when you have a constant pain in your lower back so I stayed home from work.
On the robotic front I made huge strides. The spasms are weird in that the come and go in spurts (Ibuprofen helps to relax the muscles). When I felt a relaxation I went into my computer room to work on playing with AVRLib. Specifically, I wired up serial communication to a serial LCD and servo control.
Serial LCD:
This was cake to wire as the MAVRIC has screw headers from the Maxim 232 chip. The serial LCD from http://www.crystalfontz.com/ can take level shifted 232 or TTL 232. So I enabled the onboard RS232 pullups (via the dip switches) and gave it a try. It worked, but needed some tweaking to allow the LCD to init before sending any text. It would be nice to have a bigger LCD (4 line, 20 chars but anything is better than nothing).
Servos:
Now this was a PITA. Long story short, I already knew to change timer.h to timer128.h to accommodate the Mega128 device. However, I also had to modify the makefile to do the same thing. I had a 3 hour debug session wherein I dragged out my O-scope to watch the pin transition. After I got one working, adding more was cake. The AVRLib allows you to control up to 8 (any port, any pin) servos simultaneously by using the 16-bit timer/counter. Seemed a bit jerky, but that’s probably due to my adding printf statement to show the position of the servo before updating it to the next value.
I also made a mounting board for the LCD, MAVRIC, and servos. What I’ve learned thus far is I need to add two toggle switches. One for the power to the MAVRIC as there is no reset switch and 1 for the servo power. Come to think of it adding 1 more for the drive motors would be a good idea too.

You can see the MAVRIC, serial LCD, two micro servos,
my wire wrapping connections for the servos, oneofthe RC battery packs, and the Ecro ICE Cube JTAG unit.
Onward,
Jay
Well on the physical front things aren’t so good. I have had chronic back issues (muscle spasms) ever since 7th grade (maybe even before) where I am somewhat debilitated and unable to stand. Yesterday I woke and was not able to stand up without a lot of pain. It’s hard to concentrate when you have a constant pain in your lower back so I stayed home from work.
On the robotic front I made huge strides. The spasms are weird in that the come and go in spurts (Ibuprofen helps to relax the muscles). When I felt a relaxation I went into my computer room to work on playing with AVRLib. Specifically, I wired up serial communication to a serial LCD and servo control.
Serial LCD:
This was cake to wire as the MAVRIC has screw headers from the Maxim 232 chip. The serial LCD from http://www.crystalfontz.com/ can take level shifted 232 or TTL 232. So I enabled the onboard RS232 pullups (via the dip switches) and gave it a try. It worked, but needed some tweaking to allow the LCD to init before sending any text. It would be nice to have a bigger LCD (4 line, 20 chars but anything is better than nothing).
Servos:
Now this was a PITA. Long story short, I already knew to change timer.h to timer128.h to accommodate the Mega128 device. However, I also had to modify the makefile to do the same thing. I had a 3 hour debug session wherein I dragged out my O-scope to watch the pin transition. After I got one working, adding more was cake. The AVRLib allows you to control up to 8 (any port, any pin) servos simultaneously by using the 16-bit timer/counter. Seemed a bit jerky, but that’s probably due to my adding printf statement to show the position of the servo before updating it to the next value.
I also made a mounting board for the LCD, MAVRIC, and servos. What I’ve learned thus far is I need to add two toggle switches. One for the power to the MAVRIC as there is no reset switch and 1 for the servo power. Come to think of it adding 1 more for the drive motors would be a good idea too.

You can see the MAVRIC, serial LCD, two micro servos,
my wire wrapping connections for the servos, oneof
Onward,
Jay
Wednesday, October 04, 2006
Had a chance at lunch to play with the MAVRIC some more. Went through the intro document that comes with WinAVR. Was able to enter a debug session in AVRStudio and step, watch, modify register and program variables. One thing I learned is that everything slows way down from real time.
I then proceeded to debug the hello world program which uses interrupts. Ended up having to modify the program to get any realistic speed, but the program did step as it should. To improve the speed, I will play with breakpoints.
I then modified an AVRLib program using his library to do the same thing as Hello Wolrd. After I figured out the different places I need to check to make sure the right library and target chip is configured it works too. All in all a very productive day.
Next steps. Time to play with some hardware. I will add a serial LCD, a server, and a quadrature encoder. maybe even a push button ... I think I have a "test" board with some LEDs and buttons on it from a Rabbit2000 kit.
Onward,
Jay
I then proceeded to debug the hello world program which uses interrupts. Ended up having to modify the program to get any realistic speed, but the program did step as it should. To improve the speed, I will play with breakpoints.
I then modified an AVRLib program using his library to do the same thing as Hello Wolrd. After I figured out the different places I need to check to make sure the right library and target chip is configured it works too. All in all a very productive day.
Next steps. Time to play with some hardware. I will add a serial LCD, a server, and a quadrature encoder. maybe even a push button ... I think I have a "test" board with some LEDs and buttons on it from a Rabbit2000 kit.
Onward,
Jay
Microcontroller board update
Good news, with Brian's (of www.bdmicro.com) patience I have successfully run a test program on the Mavric board. Of course had I done everything right last night I could have reached this step sooner. Here's what all I had to do to get this thing to blink the LED as it should:
1. After soldering the rest of the thru-hole components on the board and getting the go ahead from Brian about the missing (but in the mail) caps I decided on an RC reciever battery (5V DC) to connect the Vcc and GND pins bypassing the LDO regulator.
2. I installed AVRStudio 4 and it's service pack, WinAVR (except PN), and AVRLib
3. Following along with the ICE Cube quick start guide, I atteched it to the JTAG header, connected the battery, and ran AVRStudio.
4. Using the Tools menu I selected AVR Prog to loag the JTAG ICE image to the ICE CUBE. Worked perfectly
5. Using the command line ran make on the Hello World sample from Brian's site. Compiled fine.
6. Using the JTAGICE under Tools programmed the board with the .hex file generated. Programmed fine.
7. Nothing ... no blinking. After an hour or so, I decided to look at it with fresh eyes and went to bed
8. I decided to read the user help in AVRStudio (I know ... wierd isn't it) and read the following under known issues: "ATmega128 in ATmega103 compatibility mode: Not supported, but will be available in a later version of AVR Studio 4." I remembered seeing, reading, something about 103 compatibility mode and found it under the Fuses tab in the JTAG ICE screen. Cleared the fuse and now was seeing a very slow (say 8hz blinking LED). Ok, so it works ... kinda.
9. Read the ATMega datasheet and run ferquency calc in Excel to confirm register settings.
10. Brian's email telling me that the chip has not been programmed for the 16MHz external clock and that the fuse sertting are in the Mavric user manual. DOH! That's where I saw them.
11. Set the fuses per the manual, reset the code fro the Hello World same program ... viola!
Next step, figure out how to use JTAG debugging. Oh, and I've noticed what may be a solder bridge on two of PortB's pins that need to be inspected closer.
Onward,
Jay
Good news, with Brian's (of www.bdmicro.com) patience I have successfully run a test program on the Mavric board. Of course had I done everything right last night I could have reached this step sooner. Here's what all I had to do to get this thing to blink the LED as it should:
1. After soldering the rest of the thru-hole components on the board and getting the go ahead from Brian about the missing (but in the mail) caps I decided on an RC reciever battery (5V DC) to connect the Vcc and GND pins bypassing the LDO regulator.
2. I installed AVRStudio 4 and it's service pack, WinAVR (except PN), and AVRLib
3. Following along with the ICE Cube quick start guide, I atteched it to the JTAG header, connected the battery, and ran AVRStudio.
4. Using the Tools menu I selected AVR Prog to loag the JTAG ICE image to the ICE CUBE. Worked perfectly
5. Using the command line ran make on the Hello World sample from Brian's site. Compiled fine.
6. Using the JTAGICE under Tools programmed the board with the .hex file generated. Programmed fine.
7. Nothing ... no blinking. After an hour or so, I decided to look at it with fresh eyes and went to bed
8. I decided to read the user help in AVRStudio (I know ... wierd isn't it) and read the following under known issues: "ATmega128 in ATmega103 compatibility mode: Not supported, but will be available in a later version of AVR Studio 4." I remembered seeing, reading, something about 103 compatibility mode and found it under the Fuses tab in the JTAG ICE screen. Cleared the fuse and now was seeing a very slow (say 8hz blinking LED). Ok, so it works ... kinda.
9. Read the ATMega datasheet and run ferquency calc in Excel to confirm register settings.
10. Brian's email telling me that the chip has not been programmed for the 16MHz external clock and that the fuse sertting are in the Mavric user manual. DOH! That's where I saw them.
11. Set the fuses per the manual, reset the code fro the Hello World same program ... viola!
Next step, figure out how to use JTAG debugging. Oh, and I've noticed what may be a solder bridge on two of PortB's pins that need to be inspected closer.
Onward,
Jay
Monday, October 02, 2006
Encoders and odometry
Along with knowing how many RPM my wheels will be spinning, I can calculate velocity. With the dimensions of my wheels I can calculate distance. And with the dimensions and layout of the wheels to the center of the bot, I can calculate angle. David Anderson has a great site to dicuss these and showcase his robot SRO4. Be sure to have a look at his writeups towards the end of the page.
Also, I have found a nice lab pdf that uses the AVRlib to do quadrature encoding.
Onward,
Jay
Along with knowing how many RPM my wheels will be spinning, I can calculate velocity. With the dimensions of my wheels I can calculate distance. And with the dimensions and layout of the wheels to the center of the bot, I can calculate angle. David Anderson has a great site to dicuss these and showcase his robot SRO4. Be sure to have a look at his writeups towards the end of the page.
Also, I have found a nice lab pdf that uses the AVRlib to do quadrature encoding.
Onward,
Jay
Coding
On the trail of PID motor control I found this interesing library.
This may save me a lot of "reinventing the wheel" and allow me to
concentrate on high level tasks ... just as the author intended ;-)
http://seasight.dforge.cse.ucsc.edu/details/data_acquisition/ATmega128/avrlib/docs/html/index.html
The more examples the better.
Onward,
Jay
On the trail of PID motor control I found this interesing library.
This may save me a lot of "reinventing the wheel" and allow me to
concentrate on high level tasks ... just as the author intended ;-)
http://seasight.dforge.cse.ucsc.edu/details/data_acquisition/ATmega128/avrlib/docs/html/index.html
The more examples the better.
Onward,
Jay
Microprocessor Update
Well I learned a few things this past weekend. First and foremost my SMD soldering skills are rusty. We perhaps I’m being too critical of myself. I have never actually tried to solder a discrete component smaller than 0805 and the bypass caps in this kit have to be 0402 or smaller. Smaller than a grain of rice for sure. Anyways, I got through 98% of the SMD components on Friday night but two of the .1uF bypass caps were lost as my tweezers shot them into wherever. I contact Brian to get some replacement parts so maybe those will get here today and I can knock them out later tonight.
As I couldn’t finish the board I decided to wit on the thru-hole parts too. To pass the time I started re-reading my Mobile Robotics book and looking for online content along the lines of PID motor control code using the ATMega128. I found a very promising site (still investigating) at www.drtak.org
I have also been playing with some driving strategies for the course which may end up affecting my base platform’s shape.
Onward,
Jay
Well I learned a few things this past weekend. First and foremost my SMD soldering skills are rusty. We perhaps I’m being too critical of myself. I have never actually tried to solder a discrete component smaller than 0805 and the bypass caps in this kit have to be 0402 or smaller. Smaller than a grain of rice for sure. Anyways, I got through 98% of the SMD components on Friday night but two of the .1uF bypass caps were lost as my tweezers shot them into wherever. I contact Brian to get some replacement parts so maybe those will get here today and I can knock them out later tonight.
As I couldn’t finish the board I decided to wit on the thru-hole parts too. To pass the time I started re-reading my Mobile Robotics book and looking for online content along the lines of PID motor control code using the ATMega128. I found a very promising site (still investigating) at www.drtak.org
I have also been playing with some driving strategies for the course which may end up affecting my base platform’s shape.
Onward,
Jay
Subscribe to:
Posts (Atom)