HPWMUpdate ( channel, duty_cycle )

Command Availability:

Only available on Microchip PIC microcontrollers with the PWM module.

For the Capture/Compare/PWM (CCP) module, see here HPWM CCP


This command updates the duty cycle only. You MUST have previously called the HPWM 10 Bit command using the full command (see HPWM 10 Bit) to set the channel specific settings for frequency and timer source.  See the example below for the usage.

This command only supports the previously called HPWM 10 Bit command, or, if you have set more than one HPWM 10 Bit PWM channel then to use the command you must have set the channel to the same frequency.

The command only supports the hardware PWM module of the Microchip PIC microcontroller to generate a PWM waveform at the previously defined frequency and timer source.

channel is 3, 4, 5, 6 or 7. These corresponds to the HPWM3, HPWM4, HPWM5, HPWM6 or HPWM7 respectively.  The channel MUST be supported by the microcontroller.   Check the microcontroller specific datasheet for the available channel.

duty cycle specifies the desired duty cycle of the PWM signal, and ranges from 0 to 1023 where 1023 is 100% duty cycle.


    'This program will alter the brightness of an LED using
    'hardware PWM.

    'Select chip model and speed
    #chip 16F18855, 32

    'Generated by PIC PPS Tool for Great Cow Basic
    'Template comment at the start of the config file
    #startup InitPPS, 85

    Sub InitPPS

            'Module: PWM6
            RA2PPS = 0x000E    'PWM6OUT > RA2

    End Sub
    'Template comment at the end of the config file

    'Set the PWM pin to output mode
    DIR PORTA.2 out

    'Setup PWM - this is mandated as this specifies the frequency and the clock source.
    HPWM 6, 40, 0, 2
    'Main code
        'Turn up brightness over 2.5 seconds
        For Bright = 0 to 1023
            HPWMUpdate 6, Bright
            wait 10 ms
        'Turn down brightness over 2.5 seconds
        For Bright = 1023 to 0
            HPWMUpdate 6, Bright
            wait 10 ms

For more help, see PWMOff, HPWM 10 Bit