Skip to content

PWM, or Pulse Width Modulation, is a method used in electronics to control the power supplied to devices like motors, LEDs, and heaters. Instead of changing the voltage or current level, PWM changes the amount of time the power is on (the pulse width) compared to the time it's off.

In power electronics, PWM is super important because it allows us to control the average power delivered to a load by varying the duty cycle of the pulse. This means we can regulate the speed of motors or the brightness of LEDs.

Features

HRTIM pin

  • Up to 5 pairs of PWMs possible (PWMA, PWC, PWMD, PWME, PWMF)
  • Each PWM unit has a resolution of 184ps.

Note

The resolution of a PWM signal defines the maximum number of steps that can be present in a single PWM period. In other words, it determines how finely you can adjust the pulse width of the signal. A higher resolution means you can make smaller and more precise adjustments to the pulse width.

  • Frequencies in the range of 650Hz to 1Ghz theorically possible

Warning

Only 200Khz was tested with SPIN and TWIST

  • Two different modulation mode possible : left aligned, and center aligned
  • Two ADC linkable to two differents PWM unit for precise measurement instant
  • Compatible for peak current control with the internal analog comparator
  • Positive and negative dead time set via software
  • Phase shift possible for interleaved operations

Include

Note

#include <SpinAPI.h>
Make sure that SPIN API is included to use PwmHAL

Initialization sequence

Note

Function to call before initializing the PWM unit.

1. Set the modulation type : spin.pwm.setModulation(PWMx, lft_aligned/upDwn)
2. Set wich output (1 or 2) will be controlled by the duty cycle, the other will be complementary spin.pwm.setSwitchConvention(PWMx, PWMx1/PWMx2)
3. Set if the pwm is designed to be duty-cycle driven (voltage mode) or current driven (current mode) spin.pwm.setMode(PWMx, voltageMode/currentMode)
4. Initialize the pwm unit : spin.pwm.initUnit(PWMx)

1. Set the modulation type : spin.pwm.setModulation(PWMx, lft_aligned/upDwn)
2. Set ow which edge (up/down) to trigger adc conversion spin.pwm.setAdcEdgeTrigger(PWMx, edgeTrigUp/edgeTrigDwn)
3. Set the division of the number of trigger in a fixed period spin.pwm.setAdcDecimation(PWMx, DecimValue)
4. Set wich output (1 or 2) will be constrolled by the duty cycle, the other will be complementary spin.pwm.setSwitchConvention(PWMx, PWMx1/PWMx2)
5. Set if the pwm is designed to be duty-cycle driven (voltage mode) or current driven (current mode) spin.pwm.setMode(PWMx, voltageMode/currentMode)
6. Initialize the pwm unit : spin.pwm.initUnit(PWMx)

Note

Function to call after initializing PWM unit.

  1. Set the rising/falling dead time. Can be changed before/after init : spin.pwm.setDeadTime(PWMx, rise, fall)
  2. Set an initial value for the duty cycle spin.pwm.setDutyCycle(0.5)
  3. Start the PWM, either start both outout or just one spin.pwm.startDualOutput(PWMx) / spin.pwm.startSingleOutput(PWMx, PWMx1/PWMx2)
  4. if ADC hardware triggered : follow ADC init sequence
  1. Set the rising/falling dead time. Can be changed before/after init : spin.pwm.setDeadTime(PWMx, rise, fall)
  2. Set wich ADC trigger to link to PWM unit spin.pwm.setAdcTrigger(PWMx, ADCtrig)
  3. Enable the adc trigger spin.pwm.enableAdcTrigger
  4. Set an initial value for the duty cycle spin.pwm.setDutyCycle(0.5)
  5. Start the PWM, either start both outout or just one spin.pwm.startDualOutput(PWMx) / spin.pwm.startSingleOutput(PWMx, PWMx1/PWMx2)
  6. if ADC hardware triggered : follow ADC init sequence

Example

spin.pwm.setModulation(PWMA, UpDwn);
spin.pwm.setSwitchConvention(PWMA, PWMx1);
spin.pwm.setMode(PWMA, VOLTAGE_MODE);
spin.pwm.initUnit(PWMA);
spin.pwm.setDeadTime(PWMA, 200,200);
spin.pwm.setDutyCycle(0.5);
spin.pwm.startDualOutput(PWMA);
spin.pwm.setModulation(PWMA, UpDwn);
spin.pwm.setAdcEdgeTrigger(PWMA, EdgeTrigger_up);
spin.pwm.setSwitchConvention(PWMA, PWMx1);
spin.pwm.setAdcDecimation(PWMA, 1);
spin.pwm.setMode(PWMA, VOLTAGE_MODE);
spin.pwm.initUnit(PWMA);
spin.pwm.setDeadTime(PWMA, 200,200);
spin.pwm.setAdcTrigger(PWMA, ADCTRIG_1);
spin.pwm.enableAdcTrigger(PWMA);
spin.pwm.setDutyCycle(0.5);
spin.pwm.startDualOutput(PWMA);

How it works

To generate a PWM you need two signals, a variable high frequency signals called the carrier and a constant signal called the duty cycle.

Carrier signal and PWM resolution

The carrier signal is usually a counter in the form of a sawtooth or triangle wave. The frequency of the PWM is given by the max value of that counter. It means that the minimal duty cycle step of phase step, is proportional to the frequency of the signal.

Example

Here is a counter incrementing from 0 to 27200. PWM carrier

The increment between each step is made at the PWM resolution which is here 184ps, so the carrier gets from 0 to 27200 in 5µs so a frequency of 200kHz.
In other words the smallest step is 1/27200 or 0.0037% of the period.

Duty cycle

The duty cycle is a constant value compared to the carrier.

Duty cycle

When the carrier is superior to the duty cycle, the logic output is at high level. On the contrary, when the carrier is inferior to the duty cycle the the output logic is low level. A PWM signal is thus a sqarewave signal with a frequency (the switching frequency) is fixed by the carrier.

Varying the duty cycle is how to vary the output of the PWM.

Snippet examples

Frequency

frequency 200 kHz

    spin.pwm.setFrequency(PWMA, 200000);

frequency 400 kHz

    spin.pwm.setFrequency(PWMA, 400000);

Single/Dual Output

single_output_pwm

    spin.pwm.startSingleOutput(PWMA, TIMING_OUTPUT1);    

single_output_pwm2

    spin.pwm.startSingleOutput(PWMA, TIMING_OUTPUT2);    

dual_output_pwm

    spin.pwm.startDualOutput(PWMA);

Duty Cycle

duty_cycle_20

    spin.pwm.setDutyCycle(PWMA, 0.2);

duty_cycle_80

    spin.pwm.setDutyCycle(PWMA, 0.8);

phase_shift_80

    spin.pwm.setDutyCycle(PWMA, 0.8);

Phase Shift

Tip

PWMA is defined as the phase reference. It can not be phase shifted. If you are not using PWMA, you can define any PWM channel as the reference by setting its phase shift to 0°
NB: Phase reference is 0°.

phase_shift_20

    spin.pwm.setPhaseShift(PWMC,  72);

phase_shift_80

    spin.pwm.setPhaseShift(PWMC,  288);

phase_shift_how_it_works

    spin.pwm.setPhaseShift(PWMA,  288);

Dead Time

dead_time_02

    spin.pwm.setDeadtime(PWMA,  100,  100);

dead_time_08

    spin.pwm.setDeadtime(PWMA,  400,  400);

dead_time_asymetric_0208

    spin.pwm.setDeadtime(PWMA,  100,  400);

dead_time_asymetric_0802

    spin.pwm.setDeadtime(PWMA,  400,  100);

Modulation Type

left_aligned_modulation_pwm

    spin.pwm.setModulation(PWMA, Lft_aligned);
    spin.pwm.setDutyCycle(PWMA, 0.28);

center_aligned_modulation_pwm

    spin.pwm.setModulation(PWMA, UpDwn);
    spin.pwm.setDutyCycle(PWMA, 0.28);

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