User manual
433
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
PWM_Start
PWM_Stop
Prototype
procedure PWM_Start(enable_channel_x : byte);
Description Starts PWM at requested channel.
Parameters - enable_channel_x: number of PWM channel
Returns Nothing.
Requires MCU must have the HW PWM Module.
PWM channel must be properly congured. See the PWM_Init and PWM_Set_Duty routines.
Example
‘ start PWM at channel 1
PWM_Start(1)
Notes Number of available PWM channels depends on MCU. Refer to MCU datasheet for details.
Prototype
procedure PWM_Stop(disable_channel_x : byte);
Description Stops PWM at requested channel.
Parameters - disable_channel_x: number of PWM channel
Returns Nothing.
Requires MCU must have the HW PWM Module.
Example
‘ stop PWM at channel 1
PWM_Stop(1)
Notes Number of available PWM channels depends on MCU. Refer to MCU datasheet for details.
Library Example
The example changes PWM duty ratio on channels 1 and 2 continuously. If LEDs are connected to channels 1 and 2,
a gradual change of emitted light will be noticeable.
Copy Code To Clipboard
program Pwm_Demo;
var current_duty, old_duty, current_duty1, old_duty1 : word;
pwm_period1, pwm_period2 : word;
procedure InitMain();
begin
ADPCFG := 0xFFFF; //
TRISB := 0xFFFF; // congure PORTB pins as input
PORTD := 0; // set PORTD to 0
TRISD := 0; // designate PORTD pins as output
end;
begin
InitMain();
current_duty := 16; // initial value for current_duty
current_duty1 := 16; // initial value for current_duty1