11
janvier
2009
PWM 4 canaux en C sur Attiny2313
posté dans Electronique |
Juste un petit bout de code en passant. Pour ceux qui voudraient utiliser les 4 canaux de PWM des Amtel AVR Attiny2313, voici la configuration :
DDRB |= (1<<PB2); // make OC0A an output DDRD |= (1<<PD5); // make OC0B an output DDRB |= (1<<PB3); // make OC1A an output DDRB |= (1<<PB4); // make OC1B an output TCCR0B = 0; // stop timer 0 TCCR0A = (1<<WGM00)|(1<<WGM01); // select fast pwm mode 3 TCCR0A |= (1<<COM0A1); // Clear OC0A on Compare Match when up-counting. // Set OC0A on Compare Match when down-counting. TCCR0A |= (1<<COM0B1); // Clear OC0B on Compare Match when up-counting. // Set OC0B on Compare Match when down-counting. OCR0A = 0x00; // duty cycle OCR0B = 0x00; // duty cycle TCCR0B |= (1<<CS00); // no prescaling, timer on TCCR1B = 0; // stop timer 1 TCCR1A = (1<<WGM12)|(1<<WGM10); // Fast PWM, 8-bit mode 5 TCCR1A |= (1<<COM1A1); // Clear OC1A on Compare Match when up-counting. // Set OC1A on Compare Match when down-counting. TCCR1A |= (1<<COM1B1); // Clear OC1B on Compare Match when up-counting. // Set OC1B on Compare Match when down-counting. OCR1A = 0x00; // duty cycle OCR1B = 0x00; // duty cycle TCCR1B |= (1<<CS10); // no prescaling, timer on
Il ne reste, ensuite qu'à changer la valeur de OCR0A, OCR0B, OCR1A ou OCR1B pour modifier le rapport de phase.
Article posté
on Dimanche, 11 janvier 2009 à 20:23 dans Electronique.
Vous pouvez suivre les commentaires sur cet article via un feed RSS 2.0.
Commentaires et pings fermés.