Archive

Posts Tagged ‘avr-gcc’

My first Robot - LFR (Pronounced ‘Loafer’)

November 16th, 2009

If there is anything that is considered a rite of passage among embedded hobbyists then it undoubtedly has to be the creation of a robot. A robot is not only challenging from the point of view of an embedded system designed to perform a particular function, but it also has mechanical and structural facets to it which makes it even more difficult.

But please do not assume the robots we hobbyists build would be even remotely smart and glamorous like R2D2 from Starwars or the three-laws-bound R. Daneel Olivaw from Asimov’s novels. In stead, our robots are from a much more humble origin; most of us are satisfied with simple line followers and object avoiders. Speaking of which, let me introduce you to my first robot, which I have christened, LFR - Line Following Robot - but you may call him Loafer in affection.

As the name says, this robot is programmed to follow a painted line on any plane surface using a sensing contraption. For LFR, I have used an ATmega32 - an ideal choice primarily because of its on chip debug interface. An endeavour as ambitious as robot building definitely warrants a good debug features.

For my sensor array, I have used two LDRs or Light Dependent Resistors and an LED to act as the light source which is used to shine the path of the robot. The light reflected from either side of the line is then measured and compared to decide which direction to turn the robot. The turning is achieved by using a differential drive i.e. a drive which turns the wheels independently of each other. An LM339 is used as a comparator chip and a ULQ2804A chip is used as the motor driver chip

The below schematic diagrams show how steering of the robot is achieved by using the LDR-LED sensor array. The diagrams show the cases when the robot moves in a straight line, turns left and turns right respectively. This is based on the amount of light reflected off the black painted line.

LFR - moving in a straight line.

LFR - moving in a straight line.

LFR - turning left.

LFR - turning left.

LFR - turning right

LFR - turning right

After the schematic diagrams, now here I present some actual pictures of LFR. Alas! I do not have any videos of this one. One issue which I found with LFR was that the entire circuitry along with its batteries was a bit too heavy for my motors to drive. So it moved rather sluggishly. This is one improvement which I have in mind for LFR 2.0 ;-). And in case you are wondering, for the line, I pasted some black insulation tape on my marble white floor.

So without further ado, here are some snaps of LFR. The first one is a labelled picture for the curious.

Labelled top view of LFR

Labelled top view of LFR.

lfr_side_view

Side view of LFR - notice the big tires.

If you are curious,  click here to see the ATmega32 C source code for LFR. As usual, with ATmega32, the code is extremely convenient. I used the avr-gcc toolchain to compile this and my own homemade JTAG debugger to debug my code. And yes, if you have seen the code then your guess is probably right, I have used PWM to control the speed of the motors here ;-) . Oh and probably you might have also noticed the JTAG debugger interface on the top right hand corner of the main robot board.,

So that was all about LFR - my first robot. It does not follow any of the three laws of Asimov, but yes it is nice to build your own robot, for fun as well as learning!

I hope you enjoyed this post. Stay tuned for more! Until the next time, g’bye and take care! And please do not forget to comment if you like this post.

admin Embedded Hobbyist, Tech , , , ,

My homemade AVR JTAG debugger.

December 10th, 2008

ATMega16 microcontroller: 160 Rupees.
Other Circuit components: 60 Rupees.
Solder wire:  15 Rupees.
AVR-GCC/AVR-GDB: Zero  (if you exclude the broadband cost of downloading)

The sense of satisfaction when I was finally able to debug AVR code on chip using my new homemade JTAG, over Linux: PRICELESS !!

Yes !! I was finally able to finish setting up my AVR development environment and let me tell you, the night I did it, I was not able to sleep due to excitement !

In my previous post, I had mentioned as to how I was able to come up with a minimal setup consisting of a programmer board and a general purpose development board for the Atmel AVR series of microcontrollers. Well, now that setup is complete, with the addition of a fully functional JTAG board. What this JTAG board allows me, is to examine my code execute at runtime on the actual hardware without incurring any execution overheads. It allows me to change variables at will, put breakpoints wherever I wish and inspect how my embedded program behaves. All these greatly increase my productivity as a programmer.

When I was working with the AT89S52 (an 8052 variant from Atmel) I did not have the luxury of on chip JTAG debugging and as a result I would spend hours trying to solve bugs which were very simple and would have got caught if I had some kind of on chip debugger. Solving bugs then was mainly by ‘thinking’ or by lighting up LEDs (in stead of ‘printf()’ statements that we use in our ‘normal’ programs for debugging).

The circuit schematics for this JTAG board are from the aquaticus ROV project site. And as usual I managed to take some photographs of this new JTAG board while I was constructing it.

Starting the construction of my JTAG board. Here you can see the IC bases of the MAX232 and the ATMega16 and the crystal being soldered on.

Starting the construction of my JTAG board. Here you can see the IC bases of the MAX232 and the ATMega16 along with the crystal soldered on the PCB.

With some more components soldered. Notice the USB connector for supplying power to the board directly from my PC USB and the JTAG connector.

With some more components soldered. Notice the USB connector for supplying power to the board directly from my PC USB and the JTAG connector.

The completed board. Notice the serial port connector at the bottom left corner and the actual ICs snapped onto the board finally. Also notice the 10 pin JTAG connecting ribbon to the right.

The completed board. Notice the serial port connector at the bottom left corner and the actual ICs snapped onto the board finally. Also notice the 10 pin JTAG connecting ribbon to the right.

The completed JTAG board in action. To its left, you can see my prototyping board. And further to the left I have a red LED connected to the pin 0 of port B. I am blinking this LED through a very small C program. The program execution can be stepped through using gdb in my host system.

The completed JTAG board in action. To its left, you can see my prototyping board. And further to the left I have a red LED connected to the pin 0 of port B. I am blinking this LED through a very small C program. The program execution can be stepped through using gdb in my host system.

And finally, my new JTAG board in action on my Linux host. The program source code is at the bottom left corner of the screen and behind in the terminal you can see AVARICE running in the background accepting connections from GDB. GDB, running within DDD GUI, is the top most window where you can clearly see a breakpoint being hit.

And finally, my new JTAG board in action on my Linux host. The program source code is at the bottom left corner of the screen and behind in the terminal, you can see AVARICE running in the background accepting connections from GDB. GDB, running within DDD GUI, is the top most window where you can clearly see a breakpoint being hit.

And also, here is a short video of by JTAG board in action:

Hope you liked this post. Stay tuned for more posts as I embark on a new journey of exploring the AVR microcontroller !

seemanta Embedded Hobbyist, My Creations, Tech , , , , , ,