Skip to content
Anobium edited this page Oct 18, 2020 · 1 revision
PWMOn

Syntax:

    PWMOn

Command Availability:

Only available on Microchip PIC microcontrollers with Capture/Compare/PWM module CCP1.

This command does not operate on any other CCP channel.

Explanation:

Example 1:

This command will enable the output of the CCP1/PWM module on the Microchip PIC microcontroller.

    'This program will enable a 76 Khz PWM signal, with a duty cycle
    'of 80%. It will emit the signal for 10 seconds, then stop.
    #define PWM_Freq 76    'Set frequency in KHz
    #define PWM_Duty 80    'Set duty cycle to 80 %
    PWMOn                  'Turn on the PWM
    WAIT 10 s              'Wait 10 seconds
    PWMOff                 'Turn off the PWM

Example 2:

This command will enable the output of the CCP1/PWM module on the Microchip PIC microcontroller.

Note the chip frequency.

    'This program will enable a 62Hz PWM signal, with a duty cycle
    'of 50%.


    #Chip 12F1840, 1

    dir porta.2 out
    #define PWM_Freq .0625    'Set frequency in Hz equates to 62Hz
    #define PWM_Duty 50       'Set duty cycle to 80 %
    PWMON

    Do
    loop

Example 3:

This command will enable the output of the CCP1/PWM module on the Microchip PIC microcontroller.

Note the chip frequency.

    'This program will enable a 7.7Hz PWM signal, with a duty cycle
    'of 50%.


    #Chip 12F1840, 0.125

    dir porta.2 out
    #define PWM_Freq .0077   'Set frequency in Hz equates to 7.7Hz
    #define PWM_Duty 50       'Set duty cycle to 50 %
    PWMON

    Do
    loop

For more help, also see PWMOff

Clone this wiki locally