CPU: PWM Base Frequency
The analog outputs on most controllers are in reality pulse width modulated digital outputs. They can be filtered to produce an analog voltage. The duty cycle (percentage ON time) of the signal is proportional to the number sent to the output by an fAnOut
instruction. The default frequency of the PWM signal is 16kHz for an 8 bit controller and 40kHz for a 32 bit controller. This can be changed by executing the following code:
SetU 0,U0
SPxCmd1 0,!CPU
where U0
is taken from the following table:
U0 | PWM frequency |
---|---|
0 | 16kHz |
1 | 8kHz |
2 | 4kHz |
3 | 2kHz |
4 | 1kHz |
5 | 500Hz |
6 | 250Hz |
7 | 125Hz |
8 | 50Hz (RC servo) |
The 50Hz frequency is particularly suitable for driving RC (hobby) servo motors. The other frequencies give a range of choices for, for example, controlling the speed of DC motors.
A MMi203 has slightly different frequencies as follows:
U0 | PWM frequency |
---|---|
0 | 18kHz |
1 | 9kHz |
2 | 4.5kHz |
3 | 2250Hz |
4 | 1125Hz |
5 | 562.5Hz |
6 | 281.250Hz |
7 | 140.625Hz |