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.
hrtim_adc_trigger_t getAdcTrigger (hrtim_tu_number_t pwmX, hrtim_adc_trigger_t adc_trig)
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. For example if decimation = 1, nothing changes but with decimation = 2 you have twice less adc trigger.
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, hrtim_adc_trigger_t adc_trig)
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 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 fonction 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 or 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 or 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 or 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 or 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 or 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 or PWMF

Returns:

Rollover mode - EdgeTrigger_up, EdgeTrigger_down, EdgeTrigger_Both


function getAdcTrigger

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

hrtim_adc_trigger_t PwmHAL::getAdcTrigger (
    hrtim_tu_number_t pwmX,
    hrtim_adc_trigger_t adc_trig
) 

Parameters:

  • pwmX PWM Unit - PWMA, PWMB, PWMC, PWMD, PWME or PWMF

Returns:

adc trigger - ADCTRIG_1, ADCTRIG_2, ADCTRIG_3 et ADCTRIG_4


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 or PWMF

Returns:

external event trigger - EEV1,EEV2, EEV3, 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 or 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 or 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 or PWMF

Returns:

PWM mode - VOLTAGE_MODE or CURRENT_MODE

Warning:

this function must be called before initialiazing 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 or PWMF

Returns:

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 or 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 or 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 or 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 or 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 or 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 or 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: 184 ps - Min PWM f: 83.0 kHz PRSCL = 1 : fHRTIM x 16 = 2.304 GHz - Res: 368 ps - Min PWM f: 41.5 kHz PRSCL = 2 : fHRTIM x 8 = 1.152 GHz - Res: 735 ps - Min PWM f: 20.8 kHz PRSCL = 3 : fHRTIM x 4 = 576 MHz - Res: 1470 ps - Min PWM f: 10.4 kHz PRSCL = 4 : fHRTIM x 2 = 288 MHz - Res: 2940 ps - Min PWM f: 5.2 kHz PRSCL = 5 : fHRTIM X 1 = 144 MHz - Res: 5880 ps - Min PWM f: 2.6 kHz PRSCL = 6 : fHRTIM / 2 = 72 MHz - Res:11760 ps - Min PWM f: 1.3 kHz PRSCL = 7 : fHRTIM / 4 = 36 MHz - Res:23530 ps - Min PWM f: 0.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 or PWMF

Returns:

PWMx1 (high side convention) or PWMx2 (low-side convention)


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 initialiazing 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 or PWMF

Date:

2023

Author:

Luiz Villa [email protected]

Author:

Clément Foucher [email protected]

Author:

Ayoub Farah Hassan [email protected]


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 initialiazing 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. For example if decimation = 1, nothing changes but with decimation = 2 you have twice less adc trigger.

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

Parameters:

  • pwmX PWM Unit - PWMA, PWMB, PWMC, PWMD, PWME or 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 or 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,
    hrtim_adc_trigger_t adc_trig
) 

Parameters:

  • pwmX PWM Unit - PWMA, PWMB, PWMC, PWMD, PWME or PWMF
  • adc_trig adc trigger - ADCTRIG_1, ADCTRIG_2, ADCTRIG_3 et ADCTRIG_4

Warning:

Call this function BEFORE enabling the adc trigger and AFTER initializing the selected timer


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 or PWMF
  • trig_val a 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 or 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 or 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 or PWMF
  • value duty cycle value

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 or PWMF
  • eev external event trigger - EEV1,EEV2, EEV3, EEV3, EEV4, EEV5, EEV6, EEV7, EEV8, EEV9

Warning:

this function must be called before initialiazing 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 or PWMF
  • mode PWM mode - VOLTAGE_MODE or CURRENT_MODE

Warning:

this function must be called BEFORE initialiazing 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 or 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 or 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 or PWMF
  • shift phase shift value ° 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 or PWMF
  • convention PWM Switch to be driven by the duty cycle. The other will be complementary - PWMx1 or PWMx2

Warning:

this function must be called before the timer initialization


function startBurstMode

This function starts burst mode.

void PwmHAL::startBurstMode () 


function startDualOutput

This fonction 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 or 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:

  • tu 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 or 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:

  • tu 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