[McHUG] Playing with WinAVR

Rich Mitchell geobra at att.net
Tue Apr 8 11:17:12 EDT 2008


Over the weekend I installed the Arduino setup and tried some of the example programs that came with it - with good success as I reported.  Since I also installed WinAVR, last night I decided to try the Simple example program that came with it.  Like Blink (the first Arduino program) its output is to an LED.  BUT it doesn't blink, it pulses.  The Blink program turns the LED 100% on or 100% off.  The simple demo uses something called Pulse Width Modulation (PWM) which changes the duty cycle applied to the LED.  The duty cycle will vary from 0% to 100% and back, makeing the LED pulse rather than blink.  Each time timer1 overflows, the interrupt handler increments or decrements the PWM.  You can see this happening in the program since it is written in C without the Arduino files providing a higher level of developer interface.  Yeah, PWM can make a LED pulse, but one of its main uses is to control the speed of a DC motor.

To run this program, all I had to do was hook up a LED (with internal resistor) between BareBones Board pin 9 and ground.  I then loaded the demo.c program and the iocompat.h files into my own folder from the doc/avr-libc/examples/demo folder of WinAVR.  I copied the same makefile I was using with the Si570 program to that folder and modified it to run demo.c.  I used the makefile to compile it and load it into the BBB.  Sure enough, the LED pulsed.

They have another sample program that's a bit more complex.  It was written for the ATmega16 on the STK500 development kit.  So it will take a bit more effort to run on the BBB.

73,
Rich, N3III

--
McHUG - Physical Computing ;) 
MicroController Ham User Group


More information about the McHUG mailing list