Class AInput12Module

Inheritance Relationships

Base Type

Class Documentation

class AInput12Module : public Module

This class represents the Analogue Inputs Module connected via eMOD bus to controller module. This module has 12 independent analogue inputs, the value of each one can be obtained separately. Its configuration for measuring voltage or current can be set also separately.

Class example 1

/*
 * This example uses a AInput12Module to display analog inputs.
 */
#include "AInput12Module.hpp"
#include "EmodRetMng.hpp"
#include "HAL.hpp"

int main() {
    AInput12Module module;
    if (module.init() != 0) {
        printf("Module could not be initialized!\n");
        return 1;
    }

    // Configure inputs 4, 5 and 6 as current. By default are configured as voltage
    module.configInput(
        AInput12Module::AI_INPUT05 | 
        AInput12Module::AI_INPUT06 |
        AInput12Module::AI_INPUT07);
    sleepMs(100);

    module.configSampleRate(200);
    sleepMs(100);

    // Tests inputs
    while (1) {
        float aInputs[AInput12Module::NUMBER_OF_AI_INPUTS];
        if (module.getAllAnalogInput(aInputs) == 0) {
            printf("AI01 = %2.2f V //", aInputs[0]);
            printf("AI02 = %2.2f V //", aInputs[1]);
            printf("AI03 = %2.2f V //", aInputs[2]);
            printf("AI04 = %2.2f V //", aInputs[3]);
            printf("AI05 = %2.2f mA //", aInputs[4]);
            printf("AI06 = %2.2f mA //", aInputs[5]);
            printf("AI07 = %2.2f mA //", aInputs[6]);
            printf("AI04 = %2.2f V //", aInputs[7]);
            printf("AI04 = %2.2f V //", aInputs[8]);
            printf("AI04 = %2.2f V //", aInputs[9]);
            printf("AI04 = %2.2f V //", aInputs[10]);
            printf("AI04 = %2.2f V //", aInputs[11]);
            printf("\n");
        }

        sleepMs(1000);

        float a_input;
        if (module.getAnalogInput(AInput12Module::AI_INPUT01, &a_input) == 0) {
            printf("AI01 = %2.2f V\n", a_input);
        }
        if (module.getAnalogInput(AInput12Module::AI_INPUT02, &a_input) == 0) {
            printf("AI02 = %2.2f V\n", a_input);
        }
        if (module.getAnalogInput(AInput12Module::AI_INPUT03, &a_input) == 0) {
            printf("AI03 = %2.2f V\n", a_input);
        }
        if (module.getAnalogInput(AInput12Module::AI_INPUT04, &a_input) == 0) {
            printf("AI04 = %2.2f V\n", a_input);
        }
        if (module.getAnalogInput(AInput12Module::AI_INPUT05, &a_input) == 0) {
            printf("AI05 = %2.2f mA\n", a_input);
        }
        if (module.getAnalogInput(AInput12Module::AI_INPUT06, &a_input) == 0) {
            printf("AI06 = %2.2f mA\n", a_input);
        }
        if (module.getAnalogInput(AInput12Module::AI_INPUT07, &a_input) == 0) {
            printf("AI07 = %2.2f mA\n", a_input);
        }
        if (module.getAnalogInput(AInput12Module::AI_INPUT08, &a_input) == 0) {
            printf("AI04 = %2.2f V\n", a_input);
        }
        if (module.getAnalogInput(AInput12Module::AI_INPUT09, &a_input) == 0) {
            printf("AI04 = %2.2f V\n", a_input);
        }
        if (module.getAnalogInput(AInput12Module::AI_INPUT10, &a_input) == 0) {
            printf("AI04 = %2.2f V\n", a_input);
        }
        if (module.getAnalogInput(AInput12Module::AI_INPUT11, &a_input) == 0) {
            printf("AI04 = %2.2f V\n\n", a_input);
        }
        sleepMs(1000);
    }
}

Public Functions

AInput12Module()
~AInput12Module()
EmodRet init(const AInput12ModuleCallback_Type callback_func = nullptr, void *const callback_context = nullptr, const uint8_t variant = 1)

Initialize module. It is important to emphasize that this method is mandatory to call it. It can be called several times, each of which the module is initialized again.

Parameters
  • callback_func(optional) -- [in] function that will be called when a configured event occurs.

  • callback_context(optional) -- [in] context that will be passed to the callback function.

  • variant(optional) -- [in] identifies the module in case more than one module of the same type are present.

EmodRet init(const uint8_t variant)
EmodRet configSampleRate(const uint32_t ms_period)

Configure sample rate at which you want to check the analog input data.

Param

EmodRet configInput(const uint16_t voltage_input_mask)

Configure an input or set of inputs to select them for acquiring current (4 to 20 mA) or voltage (0 to 10 V).

Parameters

voltage_input_mask -- [in] input or list of analog inputs, as enumerated above in the constants section, to configure them for acquiring current. The rest of inputs will be configured for acquiring voltage.

EmodRet getInputConfig(uint16_t *config)

Gets configured inputs mask. Each input indicates if it’s configured to acquire voltage (0) or current (1).

Parameters

config -- [out] current input mask configuration (V/A) for each input as a mask.

EmodRet getAnalogInput(const uint16_t AI_INPUT_number, float *data)

Gets last measured value of a specified analog input.

Parameters
  • input_number -- [in] analog input number to get the data, as enumerated above in the constants section.

  • data -- [out] returns last measured input data. If data has not been received yet, NO_NEW_DATA_READ is returned. Parameter is initialized inside the class. When input was configured as current, value is shown in mA; otherwise it’s represented in V. When an input is configured in current mode and sampled_data is 0, it means that the current loop is broken.

EmodRet getAllAnalogInput(float data[NUMBER_OF_AI_INPUTS])

Gets last measured values for all analog inputs.

Parameters

data -- [out] returns last measured input number data for each analog input. If an analog input data has not been measured yet, NO_NEW_DATA_READ is returned in that input. Parameter is initialized inside the class. When input was configured as current, value is shown in mA; otherwise it’s represented in V. When an input is configured in current mode and sampled_data is 0, it means that the current loop is broken.

EmodRet configEventAtTimeInterval(const uint32_t time_interval, const uint32_t event_mask = AInput12Module::AI_ALL_INPUT)

Configures module for calling init callback_func at specified period.

Parameters
  • time_interval -- [in] period in milliseconds. Minimum value is 500ms,

  • event_mask -- [in] bit mask representing inputs that must trigger the event.

EmodRet configEventOnValueChange(const uint32_t threshold, const uint32_t event_mask = AInput12Module::AI_ALL_INPUT)

Configures module for calling init callback_func when input changes its value by a specified amount.

Parameters
  • threshold -- [in] amount of samples that triggers the event (use voltageToSample() for conversion).

  • event_mask -- [in] bit mask representing inputs that must trigger the event.

EmodRet configEventWithinRange(const uint32_t low_limit, const uint32_t high_limit, const uint32_t event_mask = AInput12Module::AI_ALL_INPUT)

Configures module for calling init callback_func when input value enters the specified range.

Parameters
  • low_limit -- [in] low limit of the range in samples (use voltageToSample() for conversion).

  • high_limit -- [in] high limit of the range in samples (use voltageToSample() for conversion).

  • event_mask -- [in] bit mask representing inputs that must trigger the event.

EmodRet configEventOutOfRange(const uint32_t low_limit, const uint32_t high_limit, const uint32_t event_mask = AInput12Module::AI_ALL_INPUT)

Configures module for calling init callback_func when input value gets out of the specified range.

Parameters
  • low_limit -- [in] low limit of the range in samples (use voltageToSample() for conversion).

  • high_limit -- [in] high limit of the range in samples (use voltageToSample() for conversion).

  • event_mask -- [in] bit mask representing inputs that must trigger the event.

EmodRet resetEventConfig(void)

Resets all previously configured events.

uint16_t voltageToSamples(float voltage)

Converts voltage to discrete samples.

Parameters

voltage -- [in] voltage in V, from 0 to 10.

uint16_t currentToSamples(float current)

Converts current to discrete samples.

Parameters

voltage -- [in] voltage in mA, from 4 to 20.

float samplesToVoltage(uint16_t samples)

Converts discrete samples to voltage.

Parameters

samples -- [in] discrete samples from 0 to 10000.

float samplesToCurrent(uint16_t samples)

Converts discrete samples to current.

Parameters

samples -- [in] discrete samples from 0 to 10000.

Public Static Attributes

static constexpr uint16_t AI_INPUT01 = AInput12Module_INPUT01
static constexpr uint16_t AI_INPUT02 = AInput12Module_INPUT02
static constexpr uint16_t AI_INPUT03 = AInput12Module_INPUT03
static constexpr uint16_t AI_INPUT04 = AInput12Module_INPUT04
static constexpr uint16_t AI_INPUT05 = AInput12Module_INPUT05
static constexpr uint16_t AI_INPUT06 = AInput12Module_INPUT06
static constexpr uint16_t AI_INPUT07 = AInput12Module_INPUT07
static constexpr uint16_t AI_INPUT08 = AInput12Module_INPUT08
static constexpr uint16_t AI_INPUT09 = AInput12Module_INPUT09
static constexpr uint16_t AI_INPUT10 = AInput12Module_INPUT10
static constexpr uint16_t AI_INPUT11 = AInput12Module_INPUT11
static constexpr uint16_t AI_INPUT12 = AInput12Module_INPUT12
static constexpr uint16_t AI_ALL_INPUT = AInput12Module_ALL_INPUT
static constexpr uint8_t NUMBER_OF_AI_INPUTS = AInput12Module_NUMBER_OF_AI_INPUTS
static constexpr uint16_t MAX_ADC = AInput12Module_MAX_ADC
static constexpr uint8_t CFG_VOLTAGE = AInput12Module_CFG_VOLTAGE
static constexpr uint8_t CFG_CURRENT = AInput12Module_CFG_CURRENT
static constexpr float MAX_VOLTAGE = AInput12Module_MAX_VOLTAGE
static constexpr float MAX_CURRENT = AInput12Module_MAX_CURRENT

Protected Functions

EmodRet initFunctions()
uint8_t getInputsOffsetId()
uint8_t getNumAnalogInputs()

Protected Attributes

AnalogInputFunctions *analogInputs