Phase Correct PWM With ATmega328P - Ee-diary

Phase Correct PWM mode

The Phase Correct PWM mode is used to generate PWM signal at the output compare pins(either OC0A or OC0B depending upon which output compare unit A or B is used). It is called Phase Correct PWM because the generated PWM signal has symmetrical waveform nature which is due to its dual-slope nature of operation.

ATmega328p Phase Correct PWM mode

Modes of Phase Correct PWM mode

There are two Phase Correct PWM modes for Timer/Counter 0 unit. They are mode 1 and mode 5 which are selected using the waveform generation mode bits(WGM02, WGM01, WGM00) located in the TCCR0A and TCCR0B registers. The following table shows the WGM bits combination for mode 1 and mode 5.

The WGM02 bit is located in the TCCR0B register as shown below.

The WGM01 and WGM00 bits are located in the TCCR0A register as shown below.

The difference between the mode 1 Phase Correct PWM and mode 5 Phase Correct PWM is the TOP value. For mode 1 the TOP value is is 0xFF whereas the the TOP value for mode 5 is OCR0A. If mode 5 is used then we have to load count value into the OCR0A register. If mode 1 is used then we don't have to load the counter since the TOP value in this case is 0xFF. Once the mode is selected the counter is started and the timer/counter starts counting from zero to TOP value and when TOP value is reached the counting is repeated from the bottom.

Types of Fast PWM mode

There are two types of Phase Correct PWM modes:

(a) non-inverting Phase Correct PWM

(b) inverting Phase Correct PWM.

The Compare Output Mode bits (COM0A1 and COM0A0) located in the TCCR0A register are used to set up non-inverting or inverting mode for the output at OC0A pin. The following table shows how to select the COM0A1 and COM0A0 bits.

Similarly, the Compare Output Mode bits (COM0B1 and COM0B0) located in the TCCR0A register are used to set up non-inverting or inverting mode for the output at OC0B pin. The following table shows how to select the COM0B1 and COM0B0 bits.

Following picture shows the timing diagram for Phase Correct PWM which includes non-inverted and inverted PWM outputs.

Tag » Arduino Pwm Phase Correct