All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PwmMod Class Reference

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

## Detailed Description

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.

## Constructor & Destructor Documentation

PwmMod::PwmMod | ( | BYVAL_AS_Pruio__PTR | T | ) |

The constructor for PWM features of the PWMSS.

Parameters

  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.

Since
  0.2

Definition at line 102 of file pruio_pwmss.bas.

Here is the caller graph for this function:

## Member Function Documentation

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

Parameters

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

Returns
  Zero on success, an error string otherwise.

This functions computes the real PWM configuration of an eCAP module.

Note
  This is a private function designed for internal use. It doesn't check the validity of the Nr parameter. Values greater than PRUIO_AZ_GPIO may result in wired behaviour.

Since
  0.2

Definition at line 245 of file pruio_pwmss.bas.

Here is the caller graph for this function:

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

Parameters

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

Returns
  Zero on success, an error string otherwise.

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%).

Note
  This is a private function designed for internal use. It doesn't check the validity of the Nr parameter. Values greater than PRUIO_AZ_GPIO may result in wired behaviour.

Since
  0.2

Definition at line 276 of file pruio_pwmss.bas.

Here is the caller graph for this function:

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

Parameters

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

Returns
  Zero on success, an error string otherwise.

This functions computes the real configuration of an eHRPWM module.

Note
  This is a private function designed for internal use. It doesn't check the validity of the Nr parameter. Values greater than PRUIO_AZ_GPIO may result in wired behaviour.

Since
  0.2

Definition at line 337 of file pruio_pwmss.bas.

Here is the caller graph for this function:

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

Parameters

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

Returns
  Zero on success, an error string otherwise.

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%).

Note
  This is a private function designed for internal use. It doesn't check the validity of the Nr parameter. Values greater than PRUIO_AZ_GPIO may result in wired behaviour.

Since
  0.2

Definition at line 385 of file pruio_pwmss.bas.

Here is the caller graph for this function:

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.

Parameters

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

Returns
  Zero on success (otherwise a string with an error message).

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.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters

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

Returns
  Zero on success, an error string otherwise.

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.

Since
  0.2

Definition at line 119 of file pruio_pwmss.bas.

Here is the call graph for this function:

The documentation for this class was generated from the following files:

- src/pruio/pruio_pwmss.bi
- src/pruio/pruio_pwmss.bas