Final WinAVR 20070525 Released

Topics:

Finaly WinAVR has a new stabile buil. As mentioned in RC2 they have changed several things in new build:

  • Simplified installer no more un-installation of previous version, so you need to un-instal older version before installing new one;

  • Registry keys are tied to WinAVR version, what will allow to have multiple instances of WinAVR's on same machine;

  • Newer GCC 4.1.2 included;

  • New version of avr-libc1.4.6 with many bug-fixes;

  • New version of GDB/Insight 6.5 with expanded manual. GDB is no more tied to Cygwin – it is native WIN32 executable;

  • support foe newer devices added (AT90USB82, AT90USB162, Atmega325P, Atmega3250P, Atmega329P, Atmega3290P, AT90PWM1, Atmega16HVA, ATmega8HVA );

  • LibUSB-Win32 drivers included to work with Atmel JTAG ICE mkII and AVRISP mkII;

  • New version of Srecord 1.31;

  • New version of Programmers Notepad 2.0.7.667-devel;

  • Newer MFile with updated template.

Analog to Digital Conversion in AVR

Input signals in microcontrollers may be digital or analog. Digital signal may have two values “0” and “1” while analog any value in given interval. while AVR microcontroller may operate with only digital signals, analog signals have to be converted to digital. Mega series of AVR have built in ADC inside chip what makes this task much easier. Lets take Atmega8 as example. If Atmega8 DIP, then it has 6 ADC inputs, if package is TQFP-32 or MLF, then there are two additional ADC inputs. All ADC channels have 10 bit resolution. Bellow you see simplified Atmega8 ADC unit. Input signals come from pins PC0-PC5. Then enters multiplexer and according to ADMUX register signals is sent from one pin to ADC converter.

Typical circuits of AVR microcontrollers for fast start

All AVR microcontrollers contain same AVR core which is RISC architecture. So program or its parts written for one AVR will work in another AVR microcontroller. So it is enough to learn one AVR MCU and you can work with all other.

To make circuit work normally you need to follow several conditions: apply power supply, clock device, organise reset after power-up and connect peripherals to I/O. All this information you can find in data-sheets. By the way, Atmel datasheets are very well organised and unified. They are easy to read and there is no stress when changing AVR microcontrollers because you intuitively know where to find required information without pain. If you take like NXP ARM MCU documentation you will see how hard can it be to access required information, because datasheets are poorly organized while microcontrollers are really good. But leave this for another topic.

How to combine C program with external ASM

Sometimes it is useful to program some parts in assembly language while whole program is written in C. There are two methods how to inject assembler parts in C program. One of them is to write in-line ASM and another is to link existing assembler program. For instance some parts of program may require critical timings and you are not sure if C compiler can be as optimal as you expect. Other reasons according to avr-libc

documentation may be as follows:

  • Code for AVR's that have no RAM;

  • Very timing critical applications;

  • Special tweaks that cannot be done in C.

As I mentioned all this can be also done using in-line assembler feature. For somebody in-line assembler may look too complicated because of special syntax requirements. Before starting to write assembler program first read (What Registers are used by the C compiler) to ensure you are using right registers in your assembler program and won't mess up the normal program flow by occupying registers that are storing values from other routines. In most cases push and pop may do the job.

Measuring motor speed and display result on LCD

For measuring motos speed there can Optical interrupter used like H21A1. This is a device where IR LED and photo-transistor is coupled in to plastic housing. The gap between then allows interrupting signal with opaque material and this way switching the output from ON to OFF.

This device can be connected to Microcontrollers ICP pin and this way measuring PWM disk (with hole in it) speed can be measured. Disk has to me fixed to axis of motor. Each time the hole of disk passes the gap, optical interrupter will form a pulse which goes to ICP pin to trigger the timer. If take measuring interval 1s, then counted pulses will be equal to turns in Hz.

Lets take Atmega8 microcontroller which is clocked at 8MHz. For this lets use timer pre-scaler 8, then timer will run at frequency equal 1MHz(period 1μs ). Each time the pulse reaches ICP(Atmega8 – PB0 pin) pin then on falling front of pulse input capture interrupt occur. Interrupt service routine counts the number of timer pulses between two pulses. Number of timer counts define the disk speed (RPM - revolutions per minute).

Simplified AVR LCD routines

Controlling numeric LCD isn't so tricky as it may look like. O course you can find numbers of LCD libraries. One of more universal you can find in AVRLIB library for WinAVR AVR GCC compiler. Main disadvantage of such universal libraries that they compile all functions even if you don't want them. This way huge libraries occupy more program memory than you would like to. One way is to write simple routines specified only to your design.

My simple LCD library include only 8 bit mode. Each pin, connected to LCD, can be configured separately. For instance:

AVR LCD menu routine

Lets have some practice and write simple AVR LCD menu routine. For this we need to write LCD control library. I decided not to use one from AVRLIB. LCD controlling isn't difficult just a few lines of code unless you want to make it more universal.

I want to demonstrate how LCD menu control may look. Of course this isn't the best practice as it uses pretty simple logic, but may do the job.

To make it interesting I am going to have 4 buttons: 2 for menu scrolling up and down and two for changing submenu parameters. As output I am going to use three LED diodes that will light according to parameters selected in menu. Button states are going to be read using timer0 overflow interrupts. Code is written for WinAVR compiler.

Avr-gcc versions comparison

AVR-GCC versions comparison By Dmitry K. 
Flash and Stack values are in bytes. 
Time units are in CPU clocks. 
All values were simulated by simulavr. 
Times and sizes are presented without initialization of function args.
Results 
 
 
 

 
AVR:                             at90s8515                 atmega8      
avr-gcc version: 3.3.6 3.4.6 4.0.4 4.1.2 3.3.6 3.4.6 4.0.4 4.1.2
--------------------------------------------------------------------------
dtostre(1.2345,s,6,0)
Flash: 1024 1024 1120 1212 954 954 1038 1112
Stack: 15 15 15 17 15 15 15 17
Time: 1199 1199 1289 1315 1060 1060 1123 1155

Servo motor control using AVR

Servo motors are so called “closed feedback” systems. This means that motor comes with control circuit, which senses if motor mechanism is in desired location and if not it continuously corrects an error until motor reaches proper point.

Servo motors are widely used in robotics, remote controlled planes, vehicles. So they come in many shapes and sizes, but they operate in almost the same way. Usually Servo motors are controlled by computer, microcontroller or even simple timer circuit. Of course you may find more advanced servos – R/C so called radio controlled. But again, they are same servos just it takes signals from receiver.

How Servo Motor Control Works

Usually servo motors are put in plastic box, but inside there is a whole system: motor itself, gears and motor driving and control circuit.

New WinAVR20070122 has been released

Topics:

This is quite long waited release for those who are working with ATmega2560, and ATmega2561

devices. WinAVR20070122 major changes are:

  • GCC compiler jumped to 4.1.1 version;

  • Added devices ATmega2560, and Atmega2561;

  • DWARF2 debugging information moved from 16 to 32 bit addresses. Now debugging is possible with bigger than 64k codes for Atmega128, Atmega1281 and new devices ATmega2560, and Atmega256. Good news for AVR Studio users. AVRStudio V4.13 is now available as a Beta at http://www.atmel.no/beta_ware/ that supports 32bit debugging;

  • Package also includes new AVR-Libc with new examples and many bugs fixed;

  • New AVRDude 5.3.1;

  • New AVRICE with AVR JTAG ICE mkII support;

  • New Binutils and Srecord;

  • And of course updated Makefile template and Mfile as well.

Pages

Subscribe to WinAVR AVR-GCC Tutorial RSS