User manual

458
mikoC PRO for dsPIC
MikroElektronika
PWM_Start
PWM_Stop
Prototype
void PWM_Start(char enable_channel_x);
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 congured. 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
void PWM_Stop(char disable_channel_x);
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
unsigned int current_duty, old_duty, current_duty1, old_duty1;
unsigned int pwm_period1, pwm_period2;
void InitMain() {
ADPCFG = 0xFFFF; // Congure AN pins as digital I/O
TRISB = 0xFFFF; // congure PORTB pins as input
PORTD = 0; // set PORTD to 0
TRISD = 0; // designate PORTD pins as output
}
void main() {
InitMain();
current_duty = 16; // initial value for current_duty
current_duty1 = 16; // initial value for current_duty1