PDA

View Full Version : C code for Atmega16



shyam4uall
11-15-2008, 10:08 PM
Guys i am not so good in embedded programming with C.I need to generate PWM signal from Atmega16 with 15Khz and 50% duty cycle.

I am using WinAVR but not able to code it.Can anyone give me a sample code.

maddy_nish
11-17-2008, 01:00 AM
Try this..

also refer data sheets.. they giv u good idea..




#include <avr\io.h>
#include <avr\signal.h>

int main(void)
{

//Set portD, PD7 to output
DDRD = (1<<PD7);
//Set the Waveform generation mode for timer2.
TCCR2=1<< WGM21;
//assuming clock frequency to be 1mhz
TCCR2=1<<CS21;
OCR2 = 3; 15khz at 50% duty cycle
while(1)
{


}// end of while
}


compiled in avr studi4

bye!!