Skip to content

Class PwmHAL

ClassList > PwmHAL

Handles all pwm signals for the spin board. More...

  • #include <PwmHAL.h>

Public Functions

Type Name
void configurePeriodEvnt (hrtim_tu_t PWM_tu, uint32_t repetition, hrtim_callback_t callback)
This function configures the interrupt on repetition counter.
void deInitBurstMode ()
This function deinit burst mode.
void disableAdcTrigger (hrtim_tu_number_t tu_number)
This function disables the adc trigger for the selected timing unit.
void disablePeriodEvnt (hrtim_tu_t PWM_tu)
This function disables the interrupt on repetition counter.
void enableAdcTrigger (hrtim_tu_number_t tu_number)
This function enables the adc trigger for the selected timing unit.
void enablePeriodEvnt (hrtim_tu_t PWM_tu)
This function enables the interrupt on repetition counter.
hrtim_adc_edgetrigger_t getAdcEdgeTrigger (hrtim_tu_number_t pwmX)
This function returns the adc trigger rollover mode for the selected timer.
adc_t getAdcTrigger (hrtim_tu_number_t pwmX)
This function returns the adc trigger linked to a timer unit.
hrtim_external_trigger_t getEev (hrtim_tu_number_t pwmX)
This function sets the external event linked to the timing unit used for the current mode.
uint32_t getFrequencyMax (hrtim_tu_number_t pwmX)
This function returns the maximum frequency of the selected timer in Hz.
uint32_t getFrequencyMin (hrtim_tu_number_t pwmX)
This function returns the minimum frequency of the selected timer in Hz.
hrtim_pwm_mode_t getMode (hrtim_tu_number_t pwmX)
This function returns the PWM mode (voltage or current mode)
hrtim_cnt_t getModulation (hrtim_tu_number_t pwmX)
This function returns the modulation type of the selected timing unit.
uint16_t getPeriod (hrtim_tu_number_t pwmX)
This function returns the period of the selected timing unit.
uint32_t getPeriodEvntRep (hrtim_tu_t PWM_tu)
This function returns the repetition counter value.
uint16_t getPeriodMax (hrtim_tu_number_t pwmX)
This function returns the maximum period of the selected timing unit.
uint16_t getPeriodMin (hrtim_tu_number_t pwmX)
This function returns the period of the selected timing unit.
uint32_t getPeriodUs (hrtim_tu_number_t pwmX)
This function returns the period in µs of the selected timer.
uint32_t getResolutionPs (hrtim_tu_number_t pwmX)
This function returns the resolution of the timing unit in picoseconds.
hrtim_switch_convention_t getSwitchConvention (hrtim_tu_number_t pwmX)
This function returns the switching convention of the selected timing unit.
void initBurstMode ()
This function initialize burst mode.
void initFixedFrequency (uint32_t fixed_frequency)
This function initialize the PWM for fixed frequency applications.
void initUnit (hrtim_tu_number_t pwmX)
This function initializes a timing unit.
void initVariableFrequency (uint32_t initial_frequency, uint32_t minimal_frequency)
This functions initializes the PWM for variable frequency applications.
void setAdcDecimation (hrtim_tu_number_t pwmX, uint32_t decimation)
This function sets the number of event which will be ignored between two events.ie. you divide the number of trigger in a fixed period.
void setAdcEdgeTrigger (hrtim_tu_number_t pwmX, hrtim_adc_edgetrigger_t adc_edge_trigger)
This function sets the adc trig rollover mode for the selected timer.
void setAdcTrigger (hrtim_tu_number_t pwmX, adc_t adc)
This function sets the adc trigger linked to a timer unit.
void setAdcTriggerInstant (hrtim_tu_number_t pwmX, float32_t trig_val)
This function sets the comparator value at which the ADC is trigered.
void setAdcTriggerPostScaler (hrtim_tu_number_t pwmX, uint32_t ps_ratio)
This function sets the PostScaler value for the selected timing unit.
void setBurstMode (int bm_cmp, int bm_per)
This function sets burst mode parameters.
void setDeadTime (hrtim_tu_number_t pwmX, uint16_t rise_ns, uint16_t fall_ns)
This function sets the dead time for the selected timing unit.
void setDutyCycle (hrtim_tu_number_t pwmX, float32_t duty_cycle)
This function sets the duty cycle for the selected timing unit.
void setDutyCycleRaw (hrtim_tu_number_t pwmX, uint16_t duty_cycle)
Sets the duty cycle for the selected timing unit using an unsigned integer.
void setEev (hrtim_tu_number_t pwmX, hrtim_external_trigger_t eev)
This function sets external event linked to the timing unit essential for the current mode.
void setFrequency (uint32_t frequency_update)
Change the frequency/period after it has been initialized.
void setMode (hrtim_tu_number_t pwmX, hrtim_pwm_mode_t mode)
This function sets a special pwm mode for voltage or current mode.
void setModulation (hrtim_tu_number_t pwmX, hrtim_cnt_t modulation)
This function sets the modulation mode for a given PWM unit.
void setPeriodEvntRep (hrtim_tu_t PWM_tu, uint32_t repetition)
This function sets the repetition counter to ISR period.
void setPhaseShift (hrtim_tu_number_t pwmX, int16_t shift)
This function sets the phase shift in respect to timer A for the selected timing unit.
void setSwitchConvention (hrtim_tu_number_t pwmX, hrtim_switch_convention_t convention)
This function sets the switch convention for a given PWM unit i.e. you decide which one of the output of the timer can be controlled with duty cycle.
void startBurstMode ()
This function starts burst mode.
void startDualOutput (hrtim_tu_number_t pwmX)
This function starts both outputs of the selected HRTIM channel.
void startSingleOutput (hrtim_tu_number_t tu, hrtim_output_number_t output)
This function starts only one output of the selected HRTIM channel.
void stopBurstMode ()
This function stops burst mode.
void stopDualOutput (hrtim_tu_number_t pwmX)
This function stops both outputs of the selected HRTIM channel.
void stopSingleOutput (hrtim_tu_number_t tu, hrtim_output_number_t output)
This function starts only one output of the selected HRTIM channel.

Detailed Description

Note:

Use this element to call functions related to the pwm.

Public Functions Documentation

function configurePeriodEvnt

This function configures the interrupt on repetition counter.

void PwmHAL::configurePeriodEvnt (
    hrtim_tu_t PWM_tu,
    uint32_t repetition,
    hrtim_callback_t callback
) 

Parameters:

  • PWM_tu PWM Unit:TIMA,TIMB,TIMC,TIMD,TIME,TIMF
  • repetition Number of repetition before the interruption on repetition counter event
  • callback Function to call each interupt

function deInitBurstMode

This function deinit burst mode.

void PwmHAL::deInitBurstMode () 


function disableAdcTrigger

This function disables the adc trigger for the selected timing unit.

void PwmHAL::disableAdcTrigger (
    hrtim_tu_number_t tu_number
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

function disablePeriodEvnt

This function disables the interrupt on repetition counter.

void PwmHAL::disablePeriodEvnt (
    hrtim_tu_t PWM_tu
) 

Parameters:

  • PWM_tu PWM Unit:TIMA,TIMB,TIMC,TIMD,TIME,TIMF

function enableAdcTrigger

This function enables the adc trigger for the selected timing unit.

void PwmHAL::enableAdcTrigger (
    hrtim_tu_number_t tu_number
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

Warning:

Call this function only AFTER setting the adc trigger and initializing the chosen timer


function enablePeriodEvnt

This function enables the interrupt on repetition counter.

void PwmHAL::enablePeriodEvnt (
    hrtim_tu_t PWM_tu
) 

Parameters:

  • PWM_tu PWM Unit:TIMA,TIMB,TIMC,TIMD,TIME,TIMF

function getAdcEdgeTrigger

This function returns the adc trigger rollover mode for the selected timer.

hrtim_adc_edgetrigger_t PwmHAL::getAdcEdgeTrigger (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

Returns:

Rollover mode: EdgeTrigger_up, EdgeTrigger_down, EdgeTrigger_Both


function getAdcTrigger

This function returns the adc trigger linked to a timer unit.

adc_t PwmHAL::getAdcTrigger (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

Returns:

ADC number: ADC_1,ADC_2,ADC_3,ADC_4,ADC_5 or

UNKNOWN_ADC if the ADC trigger was not configured for this timing unit.


function getEev

This function sets the external event linked to the timing unit used for the current mode.

hrtim_external_trigger_t PwmHAL::getEev (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • eev external event trigger: EEV1,EEV2,EEV3,EEV4,EEV5,EEV6,EEV7,EEV8,EEV9

function getFrequencyMax

This function returns the maximum frequency of the selected timer in Hz.

uint32_t PwmHAL::getFrequencyMax (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

function getFrequencyMin

This function returns the minimum frequency of the selected timer in Hz.

uint32_t PwmHAL::getFrequencyMin (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

function getMode

This function returns the PWM mode (voltage or current mode)

hrtim_pwm_mode_t PwmHAL::getMode (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

Returns:

PWM mode: VOLTAGE_MODE or CURRENT_MODE

Warning:

This function must be called before initializing a timing unit


function getModulation

This function returns the modulation type of the selected timing unit.

hrtim_cnt_t PwmHAL::getModulation (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

Returns:

The type of modulation Lft_aligned or UpDwn (center aligned)


function getPeriod

This function returns the period of the selected timing unit.

uint16_t PwmHAL::getPeriod (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

Returns:

the period value in number of clock cycles


function getPeriodEvntRep

This function returns the repetition counter value.

uint32_t PwmHAL::getPeriodEvntRep (
    hrtim_tu_t PWM_tu
) 

Parameters:

  • PWM_tu PWM Unit:TIMA,TIMB,TIMC,TIMD,TIME,TIMF

Returns:

repetition counter value


function getPeriodMax

This function returns the maximum period of the selected timing unit.

uint16_t PwmHAL::getPeriodMax (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

Returns:

the period value in number of clock cycles


function getPeriodMin

This function returns the period of the selected timing unit.

uint16_t PwmHAL::getPeriodMin (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

Returns:

the period value in number of clock cycles


function getPeriodUs

This function returns the period in µs of the selected timer.

uint32_t PwmHAL::getPeriodUs (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

function getResolutionPs

This function returns the resolution of the timing unit in picoseconds.

uint32_t PwmHAL::getResolutionPs (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

Note:

The resolution of the PWM depends on the prescaler that is automatically calculated when the master unit is initialized.

For an HRTIM frequency of =170MHz:

  • PRSCL = 0: fHRTIM x 32 = 4.608 GHz - Res:00184 ps - Min PWM f: 83.00 kHz
  • PRSCL = 1: fHRTIM x 16 = 2.304 GHz - Res:00368 ps - Min PWM f: 41.50 kHz
  • PRSCL = 2: fHRTIM x 08 = 1.152 GHz - Res:00735 ps - Min PWM f: 20.80 kHz
  • PRSCL = 3: fHRTIM x 04 = 0.576 GHz - Res:01470 ps - Min PWM f: 10.40 kHz
  • PRSCL = 4: fHRTIM x 02 = 0.288 GHz - Res:02940 ps - Min PWM f: 05.20 kHz
  • PRSCL = 5: fHRTIM x 01 = 0.144 GHz - Res:05880 ps - Min PWM f: 02.60 kHz
  • PRSCL = 6: fHRTIM / 02 = 0.072 GHz - Res:11760 ps - Min PWM f: 01.30 kHz
  • PRSCL = 7: fHRTIM / 04 = 0.036 GHz - Res:23530 ps - Min PWM f: 00.65 kHz

function getSwitchConvention

This function returns the switching convention of the selected timing unit.

hrtim_switch_convention_t PwmHAL::getSwitchConvention (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

Returns:

Returns the switch convention :

  • PWMx1: BUCK convention, switch HIGH
  • PWMx2: BOOST convention, switch LOW

function initBurstMode

This function initialize burst mode.

void PwmHAL::initBurstMode () 


function initFixedFrequency

This function initialize the PWM for fixed frequency applications.

void PwmHAL::initFixedFrequency (
    uint32_t fixed_frequency
) 

Parameters:

  • fixed_frequency frequency to be fixed in Hz

Warning:

This function must be called BEFORE initializing any timing unit.

The frequency will not vary during the operation of the power device.

Use it for fixed frequencies only.


function initUnit

This function initializes a timing unit.

void PwmHAL::initUnit (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

function initVariableFrequency

This functions initializes the PWM for variable frequency applications.

void PwmHAL::initVariableFrequency (
    uint32_t initial_frequency,
    uint32_t minimal_frequency
) 

Parameters:

  • initial_frequency The initial value of the frequency in Hz
  • minimal_frequency The minimal value of the frequency in Hz

Warning:

This function must be called BEFORE initializing any timing unit.

The user can vary the frequency during the operation of the power device.

This may compromise the resolution of the PWM.

You can check your resolution with the getResolutionPS function.


function setAdcDecimation

This function sets the number of event which will be ignored between two events.ie. you divide the number of trigger in a fixed period.

void PwmHAL::setAdcDecimation (
    hrtim_tu_number_t pwmX,
    uint32_t decimation
) 

For example if :

  • decimation = 1, nothing changes but with
  • decimation = 2, you have twice less adc trigger

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • decimation decimation/post-scaler: a number between 1 and 32

Warning:

this function must be called AFTER initialiazing the selected timing unit


function setAdcEdgeTrigger

This function sets the adc trig rollover mode for the selected timer.

void PwmHAL::setAdcEdgeTrigger (
    hrtim_tu_number_t pwmX,
    hrtim_adc_edgetrigger_t adc_edge_trigger
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • adc_edge_trigger Rollover mode: EdgeTrigger_up, EdgeTrigger_down, EdgeTrigger_Both

Warning:

This function must be called BEFORE initialiazing the selected timing unit


function setAdcTrigger

This function sets the adc trigger linked to a timer unit.

void PwmHAL::setAdcTrigger (
    hrtim_tu_number_t pwmX,
    adc_t adc
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • adc ADC number: ADC_1,ADC_2,ADC_3,ADC_4,ADC_5

Warning:

Call this function:


function setAdcTriggerInstant

This function sets the comparator value at which the ADC is trigered.

void PwmHAL::setAdcTriggerInstant (
    hrtim_tu_number_t pwmX,
    float32_t trig_val
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • trig_val a float value between 0 and 1

function setAdcTriggerPostScaler

This function sets the PostScaler value for the selected timing unit.

void PwmHAL::setAdcTriggerPostScaler (
    hrtim_tu_number_t pwmX,
    uint32_t ps_ratio
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • ps_ratio post scaler ratio

Warning:

This function must be called after initialiazing a timing unit, and before enabling the adc trigger


function setBurstMode

This function sets burst mode parameters.

void PwmHAL::setBurstMode (
    int bm_cmp,
    int bm_per
) 

Parameters:

  • bm_cmp Number of period of PWM off
  • bm_per Total number of PWM period

function setDeadTime

This function sets the dead time for the selected timing unit.

void PwmHAL::setDeadTime (
    hrtim_tu_number_t pwmX,
    uint16_t rise_ns,
    uint16_t fall_ns
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • rise_ns rising edge dead time in ns
  • falling_ns falling edge dead time in ns

Warning:

use this function BEFORE initializing the chosen timer


function setDutyCycle

This function sets the duty cycle for the selected timing unit.

void PwmHAL::setDutyCycle (
    hrtim_tu_number_t pwmX,
    float32_t duty_cycle
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • value duty cycle value

function setDutyCycleRaw

Sets the duty cycle for the selected timing unit using an unsigned integer.

void PwmHAL::setDutyCycleRaw (
    hrtim_tu_number_t pwmX,
    uint16_t duty_cycle
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • value duty cycle value as an unsigned integer

function setEev

This function sets external event linked to the timing unit essential for the current mode.

void PwmHAL::setEev (
    hrtim_tu_number_t pwmX,
    hrtim_external_trigger_t eev
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • eev external event trigger: EEV1,EEV2,EEV3,EEV4,EEV5,EEV6,EEV7,EEV8,EEV9

Warning:

this function must be called before initializing a timing unit


function setFrequency

Change the frequency/period after it has been initialized.

void PwmHAL::setFrequency (
    uint32_t frequency_update
) 

Parameters:

  • frequency_update The new frequency in Hz

Warning:

The new frequency can't be inferior to the the one set in the initialization step.

Use it AFTER the initialization of the timing unit.


function setMode

This function sets a special pwm mode for voltage or current mode.

void PwmHAL::setMode (
    hrtim_tu_number_t pwmX,
    hrtim_pwm_mode_t mode
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • mode PWM mode: VOLTAGE_MODE or CURRENT_MODE

Warning:

This function must be called BEFORE initializing the selected timing unit


function setModulation

This function sets the modulation mode for a given PWM unit.

void PwmHAL::setModulation (
    hrtim_tu_number_t pwmX,
    hrtim_cnt_t modulation
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • modulation PWM Modulation: Lft_aligned or UpDwn

Warning:

this function must be called BEFORE initializing the selected timer


function setPeriodEvntRep

This function sets the repetition counter to ISR period.

void PwmHAL::setPeriodEvntRep (
    hrtim_tu_t PWM_tu,
    uint32_t repetition
) 

Parameters:

  • PWM_tu PWM Unit:TIMA,TIMB,TIMC,TIMD,TIME,TIMF
  • repetition Number of repetition before the interruption on repetition counter event

function setPhaseShift

This function sets the phase shift in respect to timer A for the selected timing unit.

void PwmHAL::setPhaseShift (
    hrtim_tu_number_t pwmX,
    int16_t shift
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • shift phase shift value in DEGREES (between -360 and 360)

Warning:

Use this function AFTER setting the frequency and initializing the chosen timer


function setSwitchConvention

This function sets the switch convention for a given PWM unit i.e. you decide which one of the output of the timer can be controlled with duty cycle.

void PwmHAL::setSwitchConvention (
    hrtim_tu_number_t pwmX,
    hrtim_switch_convention_t convention
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • convention PWM Switch to be driven by the duty cycle:

  • PWMx1: BUCK convention, switch HIGH

  • PWMx2: BOOST convention, switch LOW

Warning:

this function must be called before the timer initialization


function startBurstMode

This function starts burst mode.

void PwmHAL::startBurstMode () 


function startDualOutput

This function starts both outputs of the selected HRTIM channel.

void PwmHAL::startDualOutput (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

function startSingleOutput

This function starts only one output of the selected HRTIM channel.

void PwmHAL::startSingleOutput (
    hrtim_tu_number_t tu,
    hrtim_output_number_t output
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • output output to disable: TIMING_OUTPUT1,TIMING_OUTPUT2

function stopBurstMode

This function stops burst mode.

void PwmHAL::stopBurstMode () 


function stopDualOutput

This function stops both outputs of the selected HRTIM channel.

void PwmHAL::stopDualOutput (
    hrtim_tu_number_t pwmX
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF

function stopSingleOutput

This function starts only one output of the selected HRTIM channel.

void PwmHAL::stopSingleOutput (
    hrtim_tu_number_t tu,
    hrtim_output_number_t output
) 

Parameters:

  • pwmX PWM Unit: PWMA,PWMB,PWMC,PWMD,PWME,PWMF
  • output output to disable: TIMING_OUTPUT1,TIMING_OUTPUT2


The documentation for this class was generated from the following file docs/core/zephyr/modules/owntech_spin_api/zephyr/src/PwmHAL.h