Pwm channel, duty, period
|channel||PWM channel (0 to 15)|
|duty||Duty cycle (must be less than the period)|
|period||Maximum of 65535|
Outputs a pulse waveform whose shape is determined by the values of duty and period. Be aware that the PWM channel is different from the I/O port number. For the CB280, ports 5, 6, and 7 are used for PWM 0, 1, and 2. Before using Pwm, make sure to set the ports' I/O mode to output, and set their output to a known state (logic low or logic high).
Depending on the value of period, a PWM signal of up to 16 bit precision is generated. A period of 1024 is a 10 bit pulse and a period of 65535 is a 16 bit pulse. The pulse's actual frequency in Hz can be computed with the following formula.
Frequency = 2,304,000 / period
duty must to be less than period. The pulse's output will remain active for a fraction of the period given by duty/period. Pwm is independently hardware driven within the Cubloc. Once the Pwm command is executed, it will keep running until the PwmOff command is called.
Low 5 ' Set port 5 output and output LOW signal. Pwm 0,200,1024 ' Output 10-bit pulse with duty of 200 and width of 1024
PWM channels 0, 1, and 2 must use the same value for period since they share the same resources, but their duty cycles can be different. PWM channels 3, 4, and 5 also must use the same value for period, but again, their duty cycles can be different.
The following illustrates the PWM channels available on each module:
For CB220, 3 PWM channels are provided on ports P5, P6, and P7.
Please refer to the table below for PWM channels and their corresponding I/O ports.
|PWM0||I/O 5||I/O 5||I/O 5||I/O 8||I/O 5|
|PWM1||I/O 6||I/O 6||I/O 6||I/O 9||I/O 6|
|PWM2||I/O 7||I/O 7||I/O 7||I/O 10||I/O 7|
|PWM3||I/O 19||I/O 89||I/O 11||I/O 27|
|PWM4||I/O 20||I/O 90||I/O 12||I/O 28|
|PWM5||I/O 21||I/O 91||I/O 13||I/O 29|