Author | Stef Mientki, Copyright (C) 2002-2006, all rights reserved. |
Adapted-by | Sebastien Lelong |
Compiler | 2.4l |
This lib handles common operations on PWM, regardless the channel number. It is used in combination with one or more pwm_ccplibraries (eg. pwm_ccp1.jal, pwm_ccp2.jal, etc.). These libraries are included automatically dependent of the configuration of the target PIC.
This is a heavy refactoring of the original pwm_hardware.jal (Stef's lib).
No dependency found
var volatile word _pr2_shadow_plus1 = 256 -- value(PR2) + 1
Shadow of PR2 (value incremented by 1, i.e. value in range 1..256)
pwm_max_resolution(byte in prescaler)
Sets all(!) CCP modules for max (10-bits) PWM resolution. While setting maximum resolution, the Timer2 prescaler can be used to adjust frequency to a some extent with the Timer2 parameter value which can be either: * 1 : high frequency * 4 : medium frequency * 16: low frequency Below a table showing the PWM frequencies for common clock speeds and different Timer2 prescaler values. ||*Timer2 prescaler* || *4MHz* || *8MHz* || *10MHz* || *20MHz* || || 1 || 3.90 kHz || 7.81 kHz || 9.77 kHz || 19.43 kHz || || 4 || 976 Hz || 1.95 kHz || 2.44 kHz || 4.88 kHz || || 16 || 244 Hz || 488 Hz || 610 Hz || 1.22 kHz || For PICs with more than one CCP module you should realize that all CCP modules use Timer2 and PR2 for PWM operations. This means that the PWM period (frequency) of all PWM output pins is the same. Only the duty cycle can vary between one and another PWM pin. Set PWM to maximum resolution (for all PWM pins!). This implies 1 out of 3 specific PWM frequencies, depending on the Timer2 prescaler value passed with the call. See examples in the table above, or use the formula in the datasheet to calculate the resulting frequency.
pwm_set_frequency(dword in freq)
Sets all(!) CCP modules for a specific PWM frequency. The minimum and maximum allowed PWM frequencies depend on the clock speed. When specifying a value beyond the limits PWM will not be started. The chosen frequency may enforce a limit on the PWM resolution (number of steps). The application program should not specify a higher value for the duty cycle than this limit. When exceeding this limit the dutycycle will probably result in a 'weird' value. Only the procedure set_dutycycle_percent() is safe in this case, the other set_dutycycle procedures use absolute values and are not safe!