ATmega8(L) PWM

Loading thread data ...

Есть эти биты в ATmega8. В даташите на стр. 97.

Не знаю. У меня работает в Normal, Phase correct и Fast PWM. WGM12:0 и WGM13:0 живут в другом регистре, в TCCR1B, может в этом дело?

Кто? ;-)

С уважением, Сергей Борщ

Reply to
Sergey A. Borshch
Reply to
Vladislav Baliasov
Reply to
Michael Ryazanov

А как именно у тебя не работают?

Вот Phase and Frequency correct. Я ошибся, Phase Correct не пользовал - то письмо писал из дома а исходники на работе были.

#define KHz *1000L #define OSC (12800 KHz) #define PWMFreq (100 KHz) #define PWM OCR1B #define PWM_IE (1<<TOIE1)

#define PWMTicks (((OSC / PWMFreq) / 2) * 2) #define Amplitude ((PWMTicks/4 - 1)*0.8) #define Offset (PWMTicks/4)

char __low_level_init() { PORTB = (0<<7)|(0<<6)|(1<<5)|(0<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0); DDRB = (0<<7)|(0<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0);

// use CC-B as PWM generator TCCR1A = (0<<COM1A1)|(0<<COM1A0)|(1<<COM1B1)|(1<<COM1B0)|(0<<WGM11)|(0<<WGM10); TCCR1B = (0<<ICNC1)|(0<<ICES1)|(1<<WGM13)|(0<<WGM12)|(0<<CS12)|(0<<CS11)|(1<<CS10); ICR1 = PWMTicks / 2; // Set PWM frequency PWM = PWMTicks / 4; // generate 0.5 Vcc level

return 1; }

static unsigned char Phase=0, Step=1;

#pragma vector = TIMER1_OVF_vect __root __interrupt void FFSK_PWM_Handler (void) { // sinus generator unsigned char Tmp; Tmp = Phase + Step; // next phase if(Tmp >= SinTableLen) { // overflow Tmp -= SinTableLen; // get reminder Phase = Tmp; // store phase Tmp = SinTable[Tmp]; // read table Tmp = Offset + Tmp; // add offset PWM =Tmp; // set new duty }

Ну примерно так. Это я выдрал из большой программы, вроде ошибок не наделал.

С уважением, Сергей Борщ

Reply to
Sergey A. Borshch

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.