Mikroelektronika MIKROE-724 Scheda Tecnica

Pagina di 726
434
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
PWM_Start
PWM_Stop
Prototype
sub procedure PWM_Start(dim enable_channel_x as 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 configured. 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
sub procedure PWM_Stop(dim disable_channel_x as 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
dim current_duty, old_duty, current_duty1, old_duty1 as word
    pwm_period1, pwm_period2 as word
sub procedure InitMain()
  ADPCFG = 0xFFFF                            ‘ initialize AN pins as digital
  TRISB = 0xFFFF                             ‘ configure PORTB pins as input
  PORTD = 0                                  ‘ set PORTD to 0
  TRISD = 0                                  ‘ designate PORTD pins as output
end sub
main:
  InitMain()
  current_duty  = 16                         ‘ initial value for current_duty
  current_duty1 = 16                         ‘ initial value for current_duty1