UDT for PWM modules, containing the functions to drive the hardware. More...
Public Member Functions | |
PwmMod (BYVAL_AS_Pruio__PTR) | |
The constructor for PWM features of the PWMSS. More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | Value (BYVAL_AS_UInt8, BYVAL_AS_Float_t_PTR, BYVAL_AS_Float_t_PTR) |
Compute header pin PWM output configuration. More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | setValue (BYVAL_AS_UInt8, BYVAL_AS_Float_t, BYVAL_AS_Float_t) |
Set PWM output on a header pin. More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | pwm_set (BYVAL_AS_UInt8, BYVAL_AS_Float_t, BYVAL_AS_Float_t, BYVAL_AS_Float_t) |
Configure PWM output at a eHRPWM module (private). More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | cap_set (BYVAL_AS_UInt8, BYVAL_AS_Float_t, BYVAL_AS_Float_t) |
Configure PWM output at an eCAP module (private). More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | pwm_get (BYVAL_AS_UInt8, BYVAL_AS_Float_t_PTR, BYVAL_AS_Float_t_PTR, BYVAL_AS_UInt8) |
Compute PWM output configuration from an eHRPWM module (private). More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | cap_get (BYVAL_AS_UInt8, BYVAL_AS_Float_t_PTR, BYVAL_AS_Float_t_PTR) |
Compute PWM output configuration from an eCAP module (private). More... | |
Public Attributes | |
Pruio__PTR | Top |
pointer to the calling PruIo instance | |
ZSTRING_PTR | E0 = "pin has no PWM capability" |
common error message | |
ZSTRING_PTR | E1 = "pin not in PWM mode" |
common error message | |
ZSTRING_PTR | E2 = "PWMSS not enabled" |
common error message | |
ZSTRING_PTR | E3 = "set frequency in first call" |
common error message | |
ZSTRING_PTR | E4 = "frequency not supported" |
common error message | |
UDT for PWM modules, containing the functions to drive the hardware.
Pulse width modulated (PWM) output can get generated in two ways. The PWM subsystems (PWMSS) contain a ePWM module, which can generate two PWM outputs at the same frequency (up to 17 bit resolution). And the PWMSS contains a eCAP module, which can generate a single PWM output (up to 32 bit resolution). All PWM generators (ePWM-1/2 and eCAP) are controlled by the member functions of this structure (UDT). See ARM Reference Guide, chapter 15 for hardware details.
To use a header pins as PWM output, the pin must be in pwm mode before starting your code. Then just set the desired period (frequency) and duty cycle (load) by a call to function PwmMod::setValue().
Definition at line 196 of file pruio_pwmss.bi.
PwmMod::PwmMod | ( | BYVAL_AS_Pruio__PTR | T | ) |
The constructor for PWM features of the PWMSS.
T | A pointer of the calling PruIo structure. |
Each of the three Pulse Width Modulation SubSystem (PWMSS) in the CPU contains modules (PWM, CAP and QEP). In order to create a clear API from the user point of view, the functions to control the modules are separated to extra classes. This UDT contains functions to control the PWM module.
The constructor just copies a pointer to the calling main UDT PruIo.
Definition at line 102 of file pruio_pwmss.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR PwmMod::cap_get | ( | BYVAL_AS_UInt8 | Nr, |
BYVAL_AS_Float_t_PTR | Freq = 0 , |
||
BYVAL_AS_Float_t_PTR | Duty = 0 |
||
) |
Compute PWM output configuration from an eCAP module (private).
Nr | The PWMSS subsystem index. |
Freq | A pointer to output the frequency value (or 0 for no output). |
Duty | A pointer to output the duty value (or 0 for no output). |
This functions computes the real PWM configuration of an eCAP module.
Definition at line 245 of file pruio_pwmss.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR PwmMod::cap_set | ( | BYVAL_AS_UInt8 | Nr, |
BYVAL_AS_Float_t | F, | ||
BYVAL_AS_Float_t | D = 0. |
||
) |
Configure PWM output at an eCAP module (private).
Nr | The PWMSS subsystem index. |
F | The frequency to set (or -1 for no change). |
D | The duty cycle for output A (0.0 to 1.0, or -1 for no change). |
This functions configures an eCAP module for PWM output. It sets the frequency and the duty cycle. Only positive values in these parameters force a change. Pass a negative value to stay with the current setting. A duty parameters greater than 1.0 gets limited to 1.0 (= 100%).
Definition at line 276 of file pruio_pwmss.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR PwmMod::pwm_get | ( | BYVAL_AS_UInt8 | Nr, |
BYVAL_AS_Float_t_PTR | F = 0 , |
||
BYVAL_AS_Float_t_PTR | Du = 0 , |
||
BYVAL_AS_UInt8 | Mo = 0 |
||
) |
Compute PWM output configuration from an eHRPWM module (private).
Nr | The PWMSS subsystem index. |
F | A pointer to output the frequency value (or 0 for no output). |
Du | A pointer to output the duty value (or 0 for no output). |
Mo | The output channel (0 = A, otherwise B). |
This functions computes the real configuration of an eHRPWM module.
Definition at line 337 of file pruio_pwmss.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR PwmMod::pwm_set | ( | BYVAL_AS_UInt8 | Nr, |
BYVAL_AS_Float_t | F, | ||
BYVAL_AS_Float_t | Da = 0. , |
||
BYVAL_AS_Float_t | Db = 0. |
||
) |
Configure PWM output at a eHRPWM module (private).
Nr | The PWMSS subsystem index. |
F | The frequency to set (or -1 for no change). |
Da | The duty cycle for output A (0.0 to 1.0, or -1 for no change). |
Db | The duty cycle for output B (0.0 to 1.0, or -1 for no change). |
This private function configures an eHRPWM module. It sets the common frequency and both output duties A and B. Only positive values in these parameters force a change. Pass a negative value to stay with the current setting. Duty parameters (Da and Db) greater than 1.0 get limited to 1.0 (= 100%).
Definition at line 385 of file pruio_pwmss.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR PwmMod::setValue | ( | BYVAL_AS_UInt8 | Ball, |
BYVAL_AS_Float_t | Hz, | ||
BYVAL_AS_Float_t | Du | ||
) |
Set PWM output on a header pin.
Ball | The CPU ball number. |
Hz | The frequency to set (or -1 for no change). |
Du | The duty cycle to set (0.0 to 1.0, or -1 for no change). |
This function sets PWM output on a header pin. PWM output may either be generated by a eHRPWM or a eCAP module. Depending on the specified pin number (parameter Ball), the corresponding PWMSS module gets configured to the specified frequency and duty cycle.
It's recommended to make the first call to this function before the call to function PruIo::config(), because eCAP pins (P9_28 or P9_42) can be used in PWM output and in CAP input mode. A mode change happens when the configurations gets transfered from the host to the PRU. Also, when an eCAP pin is currently used as input, the new PWM output mode gets active after the next call to function PruIo::config().
Only positive values in the parameters Hz and Du force a change. Pass a negative value to stay with the current setting. A duty parameter greater than 1.0 gets limited to 1.0 (= 100%).
In the first call to this function, the parameter Hz must be greater than 0 (zero), to set a valid period time. But both outputs A and B of an eHRPWM module must run at the same frequency, so you need not set the Hz parameter when you set the Du for the secand output.
The hardware settings (integer values) are computed to match the passed parameters Hz and Du as close as possible. Some parameter combinations are impossible to match exactly, due to hardware limitations (ie. 17 bit resolution in case of eHRPWM modules). Use function PwmMod::Value() to compute the active settings and calculate differences.
Definition at line 187 of file pruio_pwmss.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR PwmMod::Value | ( | BYVAL_AS_UInt8 | Ball, |
BYVAL_AS_Float_t_PTR | Hz = 0 , |
||
BYVAL_AS_Float_t_PTR | Du = 0 |
||
) |
Compute header pin PWM output configuration.
Ball | The pin index. |
Hz | A pointer to output the frequency value (or 0 for no output). |
Du | A pointer to output the duty value (or 0 for no output). |
This functions computes the real PWM output of a header pin. The real setting may differ from the parameters passed to function PwmMod::setValue(). Use this function to compute the active settings.
Definition at line 119 of file pruio_pwmss.bas.