Mikroelektronika MIKROE-724 データシート
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
437
PWMx_Mc_Init
Prototype
sub function PWMx_Mc_Init(dim freq_hz, pair_output_mode, enable_output_x,
clock_prescale_output_postscale as word) as word
Description Initializes the Motor Control PWM module with duty ratio 0. The function calculates timer period, writes
it to the MCU’s PTPER register and returns it as the function result.
Parameters -
freq_hz
: PWM frequency in Hz (refer to device datasheet for correct values in respect with Fosc)
-
pair_output_mode
: output mode for output pin pairs:
1
= independent,
0
= complementary.
If
pair_output_mode.B0
is equal to 1 then PWM channels PWM1L and PWM1H will be
independent,
If
pair_output_mode.B1
is equal to 0 then PWM channels PWM2L and PWM2H will be
complementary, ...
If
pair_output_mode.Bn
is equal to 1 then PWM channels PWM(n+1)L and PWM(n+1)H will be
independent,
If
pair_output_mode.Bn
is equal to 0 then PWM channels PWM(n+1)L and PWM(n+1)H will be
complementary.
-
enable_output_x
: bits <7..0> are enabling corresponding PWM channels <
PWM4H
,
PWM3H
,
PWM2H
,
PWM1H
,
PWM4L
,
PWM3L
,
PWM2L
,
PWM1L
>.
If bit value is equal to
0
then corresponding PWM channel is disabled (pin is standard I/O).
If bit value is equal to
1
then corresponding PWM channel is enabled (pin is PWM output).
For detalied explanation consult the “Motor Control PWM Module” section in device datasheet
-
clock_prescale_output_postscale
: PWM clock prescaler/postscaler settings. Values
<0..3>
and <0..15>
correspond to prescaler/postscaler
<1:1, 1:4, 1:16, 1:64> and <1:1, 1:2,
..., 1:16>
Returns
Calculated timer period.
Requires
The dsPIC30/33 MCU must have the Motor Control PWM module.
Example
‘Initializes the PWM1 module at 5KHz, complementary pin-pair output, output
enabled on pins 4l..1l, no clock prescale and no clock postscale:
dim duty_50 as word
...
duty_50 = PWM1_Mc_Init(5000, 1, $0F, 0)
Notes
- Number of PWM modules per MCU differs from chip to chip. Please, read the appropriate datasheet
before utilizing this library.
- PWM library routines require you to specify the module you want to use. To use the desired PWM
module, simply change the letter
x in the routine prototype for a number from 1 to 2.