Skip to content

hpwmupdate_for_pwm_module_s

Anobium edited this page Oct 18, 2020 · 1 revision
HPWMUpdate for PWM Module(s)

Syntax:

    HPWMUpdate ( channel, duty_cycle )

Command Availability:

Available on Microchip PIC microcontrollers with the PWM module.

Explanation:

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.
  • You MUST have previously called the HPWM 10 Bit command with the same type of variable, or, use casting to ensure the variable tpye is the same type.

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 1, 2, 3, 4, 5, 6, 7 or 8. These corresponds to the HPWM1 through to HPWM8 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.

Example for Hardware PWM:

    '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.
    'Uses casting [word] to ensure the intialisation value of Zero (0) is a treated as a word.  The variable type MUST match the HPWMUpdate variable type.
    HPWM 6, 40, [word]0, 2
    'Main code
    do
        'Turn up brightness over 2.5 seconds
        For Bright = 0 to 1023
            HPWMUpdate 6, Bright
            wait 10 ms
        next
        'Turn down brightness over 2.5 seconds
        For Bright = 1023 to 0
            HPWMUpdate 6, Bright
            wait 10 ms
        next
    loop

For more help, see PWMOff, HPWM 10 Bit

Clone this wiki locally