Sie sind auf Seite 1von 1

PICBASIC PRO(TM) Compiler

Copyright 2015 microEngineering Labs, Inc.

Notes on special HPWM command function.

This file only applies to those devices which reference it in a message during
compilation.

A new DEFINE, HPWM_OSC, has been added to accommodate a PWM clock that is
different than the system clock. The value of HPWM_OSC is in Hertz or cycles
per second. If this define is omitted, PBP will presume that the PWM clock is
the same as the system clock. The defined clock frequency is used for HPWM
commands on all available channels. It is not possible to define different
values on individual channels.

Example:

DEFINE OSC 4 ' system clock at 4MHz


DEFINE HPWM_OSC 16000000 ' PWM clock at 16MHz

The HPWM command will read the prescaler value from the PWMxCLKCON register in
order to generate the requested frequency. For this to work correctly, the
PWMxCLKCON register must be set before the HPWM command is executed. The same
PWMxCLKCON value should be used for all available HPWM channels. Changing
PWMxCLKCON may change the frequency of any previously requested active outputs.

The HPWM command will overwrite the following register pairs:

PWMxPH (Phase-match, always set to zero)


PWMxPR (Period)
PWMxDC (Duty cycle)

The HPWM duty cycle is limited to an 8-bit value. To make use of the 16-bit
resolution offered by the device, you may write to the PWMxDC register pair
directly, after the HPWM command is executed.

You may also write to the PWMxPH register pair to change the phase of a channel
in relation to other channels. Be aware that any phase delay time is subtracted
from the total duty-cycle on time. To maintain the frequency set by the HPWM
command, add the phase-match value to the PWMxDC register pair value and
overwrite PWMxDC.

Das könnte Ihnen auch gefallen