If you configure timer1 (ATmega328P as in Uno etc.) to use fast PWM ( Wave Generation Mode 14) you can get up to 8 MHz for a 16MHz clock if the timer is set to directly manipulate a pin dedicated to it, in this case OC1A (pin D9):
//set timer1 toggle at xHz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
ICR1 = 1 ; // set TOP
OCR1A = 0 ; // set duty cycle
TCCR1A |= ( 1 << COM1A1 ) | (1 << WGM11) ;
// wg mode 14
TCCR1B |= (1 << WGM12) | (1 << WGM13);
// prescaler 1
TCCR1B |= (1 << CS10) ;
If you configure timer1 (ATmega328P as in Uno etc.) to use fast PWM ( Wave Generation Mode 14) you can get up to 8 MHz for a 16MHz clock if the timer is set to directly manipulate a pin dedicated to it, in this case OC1A (pin D9):
//set timer1 toggle at xHz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
ICR1 = 1 ; // set TOP
OCR1A = 0 ; // set duty cycle
TCCR1A |= ( 1 << COM1A1 ) | (1 << WGM11) ;
// wg mode 14
TCCR1B |= (1 << WGM12) | (1 << WGM13);
// prescaler 1
TCCR1B |= (1 << CS10) ;
ความคิดเห็น
แสดงความคิดเห็น