AVR tutorial 6


Using one of the AVR's PWM channels.

Last change : 13 November 2006 recompiled using WinAVR 20060412.

25 November 2005 : compiled using WinAVR 20040404.

Here is a capture of the traffic on the serial port terminal application.
In this example the user entered a duty cycle on 10%, then changed it to 90%.


.....................................
Serial port to PWM test application
by Murray Horn.
From www.opend.co.za
.....................................
Enter duty cycle [0..100]
10
PWM set to 010%
Enter new duty cycle [0..100]
90
PWM set to 090%
Enter new duty cycle [0..100]


Circuit diagram



Software.

The files included :
pwm.gif : the above circuit diagram.
main.c : the main c application.
uart001.c : the uart routines.
uart001.h : the header file used by main.c for the function prototypes.
uart001.inc : a file used by main.c and uart001.c for constants and defines.
pwm001.c : the pwm routines.
pwm001.h : the header file used by main.c for the function prototypes.
makefile : the file created by AVRMakeGen.

Download (19KB) the software and diagram in one Zip.

Serial setup.

9600 baud.
1 stop bit.
0 parity bits.
Full duplex

For a terminal application, use Hyper Terminal or the terminal application found here.


How to.

To build your project simply extract all the files to the same directory.
Next, using programmers note pad, open main.c.
Now click on tools and then on make all.

Note: The provided makefile is generated for a SP12 type programmer as shown in tutorial 2. If you are using a different programmer you'll have to edit the makefile.

Program the device, insert it into the circuit and plug the db9 into your PC's serial port.
Power up the circuit.
Using a terminal application send a character to the AVR. Either place a LED or a oscilloscope on pin 15 to monitor the pwm output duty cycle.


Forward to tutorial 7

Home mail add