eFlexPwm
Arduino eFlexPwm library for Teensy 4.x
|
PWM Module. More...
#include <eFlexPwmTimer.h>
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) |
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.
|
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.
doStart | starts signal generation |
doSync | synchronizes the operation by surrounding it with setPwmLdok (false) / setPwmLdok (true) |
Definition at line 52 of file eFlexPwmTimer.h.
References 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.
subModulesToBegin | PWM submodules to begin. This is a logical OR of members of the enumeration pwm_module_control_t |
doStart | starts signal generation |
doSync | synchronizes the operation by surrounding it with setPwmLdok (false) / setPwmLdok (true) |
Referenced by begin().
|
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().
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.
value | true to enable, false otherwise |
Referenced by disable().
|
inlinestatic |
Calculates the minimum PWM frequency corresponding to a prescaler.
prescaler | 1,2,4,8,16,32,64,128 |
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().
void eFlex::Timer::printAllRegs | ( | Stream & | out = Serial | ) | const |
Print registers of PWM module and its submodules to the output stream.
out | the output stream, Serial by default |
void eFlex::Timer::printRegs | ( | Stream & | out = Serial | ) | const |
Print PWM module registers to the output stream.
out | the output stream, Serial by default |
|
inline |
Sets or clears the PWM LDOK bit on all instantiated submodules for this timer.
begin()
was called with doSync=truevalue | true: Set LDOK bit for the submodule list; false: Clear LDOK bit |
Definition at line 237 of file eFlexPwmTimer.h.
Referenced by eFlex::SubModule::setPwmLdok().
|
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.
subModulesToUpdate | PWM submodules to update with buffered values. This is a logical OR of members of the enumeration pwm_module_control_t |
value | true: Set LDOK bit for the submodule list; false: Clear LDOK bit |
Definition at line 257 of file eFlexPwmTimer.h.
void eFlex::Timer::setupDeadtime | ( | uint16_t | deadtimeValue, |
uint32_t | unit = 1 |
||
) |
Setting the deadtime for all submodules before calling begin.
deadtimeValue | The deadtime value in clock cycles; only used if channel pair is operating in complementary mode |
unit | The unit of the deadtimeValue; 1: clock cycles; 1000: milliseconds; 1000000: microseconds; 1000000000: nanoseconds |
void eFlex::Timer::setupDutyCyclePercent | ( | uint8_t | dutyCyclePercent | ) |
Setting the duty cycle for all submodules before calling begin.
dutyCyclePercent | duty cycle in percent |
|
inline |
Sets up the PWM fault input filter.
faultInputFilterParams | Parameters passed in to set up the fault input filter. |
Definition at line 266 of file eFlexPwmTimer.h.
|
inline |
Sets up the PWM fault protection.
PWM has 4 fault inputs.
faultNum | PWM fault to configure. |
faultParams | Pointer to the PWM fault config structure |
Definition at line 278 of file eFlexPwmTimer.h.
void eFlex::Timer::setupFaultState | ( | pwm_fault_state_t | faultState | ) |
Setting the output fault status for all submodules before calling begin.
faultState | the output fault status |
void eFlex::Timer::setupLevel | ( | pwm_level_select_t | level | ) |
Setting the output pulse mode for all submodules before calling begin.
level | output pulse mode |
void eFlex::Timer::setupOutputEnable | ( | bool | activate = true | ) |
Setting output enable for all submodules before calling begin.
activate | true to enable the outputs |
|
inline |
Starts or stops the PWM counter for all instantiated submodules for this timer.
startit | true to start, false to stop |
begin()
was called with doStart=true Definition at line 117 of file eFlexPwmTimer.h.
References start().
|
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.
subModulesToStart | PWM submodules to start. This is a logical OR of members of the enumeration pwm_module_control_t |
startit | true to start, false to stop |
Definition at line 102 of file eFlexPwmTimer.h.
Referenced by start(), eFlex::SubModule::start(), and stop().
|
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.
subModulesToStop | PWM 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().
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.
doSync | true: Set LDOK bit for the submodule; false: LDOK bit don't set, need to call setPwmLdok to sync update. |