User manual

mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
438
PWMx_Mc_Stop
Prototype
procedure PWMx_Mc_Stop();
Description Stops the Motor Control PWM module.
Parameters None.
Returns Nothing.
Requires The dsPIC30/33 MCU must have the Motor Control PWM module.
Example
‘ stop the Motor Control PWM1 module
PWM1_Mc_Stop()
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.
Library Example
The example changes PWM duty ratio on channel 1 continually. If LED is connected to the channel 1, a gradual change
of emitted light will be noticeable.
Copy Code To Clipboard
program PWM;
var pwm_period, current_duty : word;
begin
ADPCFG := 0xFFFF; // initialize AN pins as digital
PORTB := 0;
TRISB := 0; // initialize portb as output
current_duty := 10;
Delay_ms(1000);
pwm_period := PWM1_MC_Init(5000, 1, 0x01, 0); // Pwm_Mc_Init returns calculated timer
period.
PWM1_MC_Set_Duty(current_duty, 1);
PWM1_MC_Start();
while (TRUE) do
begin // Endless loop
if (RB0_bit) then // Button on RB0 pressed
begin
Delay_ms(20);
Inc(current_duty); // Increment current_duty
if (current_duty > pwm_period) then // If we increase current_duty greater
then possible pwm_period value
begin
current_duty := 0; // reset current_duty value to zero
end;
PWM1_MC_Set_Duty(current_duty, 1); // Set newly acquired duty ratio
end;