我正在研究Atmega328数据表中的波形生成模式位描述。我有两个疑问。 1.什么是OCRx的更新(附图中标记为1)。 OCRx由程序员编写。是否意味着即使在写入之后,只有在PWM模式下它才会在TOP或Bottom处更新? 2.在CTC模式下,TCNT在比较匹配时清零。 MAX始终为0xFF。那么TOV标志如何在MAX生成?当TCNT = OCRA时,TCNT被清除了吗?我在图中将其标记为2。
支持评论的其他信息:
void timer0LEDBlinkTestCTCMode (void)
{
DDRB|=(1<<0);// // Set LED port as Output to toggle the LED.
DDRB|=(1<<1);// // Set LED port as Output to toggle the LED.
OCR0A = 0xff;
TIMSK0 |= (1<<OCIE0A)|(1 << TOIE0); // Output Compare Interrupt Enable for TimerCounter0 Compare Match A
TCCR0A |= 1<<(WGM01); // Mode = CTC: WGM01=1, WGM00=0 in TCCR0A and WGM02=0 in TCCR0B
sei(); // Enable global interrupt
// Timer is activated as soon as the clock source is selected
TCCR0B = (1<<CS02)|(1<<CS00); // Timer Prescaler Clock/1024, TCCR0B: CS00 - 1, CS01 - 0, CS02 - 1
}
//This is the ISR for Compare Mode A
ISR(TIMER0_COMPA_vect)
{
sei(); // Enable the interrupt because both interrupts may occur simultaneously.
PORTB ^= 1<<0;
}
ISR (TIMER0_OVF_vect) // timer0 overflow interrupt
{
sei();
PORTB^=1<<1; // Toggle the LED
}
答案 0 :(得分:3)