In non-inverted mode, the pulse is stared at the beginning of the period. The Period to match 50 Hz (20 ms period time frame), a timer/counter is used and the top value ICR1 is set at 19,999.
To set non-inverted mode, the COM1A1 is set and COM1A0 is not set.
The OCR value is set to correspond to the non-inverted mode so it is set at the low end of the timer/counter count. 2 ms would be equal to 2000. In inverted mode, the 2 ms would be equal to 19,999 - 2000 since the pulse is at the end.
To initialize the PWM (Pulse Width Modulation) for non-inverted mode:
DDRD |= 0xFF;
TCCR1A |= 1<<WGM11 | 1<<COM1A1;
TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS10;
ICR1 = 19999;
In the never ending loop:
While (1)
{
OCR1A = 800;
_delay_ms(100);
OCR1A = 2200;
_delay_ms(100);
}
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.