Archive

Posts Tagged ‘ATMega32’

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 , , , ,

Speed Control of a DC motor using PWM.

December 19th, 2008

My sojourn of the AVR world is proving to be a worthwhile venture. I must admit architecture-wise, things are a bit more complicated on the AVR than on the stock 8051. However that initial learning curve is easily offset by the ease of using C as a programming language. And not to mention the euphoric sensation of using the gnu tool chain over Linux to create my stuff.

I thought the best way would be to learn each subsystem of the AVR ATMega32 in turn. So this week, I chose the Timer/Counter sub-system. And so here I am demonstrating Pulse Width Modulation (PWM) on the AVR which makes use of the underlying timer/counter system to generate a PWM output on one of its port pins.

I am not going to describe PWM here, as Wikipedia has a very good article on the same. Also, if you find the Wikipedia article mathematically daunting, you may read this alternative article here.

This demo is relatively simple and does not involve hours of soldering or anything. If there was anything that I had to devote time to, then it was the official ATMega32 datasheet. But it needs a lot of guts to even try to understand the terse(but correct) language of these datasheets. Something like legal-speak, every word has its own technical meaning and cannot be substituted by another word even if they are synonyms in the ‘normal’ english sense. So I spent about half a day getting familiar with the ins and outs of the AVR and finally sometime late in the night, I came up with this contraption for the demo.

Here is a small video of my demo. Do leave in your comments afterwards. And don’t forget to stay tuned for more upcoming AVR stuff !

seemanta Embedded Hobbyist, My Creations, 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 , , , , , ,

My tryst with the AVR microcontroller.

December 2nd, 2008

I am deeply attached to the 8051 microcontroller. In the truest sense, it has been my first love. It was the very first microcontroller which I was introduced to and then it was love at first sight. Even my undergraduate project work was based on the 8051 microcontroller. (Although sometime back I did purchase an Arduino board, which in fact has an Atmega16 microcontroller in it. But you know the thing with Arduino, the processing IDE abstracts out everything for you and I never really was HW-aware that I was working with an Atmega in the strictest sense. So in effect this particular project represents my true close encounter with the AVR series of microcontrollers).

So even when I started this hobby of creating embedded stuff for fun at home, it was my natural choice. I had my own development platform - both software and hardware for the 8051 and I enjoyed creating stuff using it. For an interesting story on how I got my development platform together for the 8051, take a look at this post.

Of late however, I decided it was time to see beyond the horizon of the 8051 microcontroller. So I decided to take upon a new beast. Two most popular choices were the PIC microcontroller and the Atmel AVR. After doing some research, I zeroed down on the AVR, chiefly for three reasons:

a) Most of the basic AVR micros had JTAG debugging. Till now the 8051 variant (AT89S52) I was using did not have any debugging facilities.

b) AVR packs in more MIPS for the same clock frequency compared to a PIC.

c) Freely downloadable and FULL version of the IDE for the AVR from its makers, Atmel. On the other hand the full version of the PIC development IDE from Microchip costs real money.

Besides, the AVR is much more advanced than the plain old 8051 which I am using currently. It has :

a) An in built 8 channel ADC. The AT89S52 has none.
b) An in built hardware SPI(Serial Perepheral Interface) and TWI(Two-Wire Interface). The AT89S52 has none.
c) An in built EEPROM to store program settings and persistent data. The AT89S52 has none.
d) An in built analog comparator. The AT89S52 has none.
e) An in built PWM generator to control DC motors and the like. The AT89S52 has none.
f) In built JTAG debugging, the MOST important factor for me. The AT89S52 has none.
g) The AVR RISC architecture has been designed ground up to be keeping in mind the C language. So very compact and high density code can be generated with the widely available avr-gcc C compiler. AT89S52, on the other hand was never designed to work with C, although there are compilers(both closed source and open source) which claim to generate efficient code.

Of course, there are about a zillion 8051 variants(SILABs, Analog Devices etc.) out there in the market today which boast of all these add on capabilities like ADC/SPI/USB connectivity etc. But I compared with only the plain vanilla 8051 (AT89S52) here, because that is the one I have used so far and also to level the playing field.

After an extensive research, I gathered the following list in order to realize a complete HW+SW development platform for my future AVR projects.

a) A programmer to ‘burn’ the hex files into my microcontroller : PonyProg(SW) + SIProg(HW).
b) A small ‘development’ board wherein I can prototype my creations before ‘deployment’ : ATMega32 Dev Board.
c) A compiler/assembler suite (possibly with an IDE) to create the software to run on the ATMega32.(AVRStudio, WinAVR)
d) A JTAG board to allow real time and in-system debugging of the microcontroller : Aquaticus JTAG Board .

It took about 2 days to create a) and b). As for c), I was able to very easily download them from the web. Currently, I am engaged in making d), the JTAG debugging board and once that is done, the setup for me development environment would be complete.

Oh, here are some pictures that I took yesterday of my first setup consisting of the programmer board and the development board. Please don’t mind the crudeness of my stuff. I am still to learn to make actual PCBs at home and so till then please adjust with the ugly-looking pre-drilled PCBs. I wrote a simple C program to blink an LED on and off to see if my setup was working properly.

img_0557

My own programmer board based upon the modified SI prog circuit. Notice the serial port connectors at top left corner. I admit, I could have made it much more compact. Also notice the crude power lines coiled up like a snake. For this board, I am drawing the needed 5 volts from the PC SMPS power supply.

The small development board with the ATMega32 in place along with the 8Mhz crystal and the power terminals.

The small development board with the ATMega32 in place along with the 8Mhz crystal and the power terminals.

My first AVR LED blinky program. The Program was written in the AVR Studio IDE, compiled using avr-gcc and programmed using my new SIProg programmer board.

My first AVR LED blinky program. The Program was written in the AVR Studio IDE, compiled using avr-gcc and programmed using my new SIProg programmer board.

So that’s about my first tryst with the AVR microcontroller. I hope you enjoyed reading it as much I enjoyed writing it.

I also do hope that my dear old 8051, does not get jealous and get me wrong. She is still my first love. AVR and I are just friends! ;-)

admin Embedded Hobbyist, My Creations, Tech , , , , , ,