libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
AdcUdt Class Reference

Structure for ADC features. More...

Public Member Functions

 AdcUdt (BYVAL_AS_Pruio__PTR)
 The constructor for the ADC features. More...
 
FUNCTION_CDECL_AS_ZSTRING_PTR initialize (BYVAL_AS_UInt8, BYVAL_AS_UInt32, BYVAL_AS_UInt8)
 Initialize the register context after running the pasm_init.p instructions (private). More...
 
FUNCTION_CDECL_AS_ZSTRING_PTR configure (BYVAL_AS_UInt32, BYVAL_AS_UInt32, BYVAL_AS_UInt32, BYVAL_AS_UInt16)
 Configuration of ADC parameters for PRU (private). More...
 
FUNCTION_CDECL_AS_ZSTRING_PTR setStep (BYVAL_AS_UInt8, BYVAL_AS_UInt8, BYVAL_AS_UInt8, BYVAL_AS_UInt8, BYVAL_AS_UInt32)
 Customize a single configuration step. More...
 
FUNCTION_CDECL_AS_UInt32 mm_trg_pin (BYVAL_AS_UInt8, BYVAL_AS_UInt8, BYVAL_AS_UInt16)
 Create a trigger configuration for a digital trigger (GPIO). More...
 
FUNCTION_CDECL_AS_UInt32 mm_trg_ain (BYVAL_AS_UInt8, BYVAL_AS_Int32, BYVAL_AS_UInt8, BYVAL_AS_UInt16)
 Create a trigger configuration for an analog input trigger. More...
 
FUNCTION_CDECL_AS_UInt32 mm_trg_pre (BYVAL_AS_UInt8, BYVAL_AS_Int32, BYVAL_AS_UInt16, BYVAL_AS_UInt8)
 Create a trigger configuration for an analog input trigger. More...
 

Public Attributes

Pruio__PTR Top
 Pointer to the calling PruIo instance.
 
AdcSet_PTR Init
 Initial subsystem configuration, used in the destructor PruIo::~PruIo().
 
AdcSet_PTR Conf
 Current subsystem configuration, used in PruIo::config().
 
UInt32 Samples
 Number of samples (specifies run mode: 0 = config, 1 = IO mode, >1 = RB/MM mode).
 
UInt32 TimerVal
 Timer value in [ns].
 
UInt32 InitParA
 Offset to read data block offset.
 
UInt16 LslMode
 Bit shift modus (0 to 4, for 12 to 16 bits).
 
UInt16 ChAz
 The number of active steps.
 
UInt16_PTR Value
 Fetched ADC samples (step 1 => Value[1], ..., step 16 => Value[16]).
 
ZSTRING_PTR E0 = "step number too big"
 Common error message.
 
ZSTRING_PTR E1 = "channel number too big"
 Common error message.
 
ZSTRING_PTR E2 = "too much values to skip"
 Common error message.
 
ZSTRING_PTR E3 = "trigger step not configured"
 Common error message.
 
ZSTRING_PTR E4 = "invalid step number"
 Common error message.
 
ZSTRING_PTR E5 = "ADC not enabled"
 Common error message.
 

Detailed Description

Structure for ADC features.

The UDT contains the variables and member function to control the ADC subsystem.

Since
0.2

Definition at line 79 of file pruio_adc.bi.

Constructor & Destructor Documentation

◆ AdcUdt()

AdcUdt::AdcUdt ( BYVAL_AS_Pruio__PTR  T)

The constructor for the ADC features.

Parameters
TA pointer of the calling PruIo structure.

The constructor prepares the DRam parameters to run the pasm_init.p instructions. The adress of the subsystem and the adress of the clock registers get prepared, and the index of the last parameter gets stored to compute the offset in the Init and Conf data blocks.

Since
0.2

Definition at line 31 of file pruio_adc.bas.

Here is the caller graph for this function:

Member Function Documentation

◆ configure()

FUNCTION_CDECL_AS_ZSTRING_PTR AdcUdt::configure ( BYVAL_AS_UInt32  Samp = PRUIO_DEF_SAMPLS,
BYVAL_AS_UInt32  Mask = PRUIO_DEF_STPMSK,
BYVAL_AS_UInt32  Tmr = PRUIO_DEF_TIMERV,
BYVAL_AS_UInt16  Mds = PRUIO_DEF_LSLMOD 
)

Configuration of ADC parameters for PRU (private).

Parameters
SampThe number of samples to fetch (or 1 for IO mode).
MaskThe step mask to use.
TmrThe timer value in ns (ignored in IO mode).
MdsThe bit encoding modus (0 = 12 bit, ... 4 = 16 bit).
Returns
Zero on success (otherwise a string with an error message).

This is a private function, designed to be called from PruIo::config(). It checks if the ADC subsystem is enabled and prepares parameters in PruIo::DRam. Don't call it directly.

Since
0.2

Definition at line 101 of file pruio_adc.bas.

◆ initialize()

FUNCTION_CDECL_AS_ZSTRING_PTR AdcUdt::initialize ( BYVAL_AS_UInt8  Av = PRUIO_DEF_AVRAGE,
BYVAL_AS_UInt32  OpD = PRUIO_DEF_ODELAY,
BYVAL_AS_UInt8  SaD = PRUIO_DEF_SDELAY 
)

Initialize the register context after running the pasm_init.p instructions (private).

Parameters
AvThe avaraging for default step configuration.
OpDThe open delay for default step configuration.
SaDThe sample delay for default step configuration.
Returns
Zero on success (otherwise a string with an error message).

This is a private function, designed to be called from the main constructor PruIo::PruIo(). It sets the pointers to the Init and Conf structures in the data blocks. And it initializes some register context, if the subsystem woke up and is enabled.

Since
0.2

Definition at line 56 of file pruio_adc.bas.

Here is the caller graph for this function:

◆ mm_trg_ain()

FUNCTION_CDECL_AS_UInt32 AdcUdt::mm_trg_ain ( BYVAL_AS_UInt8  Stp,
BYVAL_AS_Int32  AdcV,
BYVAL_AS_UInt8  Rela = 0,
BYVAL_AS_UInt16  Skip = 0 
)

Create a trigger configuration for an analog input trigger.

Parameters
StpThe step number to use for trigger input (or 0 for all active steps).
AdcVThe sample value to match (positive checks greater than, negative checks less than).
RelaNot zero means AdcV is relative to the sample at start (ignored when Stp = 0).
SkipThe number of samples to skip (defaults to 0 = zero, max. 1023).
Returns
The trigger configuration (or zero in case of an error, check PruIo::Errr).

This function is used to create a configuration for an analog (= AIN) trigger. Pass the returned value as parameter to function PruIo::mm_start(). The measurement (or the next trigger) will start when the specified analog input (AIN) gets in to the declared state.

The parameter Stp specifies the step number to use for the trigger. This may be an active step (enabled in the PruIo::config() call). Or it can be a further step with customized settings only for trigger purposes (see trigger.bas for an example).

The parameter AdcV specifies the value to compare with. A positive value starts when the input is greater than AdcV. A negative value starts when the input is less than AdcV.

AdcV is scalled like the samples, so when the previuos call to function PruIo::config() requires 16 bit samples (Mds = 4), AdcV has to be specified as 16 bit value as well.

AdcV can either be an absolute value or a relative value. For the later case set parameter Rela to any value <> zero. The driver will fetch the current analog input value when the trigger gets active and adds AdcV to calculate the absolute trigger value.

This trigger value gets auto-limited to a certain range (ie &hF0 to &hFF00, in case of default 16 bit setting), to avoid trigger values that never can be reached.

The parameter Skip can be used to hold up the start for a certain time (previously defined by the Tmr parameter in the last call to function PruIo::config() ). Example:

Tmr = 1e8 ' 10 Hz
Skip = 500 ' skip 500 samples
time = Skip / Tmr * 1e9 ' delay time = 5 seconds (1e9 = Hz / GHz)

This trigger is a fast trigger. Only the specified step is active while waiting for the event. The trigger step can be inactive in the Mask of the previous call to function PruIo::config() and only be used for trigger purposes. (Ie. a short open delay can get specified for the trigger step since there is no channel muxing.)

Note
All error checks in this function are related to the parameters of the previuos call to function PruIo::config(). The created specification may get invalid by changing the ADC settings by a further call to function PruIo::config() with different parameters (ie. when the trigger step gets cleared). To be on the save side, re-create your trigger specifications after each call to function PruIo::config().

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

Since
0.2

Definition at line 367 of file pruio_adc.bas.

Here is the caller graph for this function:

◆ mm_trg_pin()

FUNCTION_CDECL_AS_UInt32 AdcUdt::mm_trg_pin ( BYVAL_AS_UInt8  Ball,
BYVAL_AS_UInt8  GpioV = 0,
BYVAL_AS_UInt16  Skip = 0 
)

Create a trigger configuration for a digital trigger (GPIO).

Parameters
BallThe CPU ball number to test.
GpioVThe state to check (defaults to low = 0).
SkipThe number of samples to skip (defaults to 0 = zero, max. 1023).
Returns
The trigger configuration (or zero in case of an error, check PruIo::Errr).

This function is used to create a configuration for a digital (= GPIO) trigger. Pass the returned value as parameter to function PruIo::mm_start(). The measurement (or the next trigger) will start when the specified GPIO gets in to the declared state. Ie using the default setting, the GPIO can get pulled up by an internal resistor and the measurement starts when the pin is grounded by a button.

Note
When the pin is in the declared at the time of the PruIo::mm_start() function call, the measurement starts immediatelly.

The parameter Skip can be used to hold up the start for a certain time (previously defined by the Tmr parameter in the last call to function PruIo::config() ).

This trigger is a fast trigger. The ADC subsystem is waiting in idle mode while the GPIO gets checked.

Note
When the CPU ball number (parameter Ball) is on a GPIO subsystem that is not enabled, an error gets reported (return value = zero). When you switch off the subsystem after creating the trigger specification, the trigger has no effect (it gets skipped).

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

Since
0.2

Definition at line 278 of file pruio_adc.bas.

Here is the caller graph for this function:

◆ mm_trg_pre()

FUNCTION_CDECL_AS_UInt32 AdcUdt::mm_trg_pre ( BYVAL_AS_UInt8  Stp,
BYVAL_AS_Int32  AdcV,
BYVAL_AS_UInt16  Samp = 0,
BYVAL_AS_UInt8  Rela = 0 
)

Create a trigger configuration for an analog input trigger.

Parameters
StpThe step number to use for trigger input.
AdcVThe sample value to match (positive check greater than, negative check less than).
SampThe number of samples for the pre-trigger.
RelaIf AdcV is relative to the current input.
Returns
The trigger configuration (or zero in case of an error, check PruIo::Errr).

This function is used to create a configuration for an analog (= AIN) pre-trigger. Pass the returned value as parameter to function PruIo::mm_start(). The measurement on all active steps will start immediately and collect the input values in a ring buffer. Normal measurement starts when the specified analog input (AIN) gets in to the declared state.

Either a certain step (that must be activated in the previous call to function PruIo::config() ) can be checked. Or all active inputs get checked against the specified AdcV. In the later case AdcV is allways an absolute value (parameter Rela gets ignored).

The parameter AdcV specifies the value to compare with. A positive value starts when the input is greater than AdcV. A negative value starts when the input is less than AdcV.

AdcV is scalled like the samples, so when the previuos call to function PruIo::config() requires 16 bit samples (Mds = 4), AdcV has to be specified as 16 bit value as well.

AdcV can either be an absolute value or a relative value. For the later case set parameter Rela to any value <> zero. The driver will fetch the current analog input value when the trigger gets active and add AdcV to calculate the absolute trigger value.

The trigger value gets auto-limited to a certain range (ie &hF0 to &hFF00, in case of default 16 bit setting), to avoid trigger values that never can be reached.

Parameter Samp is used to specify the number of samples to fetch before the trigger event occurs. It specifies the number of sampling sets for all active channels. Its maximum value is limited to 1023 and also by the amount of memory available (approx. 7000 samples in DRam0 and DRam1) to sort the ring buffer.

The pre-trigger is a slow trigger. The ADC subsystem goes through all activated steps while waiting for the trigger event.

Note
All error checks in this function are related to the parameters of the previuos call to function PruIo::config(). The created specification may get invalid by changing the ADC settings by a further call to function PruIo::config() with different parameters (ie. when the trigger step gets cleared). To be on the save side, re-create your trigger specifications after each call to function PruIo::config().
A pre-trigger is always the last trigger specification in the call to function PruIo::mm_start() (all further specifications get ignored).

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

Since
0.2

Definition at line 454 of file pruio_adc.bas.

Here is the caller graph for this function:

◆ setStep()

FUNCTION_CDECL_AS_ZSTRING_PTR AdcUdt::setStep ( BYVAL_AS_UInt8  Stp,
BYVAL_AS_UInt8  ChN,
BYVAL_AS_UInt8  Av = PRUIO_DEF_AVRAGE,
BYVAL_AS_UInt8  SaD = PRUIO_DEF_SDELAY,
BYVAL_AS_UInt32  OpD = PRUIO_DEF_ODELAY 
)

Customize a single configuration step.

Parameters
StpStep index (0 = step 0 => charge step, 1 = step 1 (=> AIN-0 by default), ..., 17 = idle step)
ChNChannel number to scan (0 = AIN-0, 1 = AIN-1, ...)
AvNew value for avaraging (defaults to 4)
SaDNew value for sample delay (defaults to 0)
OpDNew value for open delay (defaults to 0x98)
Returns
Zero on success (otherwise a string with an error message).

This function is used to adapt a step configuration. In the constructor, steps 1 to 8 get configured for AIN-0 to AIN-7 (other steps stay un-configured). By this function you can customize the default settings and / or configure further steps (input channel number, avaraging and delay values).

Parameter Stp is the step number in the hardware sequencer FSM. The steps get executed in upcounting order, if enabled. Since there are eight input lines, but 16 steps in the sequencer, the sampling sequence can be asymmetric.

Stp Description
0 charge step
1 step 1
2 step 2
... ...
16 step 16
Note
This sets the local data on the host system (ARM). The setup gets uploaded to the PRU and activated when calling function PruIo::config().

Parameter ChN is the ADC line to measure. The ADC subsystem multiplexes eight lines to the ADC unit (AIN-[0-7]). On Beaglebone boards (2x46 headers) AIN-7 is not pinned out, but wired to the on-board power, and therefor usable for power measurements only.

Parameter Av specifies avaraging. The hardware can perform multiple measuremnts before serving the a single result, in order to increase accuracy. Avaraging slows down maximum sampling rate.

The parameters SaD and OpD are delay values (cycles @ 24MHz). The ADC subsystem can perform some wait cycles after the multiplexer switching, in order to optimize the transient behavior for high impedance signals. The SaD (= sample delay) gets applicated before each sampling process (ie. between each avaraging measurements), and the OpD (= open delay) gets applicated once (before the avaraging sequence).

It's also possible to directly write to the step configuration in AdcSet::St_p by writing to the member variables Confg and Delay. See ARM Reference Guide, chapter 12 for details on ADC configurations.

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

Since
0.2

Definition at line 223 of file pruio_adc.bas.

Here is the caller graph for this function:

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