Simple c-programs for input and hardware PWM.

Here are two programs that use the A/D converter in the AVR tiny 45 in a simple way.  The first does an analog read every 1/2 second and sends the most significant byte of the result through the serial output at 9600 baud.  The second reads an analog input and uses the result to set a PWM duty cycle, using the hardware PWM.

Refer to comments in the programs, and to the AVR tiny45 datasheets for explanations.  Note that the code is transferrable to other chips with little or no alteration.

1. Here is a simple program and makefile to make an A/D conversion and read the most significant byte to serial.



2. Here is a program that alters PWM in response to the A/D read.