eFlexPwm
Arduino eFlexPwm library for Teensy 4.x
eFlex::Timer

PWM Module. More...

#include <eFlexPwmTimer.h>

Collaboration diagram for eFlex::Timer:

Public Member Functions

bool beginSubModules (uint8_t subModulesToBegin, bool doStart=true, bool doSync=true)
 Sets up the PWM signals for the sub-modules passed as parameters. More...
 
bool begin (bool doStart=true, bool doSync=true)
 Sets up the PWM signals for all instantiated submodules of the timer. More...
 
uint8_t index () const
 Returns the timer module index (0 for PWM1...)
 
void enable (bool value=true)
 Enable or disable all instantiated submodules of the timer. More...
 
void disable ()
 Disable all instantiated submodules of the timer. More...
 
bool isEnabled () const
 Returns true if the timer is enabled.
 
void start (uint8_t subModulesToStart, bool startit=true)
 Starts or stops the PWM counter for a single or multiple submodules. More...
 
void start (bool startit=true)
 Starts or stops the PWM counter for all instantiated submodules for this timer. More...
 
void stop (uint8_t subModulesToStop)
 Stops the PWM counter for a single or multiple submodules. More...
 
void stop ()
 Stops the PWM counter for all instantiated submodules for this timer.
 
void setupDutyCyclePercent (uint8_t dutyCyclePercent)
 Setting the duty cycle for all submodules before calling begin. More...
 
void setupLevel (pwm_level_select_t level)
 Setting the output pulse mode for all submodules before calling begin. More...
 
void setupDeadtime (uint16_t deadtimeValue, uint32_t unit=1)
 Setting the deadtime for all submodules before calling begin. More...
 
void setupOutputEnable (bool activate=true)
 Setting output enable for all submodules before calling begin. More...
 
void setupFaultState (pwm_fault_state_t faultState)
 Setting the output fault status for all submodules before calling begin. More...
 
bool updateSetting (bool doSync=true)
 Update PWM signals for all submodules. More...
 
uint32_t srcClockHz () const
 PWM main counter clock in Hz.
 
void printRegs (Stream &out=Serial) const
 Print PWM module registers to the output stream. More...
 
void printAllRegs (Stream &out=Serial) const
 Print registers of PWM module and its submodules to the output stream. More...
 
void setPwmLdok (bool value=true)
 Sets or clears the PWM LDOK bit on all instantiated submodules for this timer. More...
 
void setPwmLdok (uint8_t subModulesToUpdate, bool value)
 Sets or clears the PWM LDOK bit on a single or multiple submodules. More...
 
void setupFaultInputFilter (const pwm_fault_input_filter_param_t *faultInputFilterParams)
 Sets up the PWM fault input filter. More...
 
void setupFaults (pwm_fault_input_t faultNum, const pwm_fault_param_t *faultParams)
 Sets up the PWM fault protection. More...
 

Static Public Member Functions

static uint32_t busClockHz ()
 Bus clock in Hz.
 
static uint32_t prescalerToMinPwmFrequency (unsigned prescaler)
 Calculates the minimum PWM frequency corresponding to a prescaler. More...
 
static uint32_t prescalerToMinPwmFrequency (pwm_clock_prescale_t prescaler)
 

Detailed Description

PWM Module.

This class cannot be instantiated directly and can only be used by a call to SubModule::timer()

Definition at line 19 of file eFlexPwmTimer.h.

Member Function Documentation

◆ begin()

bool eFlex::Timer::begin ( bool  doStart = true,
bool  doSync = true 
)
inline

Sets up the PWM signals for all instantiated submodules of the timer.

The function initializes the submodule according to the parameters passed in by the user. The function also sets up the value compare registers to match the PWM signal requirements. If the dead time insertion logic is enabled, the pulse period is reduced by the dead time period specified by the user.

Parameters
doStartstarts signal generation
doSyncsynchronizes the operation by surrounding it with setPwmLdok (false) / setPwmLdok (true)
Returns
Returns false if there was error setting up the signal; true otherwise

Definition at line 52 of file eFlexPwmTimer.h.

References beginSubModules().

Here is the call graph for this function:

◆ beginSubModules()

bool eFlex::Timer::beginSubModules ( uint8_t  subModulesToBegin,
bool  doStart = true,
bool  doSync = true 
)

Sets up the PWM signals for the sub-modules passed as parameters.

The function initializes the submodule according to the parameters passed in by the user. The function also sets up the value compare registers to match the PWM signal requirements. If the dead time insertion logic is enabled, the pulse period is reduced by the dead time period specified by the user.

Parameters
subModulesToBeginPWM submodules to begin. This is a logical OR of members of the enumeration pwm_module_control_t
doStartstarts signal generation
doSyncsynchronizes the operation by surrounding it with setPwmLdok (false) / setPwmLdok (true)
Returns
Returns false if there was error setting up the signal; true otherwise

Referenced by begin().

◆ disable()

void eFlex::Timer::disable ( )
inline

Disable all instantiated submodules of the timer.

This function allows you to disable the output pins without changing anything in the configuration. When the submodule is disabled, its output pins are forced to zero.

Definition at line 81 of file eFlexPwmTimer.h.

References enable().

Here is the call graph for this function:

◆ enable()

void eFlex::Timer::enable ( bool  value = true)

Enable or disable all instantiated submodules of the timer.

This function allows you to enable/disable the output pins without changing anything in the configuration. When the timer is disabled, its output pins are forced to zero.

Parameters
valuetrue to enable, false otherwise

Referenced by disable().

◆ prescalerToMinPwmFrequency()

uint32_t eFlex::Timer::prescalerToMinPwmFrequency ( unsigned  prescaler)
inlinestatic

Calculates the minimum PWM frequency corresponding to a prescaler.

Parameters
prescaler1,2,4,8,16,32,64,128
Returns
minimum PWM frequency in Hz

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 288 of file eFlexPwmTimer.h.

References busClockHz().

Referenced by eFlex::SubModule::setPrescaler().

Here is the call graph for this function:

◆ printAllRegs()

void eFlex::Timer::printAllRegs ( Stream &  out = Serial) const

Print registers of PWM module and its submodules to the output stream.

Parameters
outthe output stream, Serial by default

◆ printRegs()

void eFlex::Timer::printRegs ( Stream &  out = Serial) const

Print PWM module registers to the output stream.

Note
submodule registers are not printed.
Parameters
outthe output stream, Serial by default

◆ setPwmLdok() [1/2]

void eFlex::Timer::setPwmLdok ( bool  value = true)
inline

Sets or clears the PWM LDOK bit on all instantiated submodules for this timer.

Note
This operation is not useful if begin() was called with doSync=true
Parameters
valuetrue: Set LDOK bit for the submodule list; false: Clear LDOK bit

Definition at line 237 of file eFlexPwmTimer.h.

Referenced by eFlex::SubModule::setPwmLdok().

◆ setPwmLdok() [2/2]

void eFlex::Timer::setPwmLdok ( uint8_t  subModulesToUpdate,
bool  value 
)
inline

Sets or clears the PWM LDOK bit on a single or multiple submodules.

Set LDOK bit to load buffered values into CTRL[PRSC] and the INIT, FRACVAL and VAL registers. The values are loaded immediately if kPWM_ReloadImmediate option was choosen during config. Else the values are loaded at the next PWM reload point. This function can issue the load command to multiple submodules at the same time.

Parameters
subModulesToUpdatePWM submodules to update with buffered values. This is a logical OR of members of the enumeration pwm_module_control_t
valuetrue: Set LDOK bit for the submodule list; false: Clear LDOK bit

Definition at line 257 of file eFlexPwmTimer.h.

◆ setupDeadtime()

void eFlex::Timer::setupDeadtime ( uint16_t  deadtimeValue,
uint32_t  unit = 1 
)

Setting the deadtime for all submodules before calling begin.

Note
If you want this value to take effect after the call to begin, you must call updateSetting
Parameters
deadtimeValueThe deadtime value in clock cycles; only used if channel pair is operating in complementary mode
unitThe unit of the deadtimeValue; 1: clock cycles; 1000: milliseconds; 1000000: microseconds; 1000000000: nanoseconds

◆ setupDutyCyclePercent()

void eFlex::Timer::setupDutyCyclePercent ( uint8_t  dutyCyclePercent)

Setting the duty cycle for all submodules before calling begin.

Note
If you want this value to take effect after the call to begin, you must call updateSetting
Parameters
dutyCyclePercentduty cycle in percent

◆ setupFaultInputFilter()

void eFlex::Timer::setupFaultInputFilter ( const pwm_fault_input_filter_param_t faultInputFilterParams)
inline

Sets up the PWM fault input filter.

Parameters
faultInputFilterParamsParameters passed in to set up the fault input filter.

Definition at line 266 of file eFlexPwmTimer.h.

◆ setupFaults()

void eFlex::Timer::setupFaults ( pwm_fault_input_t  faultNum,
const pwm_fault_param_t faultParams 
)
inline

Sets up the PWM fault protection.

PWM has 4 fault inputs.

Parameters
faultNumPWM fault to configure.
faultParamsPointer to the PWM fault config structure

Definition at line 278 of file eFlexPwmTimer.h.

◆ setupFaultState()

void eFlex::Timer::setupFaultState ( pwm_fault_state_t  faultState)

Setting the output fault status for all submodules before calling begin.

Note
If you want this value to take effect after the call to begin, you must call updateSetting
Parameters
faultStatethe output fault status

◆ setupLevel()

void eFlex::Timer::setupLevel ( pwm_level_select_t  level)

Setting the output pulse mode for all submodules before calling begin.

Note
If you want this value to take effect after the call to begin, you must call updateSetting
Parameters
leveloutput pulse mode

◆ setupOutputEnable()

void eFlex::Timer::setupOutputEnable ( bool  activate = true)

Setting output enable for all submodules before calling begin.

Note
If you want this value to take effect after the call to begin, you must call updateSetting
Parameters
activatetrue to enable the outputs

◆ start() [1/2]

void eFlex::Timer::start ( bool  startit = true)
inline

Starts or stops the PWM counter for all instantiated submodules for this timer.

Parameters
startittrue to start, false to stop
Note
This operation is not useful if begin() was called with doStart=true

Definition at line 117 of file eFlexPwmTimer.h.

References start().

Here is the call graph for this function:

◆ start() [2/2]

void eFlex::Timer::start ( uint8_t  subModulesToStart,
bool  startit = true 
)
inline

Starts or stops the PWM counter for a single or multiple submodules.

Sets the Run bit which enables the clocks to the PWM submodule. This function can start multiple submodules at the same time.

Parameters
subModulesToStartPWM submodules to start. This is a logical OR of members of the enumeration pwm_module_control_t
startittrue to start, false to stop

Definition at line 102 of file eFlexPwmTimer.h.

Referenced by start(), eFlex::SubModule::start(), and stop().

◆ stop()

void eFlex::Timer::stop ( uint8_t  subModulesToStop)
inline

Stops the PWM counter for a single or multiple submodules.

Clears the Run bit which resets the submodule's counter. This function can stop multiple submodules at the same time.

Parameters
subModulesToStopPWM submodules to stop. This is a logical OR of members of the enumeration pwm_module_control_t

Definition at line 130 of file eFlexPwmTimer.h.

References start().

Here is the call graph for this function:

◆ updateSetting()

bool eFlex::Timer::updateSetting ( bool  doSync = true)

Update PWM signals for all submodules.

The function initializes the submodule according to the parameters passed in by the user. The function also sets up the value compare registers to match the PWM signal requirements. If the dead time insertion logic is enabled, the pulse period is reduced by the dead time period specified by the user.

Parameters
doSynctrue: Set LDOK bit for the submodule; false: LDOK bit don't set, need to call setPwmLdok to sync update.
Returns
Returns false if there was error setting up the signal; true otherwise