Summary of 8 Channel PWM using AVR microcontroller
This article details an assembly code solution for the AT90S1200 microcontroller to generate 8 channels of high-frequency PWM. Unlike conventional PWM, this method maintains constant ripple voltage by varying pulse frequency relative to data values, ensuring consistent performance across duty cycles. The implementation supports 8-bit resolution at a minimum frequency of 60 Hz with a 4 MHz clock, which can be increased to 100 Hz by adjusting timer reload values or oscillator frequency.
Parts used in the 8 Channel PWM using AVR microcontroller:
- AT90S1200 microcontroller
- Assembly code
- Low pass filter
- Interrupt timer
- Clock oscillator
The assembly code given here was written to see what it would take to make an AT90S1200 generate 8 channels of proper PWM. In this case, by proper, I mean with the maximum high frequency content consistent with the needed duty cycle and give clock. Take a look at the scope shots below and notice that when the data value is =$02, there pulse frequency is twice that which occurs when the data value is =$01. The significance of this is that the percent of ripple voltage out of the low pass filter stays much more constant as the data values change than they would with a conventional PWM that merely varies the width of a single pulse (see the auto zero code for the RF Field Strength Probe for an example of code that does this). Take a look at the pictures below to see the effect.
When running with a 4 MHz clock, this code provides 8 channels of 8 bit resolution with a 60 Hz minimum frequency (which occur at data values of $01 and $FF. By adjusting the interrupt timer reload value, the minimum frequency can be taken to 100 Hz, but at the cost of time available for other tasks. Of course, changing the clock oscillator frequency is another way to increase the minimum frequency.
For more detail: 8 Channel PWM using AVR microcontroller
- What is the main benefit of this PWM method over conventional PWM?
The percent of ripple voltage out of the low pass filter stays much more constant as data values change. - How many PWM channels does the code generate?
The code provides 8 channels of 8 bit resolution. - What clock speed is used in the example?
The example runs with a 4 MHz clock. - What is the minimum frequency achieved with a 4 MHz clock?
The minimum frequency is 60 Hz when data values are $01 and $FF. - Can the minimum frequency be increased?
Yes, it can be taken to 100 Hz by adjusting the interrupt timer reload value. - What happens if you adjust the interrupt timer reload value?
Increasing the frequency comes at the cost of time available for other tasks. - Is there another way to increase the minimum frequency besides changing the timer?
Yes, changing the clock oscillator frequency is another way to increase the minimum frequency. - What happens to the pulse frequency when the data value is $02 compared to $01?
When the data value is $02, the pulse frequency is twice that which occurs when the data value is $01.

