libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
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 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 Sync (BYVAL_AS_UInt8)
 Synchronize PWMSS-PWM modules. More...
 

Public Attributes

Pruio__PTR Top
 pointer to the calling PruIo instance
 
UInt16 ForceUpDown = 0
 Switch to force up-down counter for ePWM modules.
 
UInt16 Cntrl [PRUIO_AZ_PWMSS+1]
 Initializers TBCTL register for ePWM modules (see PWM). More...
 
UInt16 AqCtl [1+1][PRUIO_AZ_PWMSS+1][+1]
 Initializers for Action Qualifier for ePWM modules (see PWM). More...
 

Detailed Description

UDT for PWM modules, containing the functions to drive the hardware.

Pulse width modulated (PWM) output can get generated in three ways.

  1. The PWM subsystems (PWMSS) contain a ePWM module, which can generate two PWM outputs at the same frequency (up to 17 bit resolution at up to 100 MHz).
  2. The PWMSS also contains a eCAP module, which can generate a single PWM output with 32 bit resolution at 100 MHz.
  3. The TimerSS can also be used to generate PWM output with 32 bit resolution at up to 25 MHz.

All PWM generators (ePWM-1/2, eCAP and Timer) are controlled by the member functions of this structure (UDT). See ARM Reference Guide, chapter 15 for hardware details.

Since
0.2

Definition at line 239 of file pruio_pwmss.bi.

Constructor & Destructor Documentation

◆ PwmMod()

PwmMod::PwmMod ( BYVAL_AS_Pruio__PTR  T)

The constructor for PWM features of the PWMSS.

Parameters
TA pointer of the calling PruIo structure.

Each of the three Pulse Width Modulation SubSystems (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 470 of file pruio_pwmss.bas.

Here is the caller graph for this function:

Member Function Documentation

◆ setValue()

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
BallThe CPU ball number.
HzThe frequency to set (or -1 for no change).
DuThe 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 in the PWMSS subsystem, or by one of the TIMER-[4-7] subsystems. Depending on the specified pin number (parameter Ball), the corresponding PWMSS module or TIMERSS 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. In case of eHRPWM modules both outputs A and B of must run at the same frequency, so you need not set the Hz parameter when you set the Du parameter for the second 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, in order to calculate differences.

Wrapper function (C or Python): pruio_pwm_setValue().

Since
0.2

Definition at line 564 of file pruio_pwmss.bas.

Here is the caller graph for this function:

◆ Sync()

FUNCTION_CDECL_AS_ZSTRING_PTR PwmMod::Sync ( BYVAL_AS_UInt8  Mask)

Synchronize PWMSS-PWM modules.

Parameters
MaskThe bit-mask to set
Returns
Zero on success (otherwise a string with an error message).

All clocks of the PWM modules in the PWM sub systems can get enabled or disabled by a single write access to TBCLK register in the controll modules (CM). This feature allows to syncronise PWM signals generated by several modules on different subsystem. The process is

  1. stopp the related PWMSS-PWM modules
  2. configure the registers
  3. start the clocks simultaneou0sly

In order to stop a clock, set its bit in the Mask parameter to 0 (zero). Bit 2 is for PWMSS2-PWM, Bit 1 for PWMSS1-PWM and Bit 0 for PWMSS0-PWM module.

Once you configured the modules and uploaded the configuration to the PRUSS (by calling PruIo::config() ) you can start all PWM modules by a further call with their Mask bits set to 1. See ARM Reference Guide, chapter 15.2.2.3.4 for details,

Examples:

.sync(&b000) ' -> stopps all PWM module clocks
.sync(&b101) ' -> starts clocks of modules 2 and 0, counters synchonized
Since
0.6

Definition at line 648 of file pruio_pwmss.bas.

◆ Value()

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 PWM output configuration.

Parameters
BallThe pin index.
HzA pointer to output the frequency value (or 0 for no output).
DuA 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.

Wrapper function (C or Python): pruio_pwm_Value().

Since
0.2

Definition at line 489 of file pruio_pwmss.bas.

Here is the caller graph for this function:

Member Data Documentation

◆ AqCtl

UInt16 PwmMod::AqCtl[1+1][PRUIO_AZ_PWMSS+1][+1]
Initial value:
=
{ { {&b000000010010, &b000000010010, &b000001000010}
, {&b000000010010, &b000000010010, &b000001000010}
, {&b000000010010, &b000000010010, &b000001000010} }
, { {&b000100000010, &b000100000010, &b010000000010}
, {&b000100000010, &b000100000010, &b010000000010}
, {&b000100000010, &b000100000010, &b010000000010} } }

Initializers for Action Qualifier for ePWM modules (see PWM).

Definition at line 245 of file pruio_pwmss.bi.

◆ Cntrl

UInt16 PwmMod::Cntrl[PRUIO_AZ_PWMSS+1]
Initial value:
=
{&b1010000000010000, &b1010000000010000, &b1010000000010000}

Initializers TBCTL register for ePWM modules (see PWM).

Definition at line 243 of file pruio_pwmss.bi.


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