Pulse Width Modulation (PWM) frequency calculations are based on the Firewing default clock running at of 32MHz. For information on PWM frequency and resolution calculations used by this module, please select the following:
Please note that the following PWM routines require the use of the microcontroller Timer 2 module. This timer peripheral should therefore not be used when using this module.
sub Open(portPin as bit)
- portPin - PWM port pin to open. Can be D3, D5, D6 or D9.
Open the PWM port specified by portPin.
sub Close(portPin as bit)
- portPin - PWM port pin to close. Can be D3, D5, D6 or D9.
Close the PWM port specified by portPin.
sub Write(portPin as bit, duty as UShort)
- portPin - PWM port pin to write to. Can be D3, D5, D6 or D9.
- duty - The duty cyle value. Can be 0 to 1023 (10 bit).
Sets the duty cycle for a PWM port pin. The pin must have been previously opened with a call to open. For example:
' assumes LED connected to D3... Pwm.Open(D3) ' open the port Pwm.Write(D3, 100) ' set the brightness
sub SetFrequency(freq as Frequency)
- freq - set the PWM frequency for all PWM port pins. Allowable values are Frequency.Is15KHz, Frequency.Is1953Hz, Frequency.Is244Hz and Frequency.Is61Hz. Default is Frequency.Is244Hz.