WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

Analogue Output - PWM

Provides a generic way of generating a hardware PWM signal.
The duty cycle of the PWM can be smoothed out to provide an analogue DC voltage output.
PWM has two main requirements:
1. The frequency: ie the 'off time' + the 'on time'
2. The duty cycle: the percentage of time that that the signal is 'on'
Once the 'frequency' has been set it cannot be changed - whereas the duty cycle will dictate the percentage of the time is spent 'on'. A duty cycle of 0 means that the output is always 'off', 100 means it always 'on' and there is a linear distribution in between these two values. ie a duty cycle of 50% means that it will spend half of its time 'on' and the other half 'off'.
Note that the overall frequency can only be set once per timer - whereas the duty cycle can be varied from 0% to 100% on each pin that is connected to the timer. So if you want multiple PWM outputs using the functions in this section then try to put all of the entries that require the same frequency on pins from the same timer.
For example: if you attempt to set up two pins with one pin requiring a frequency of 1 hertz and the second requiring 1000 hertz then you can run into problems if you use two pins from the same timer. Assuming that you set up the first pin then the timer is set to use 1 hertz and so the request for the second pin to use 1000 hertz cannot be honoured (as it would mess up the first pin).
Also note that the slowest frequency you can set will depend upon the clock speed and whether you are using an 8 bit or 16 bit timer.
For example: if you are using an 8 bit timer (maximum value of TOP = 255) on a 16 MHz board then the slowest frequency the library can create is by using a prescaler of 1024. This gives a frequency of about (16MHz / 1024)/256 = 61Hz. So if you want really low frequencies then you would be better choosing a 16 bit timer instead.
Function Summary

Valid XHTML 1.0 Transitional