Archive

Posts Tagged ‘AVR’

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

Embedded development platforms I own

April 21st, 2009

I started creating small embedded projects for fun about a year and a half back. Since then I have been hooked into it and today it takes the entirety of my free time. I started out with the humble 8051 and along the way have had the fortune of laying my eyes on the sexy Arduino, the powerful AVR and even the austere MSP430. A list of my embedded projects can be accessed here.

Here is a brief overview of the platforms that I own, as of this writing. By platform, I mean a hardware and software setup that allows me to write code in C or assembly, compile/assemble that code, ‘burn’ that binary into the target microcontroller and then possibly debug that ‘burned’ code.

1. AT89S52 development platform: This is the very first platform I ever owned. I purchased this from a company in Gujarat (a western province in India) called Sunrom. I am very satisfied with their product although a bit disappointed with the company for the lack of Linux support for its flashing software. I chose this as my first platform since I was most familiar with the architecture of the ATMEL AT89S52. AT89S52 has a 8-bit CISC architecture.

AT89S52 Development Platform

My AT89S52 Development Platform

Type: Purchased
Approximate cost2250 INR (2006)
On Chip Debug support: No
Linux support: No. But I created a ‘reverse-engineered’  linux port for its flashing software. Look here.
Cons: Lack of Linux support from Sunrom and on chip debug.
Pros: Availability of some very good development tools like SDCC, ASEM51 etc.
My Comments: Best system to start embedded development at a minimum cost. Good value for money.
Overall Rating: 4.0/5

2. MSP430 EZ430-RF2500 USB development tool: I went to attend the MSP430 day conducted by Texas Instruments all over the globe and they gave this USB development tool as a free sample. This tool can be programmed via the IAR IDE that runs on windows through the PC USB. For the unitiatiated, MSP430 is a range of ultra low power microcontrollers from Texas Instruments. It has a 16-bit RISC architecture. Frankly speaking, I have never created any big project with the MSP430. Main reason being that for it to work, a separate 3.7 V power supply is needed for this ultra low power beast. Normal 5 volts that we use usually for other micros would fry it. But the circuit components would still need 3.7 volts. Thus, a kind of isolation would be needed to make sure that the 5V does not flow into the MSP430. This is one reason, I have never tried making anything with this platform. It just lies in my shelf, gathering dust till the moment of its beckoning comes.

A plus point however is that Texas Instruments have also created DIP version of this microcontroller which helps the hobbiyst who is occasional not well equipped to perform SMD soldering.

MSP430 Development Platform

My MSP430 Development Platform

Type: Free Sample given by Texas Instruments for MSP430 day attendees.
Approximate cost: 40 USD, if I remember correctly.
On Chip Debug support: Yes
Linux support: GCC port of MSP430 seems to work in Linux, but have heard horror stories from people trying to make the USB tool which I have work in Linux. Problem is compounded by Texas Instruments not releasing the sources for the DLL needed to talk with the USB stick tool.
Cons: Lack of proper Linux support. IAR compiler does not work beyond 4k code size.
Pros: DIP version is hobbyist friendly and availability of MSP-GCC is a boon for those who cannot afford the IAR C compiler.
My Comments: Not recommended for newcomers.
Overall Rating: 2.5/5

3. Arduino: This tiny physical computing platform has taken the embedded hobby world by storm. There are thousands of websites all over the web with thousands of cool arduino projects. Arduino is easy to learn and easy to program. But while many people would recommend it for newcomers, I would really not do so. Arduino lets users program at a somewhat abstract level using its IDE which is based on processing. I firmly believe that someone should start with embedded development with the guts-first approach, i.e. learn the architecture from inside out and start programming in assembly language before graduating to high level languages like C or processing/wiring.

Arduino Development Platform

My Arduino Development Platform

Type: Purchased
Approximate cost: 35 USD, back in 2008.
On Chip Debug support: No
Linux support: Yes. Arduino works out of the box with my laptop which has Ubuntu Intrepid Ibex.
Cons: Lack of on chip debug really makes creating complex stuff a pain in the butt.
Pros: Lots of sites on the web to start development.
My Comments: Not recommended for newcomers. But would readily recommend for experienced developers.
Overall Rating: 4.0/5

4. AVR ATmega: This is my latest acquisition in the world of embedded platforms. I hand made this myself after hours of backbreaking soldering sessions. But every minute of those sessions was wortwhile when I was able to use plain old GDB to perform hardware debugging of my target board. And did I mention, it works in windows too ? You just need to install win-avr and avr studio :-) .

For the uninitiated, AVR is a RISC architecture from ATMEL and is wildly popular among hobbyists. The best thing about AVR is the availability of the completely free GNU tool chain for this arcthitecture which is why is it so much popular among students and hobbyists.

AVR ATMega Development Platform

My AVR ATMega Development Platform

Type: Hand made
Approximate cost: 300 INR or 7.5 USD (Believe me !!)
On Chip Debug support: Yes.
Linux support: Yes. AVR ATmega is fully supported on Linux through AVaRice and the AVR port of the GNU toolchain.
Cons: Might be a bit daunting for the absolute noob to make this with bare hands, but then it can be also purchased from ATMEL but be ready to shell out in the range of 100 USD.
Pros: Very hacker friendly, and GNU/Linux friendly too. Works on windows along with win-avr and avr studio.
My Comments: Excellent  for newcomers. Also a great way to learn basics of soldering and embedded development.
Overall Rating: 4.5/5

So this completes my review. And no prizes for guessing who the winner is!. It is no doubt the AVR platform that steals the show. And why not? With its powerful on chip debug, 100% free GNU tool chain, GDB compatible software, Windows plus Linux compatibility, AVR really does steal the show.

That is all the time I have this time. Happy embedding!!
With this thought, I now take your leave and would see you all in my next post!

regards,
Seemanta

admin Embedded Hobbyist , , , , , , ,

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