ATMega_2560_Embedded_THT/PWM_Module/PWM_deadtime/main.c

24 lines
610 B
C
Raw Normal View History

2022-10-04 18:52:43 +05:30
#define F_CPU 16000000//16Mhz
#define MS_DELAY 1000
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB = 0xFF;//Port B set as output
2022-10-05 20:05:08 +05:30
OCR0A= 0x7F;//50 percent of 255=duty cycle//decimal=127
2022-10-04 18:52:43 +05:30
TCCR0A = 0x83;
2022-10-05 20:05:08 +05:30
//TCCR0B = 0x03;//prescaler = 64 for 1kHz
TCCR0B = 0x02;//prescaler = 8 for 8kHz
2022-10-04 18:52:43 +05:30
//output at OC0A=pin 13
2022-10-05 20:05:08 +05:30
//OCR2A= 0x87;//duty cycle= 47 percent, value= 0.53*255=135
OCR2A= 0x83;//duty cycle= 48 percent, value= 0.52*255=131
2022-10-04 18:52:43 +05:30
TCCR2A = 0xC3;//inverting PWM
2022-10-05 20:05:08 +05:30
//TCCR2B = 0x04;//prescaler = 64 for 1 kHz
TCCR2B = 0x02;//prescaler = 8 for 8kHz
2022-10-04 18:52:43 +05:30
//output at OC2A=pin 10
while(1);
}