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 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.
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.
uint32_t getPeriodUs (hrtim_tu_number_t pwmX)
This function returns the period in µs of the selected timer.
hrtim_switch_convention_t getSwitchConvention (hrtim_tu_number_t pwmX)
This function returns the switching convention of the selected timing unit.
void initFrequency (uint32_t init_frequency)
This function initialize the frequency.
void initFrequency (uint32_t init_frequency, uint32_t minimal_frequency)
This functions initialize the frequency and also sets the minimal reachable frequency.
void initUnit (hrtim_tu_number_t pwmX)
This function initializes a timing unit.
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 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 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 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 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 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 uint16


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 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 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 initFrequency [1/2]

This function initialize the frequency.

void PwmHAL::initFrequency (
    uint32_t init_frequency
) 

Parameters:

  • init_frequency frequency in Hz

Warning:

this function must be called BEFORE initialiazing any timing unit. the frequency initialized becomes the MINIMUM possible. use it BEFORE initialization of the timing unit.


function initFrequency [2/2]

This functions initialize the frequency and also sets the minimal reachable frequency.

void PwmHAL::initFrequency (
    uint32_t init_frequency,
    uint32_t minimal_frequency
) 

Parameters:

  • init_frequency frequency in Hz
  • minimal_frequency desired minimal frequency in Hz

Warning:

this function must be called BEFORE initialiazing any timing unit


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