Serial Wombat Arduino Library

Loading...
Searching...
No Matches
Public Member Functions | List of all members
SerialWombatAnalogInput Class Reference

A class to make analog measurements with the Serial Wombat. More...

`#include <SerialWombatAnalogInput.h>`

Inheritance diagram for SerialWombatAnalogInput:
[legend]
Collaboration diagram for SerialWombatAnalogInput:
[legend]

## Public Member Functions
| SerialWombatAnalogInput (SerialWombatChip &SerialWombatChip)
| Constructor for the SerialWombatAnalogInput class.
int16_t | begin (uint8_t pin, uint16_t averageSamples=64, uint16_t filterConstant=0xFF80, AnalogInputPublicDataOutput output=AnalogInputPublicDataOutput::AnalogInputPublicDataOutput_Raw)
| Initialize an analog input on a given pin.
uint16_t | readVoltage_mV ()
| Retreive a raw A/D measurement and convert it to mV.
uint16_t | readCounts ()
| Retreive a raw A/D measurement.
uint16_t | readFiltered_mV ()
| Retreive a filtered A/D measurement and convert it to mV.
uint16_t | readFilteredCounts ()
| Retreive a filtered A/D measurement.
uint16_t | readAveraged_mV ()
| Retreive an averaged A/D measurement and convert it to mV.
uint16_t | readAveragedCounts ()
| Retreive an averaged A/D measurement.
uint16_t | updateSupplyVoltage_mV ()
| Provides a wrapper around the readSupplyVoltage_mV() method for the SerialWombat chip hosting this pin mode.
uint16_t | readMaximum_mV (bool resetAfterRead=false)
| Retreive the maximum single sample A/D value in mV.
uint16_t | readMaximumCounts (bool resetAfterRead=false)
uint16_t | readMinimum_mV (bool resetAfterRead=false)
uint16_t | readMinimumCounts (bool resetAfterRead=false)
| Retreive the maximum single sample A/D value in counts.
Public Member Functions inherited from SerialWombatPin
| SerialWombatPin (SerialWombatChip &serialWombatChip)
| Instantiates a Serial Wombat Pin.
| SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
| Instantiates a Serial Wombat Pin.
uint16_t | readPublicData ()
| Read the 16 Bit public data associated with this pin.
void | pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false)
| Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
void | digitalWrite (uint8_t val)
| Set output pin High or Low.
int | digitalRead ()
| Reads the state of the Pin.
uint16_t | writePublicData (uint16_t value)
| Write a 16 bit value to this pin.
uint8_t | pin ()
| Returns the current SW pin number. Used primarily for virtual calls by derived classes.
uint8_t | swPinModeNumber ()
| Returns the Mode number. Used primarily by derived classes to populate packet data.
int16_t | initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
int16_t | disable ()
| Disables the pin mode (if applicable)
int16_t | enablePullup (bool enabled)
| Enables the weak pull up on a pin. Implemented on SW18AB only.
int16_t | enablePullDown (bool enabled)
| Enables the weak pull down on a pin. Implemented on SW18AB only.
int16_t | enableOpenDrain (bool enabled)
| Enables open drain mode on a pin. Implemented on SW18AB only.

## Additional Inherited Members
Protected Attributes inherited from SerialWombatPin
uint8_t | _pin = 255
SerialWombatChip & | _sw
uint8_t | _pinMode = 0

## Detailed Description

A class to make analog measurements with the Serial Wombat.

The SerialWombatAnalogInput class is used to make measurements on a given pin.

Any analog-capable pin may be used to make a measurement.

Averaging of samples and first order IIR filtering (1 kHz sampling) of input are available.

For a good explanation of 1st order IIR filter calculations, see: https://www.monocilindro.com/2017/04/08/how-to-implement-a-1st-order-iir-filter-in-5-minutes/

Some filter cut-off (3dB down) frequency and constant values:

- 0.5 Hz 65417
- 1 Hz 65298
- 2 Hz 65062
- 5 Hz 64358
- 10 Hz 63202

Filtering adds lag. The higher the filter constant value, the longer it takes for the filter to settle when given a steady input.

Declare and initialize a SerialWombatAnalogInput instance for each pin being used as an analog input.

The SW4B_ard_analogInput example included with the Arduino library shows how to use this class.

A Tutorial video is also avaialble:

https://youtu.be/_EKlrEVaEhg

Definition at line 80 of file SerialWombatAnalogInput.h.

## Constructor & Destructor Documentation

## ◆ SerialWombatAnalogInput()

SerialWombatAnalogInput::SerialWombatAnalogInput | ( | SerialWombatChip & | SerialWombatChip | ) |
| inline

Constructor for the SerialWombatAnalogInput class.

Parameters

  SerialWombatChip | a reference to the Serial Wombat chip on which the Analog Input will be measured

Definition at line 88 of file SerialWombatAnalogInput.h.

## Member Function Documentation

## ◆ begin()

int16_t SerialWombatAnalogInput::begin | ( | uint8_t | pin,
|  | uint16_t | averageSamples = 64,
|  | uint16_t | filterConstant = 0xFF80,
|  | AnalogInputPublicDataOutput | output = AnalogInputPublicDataOutput::AnalogInputPublicDataOutput_Raw )
| inline

Initialize an analog input on a given pin.

Parameters

  pin | The Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3 SW18AB: 0-4 and 16-19
  averageSamples | Number of samples to average. Valid values for SW4A and SW4B are 0 or 64. All non-zero values will be treated as 64 on these platforms. Default is 64.
  filterConstant | First Order IIR filter constant, expressed as 1/65536ths . Default is 65508 Values closer to 65536 give heavier filtering. Sample frequency is 1kHz.
  publicDataOutput | What to output as pin public data. Default is raw.

Returns
  Returns a negative error code if initialization failed.

Definition at line 105 of file SerialWombatAnalogInput.h.

## ◆ readAveraged_mV()

uint16_t SerialWombatAnalogInput::readAveraged_mV | ( |  | ) |
| inline

Retreive an averaged A/D measurement and convert it to mV.

Conversion is based on the most recent averaged A/D result taken by the Serial Wombat A/D at the command time and the last reference measurement made on the Serial Wombat chip using the SerialWombatChip.readSupplyVoltage_mV() method.

Returns
  A 16 bit unsigned value indicating measurement in mV

Definition at line 194 of file SerialWombatAnalogInput.h.

## ◆ readAveragedCounts()

uint16_t SerialWombatAnalogInput::readAveragedCounts | ( |  | ) |
| inline

Retreive an averaged A/D measurement.

Conversion is based on the most recent averaged A/D value taken by the Serial Wombat A/D at the command time.

All Serial Wombat products will return a 16-bit value. However the SW4A and SW4B products only have 10-bit A/D converters. Averaging will potentially increase the effective resolution slightly for signals that have a small amount of randomly distributed noise.

Returns
  A 16 bit unsigned value indicating the counts of the A/D conversion

Definition at line 214 of file SerialWombatAnalogInput.h.

## ◆ readCounts()

uint16_t SerialWombatAnalogInput::readCounts | ( |  | ) |
| inline

Retreive a raw A/D measurement.

Conversion is based on the most recent A/D conversion taken by the Serial Wombat A/D at the command time.

All Serial Wombat products will return a 16-bit value. However the SW4A and SW4B products only have 10-bit A/D converters, so the returned value moves by 64 counts at a time, except for the topmost value. For all Serial Wombat products, the highest possible reading (0xFFC0 for the SW4A/SW4B, 0xFFF0 for the SW18AB) is changed to 0xFFFF to indicate maximum possible hardware value.

Returns
  A 16 bit unsigned value indicating the counts of the A/D conversion

Definition at line 147 of file SerialWombatAnalogInput.h.

## ◆ readFiltered_mV()

uint16_t SerialWombatAnalogInput::readFiltered_mV | ( |  | ) |
| inline

Retreive a filtered A/D measurement and convert it to mV.

Conversion is based on the most recent filtered A/D result taken by the Serial Wombat A/D at the command time and the last reference measurement made on the Serial Wombat chip using the SerialWombatChip.readSupplyVoltage_mV() method.

Returns
  A 16 bit unsigned value indicating measurement in mV

Definition at line 160 of file SerialWombatAnalogInput.h.

## ◆ readFilteredCounts()

uint16_t SerialWombatAnalogInput::readFilteredCounts | ( |  | ) |
| inline

Retreive a filtered A/D measurement.

Conversion is based on the most recent filtered A/D value taken by the Serial Wombat A/D at the command time.

Returns
  A 16 bit unsigned value indicating the filtered A/D result

Definition at line 176 of file SerialWombatAnalogInput.h.

## ◆ readMaximum_mV()

uint16_t SerialWombatAnalogInput::readMaximum_mV | ( | bool | resetAfterRead = false | ) |
| inline

Retreive the maximum single sample A/D value in mV.

The maximum value the Serial Wombat chip has seen on that pin since last reset of Min/Max

Parameters

  resetAfterRead | If True, maximum value is set to 0 after read so that subsequent values become maximum. Also resets minimum to next sample.

Returns
  A 16 bit unsigned value indicating measurement in mV

Definition at line 238 of file SerialWombatAnalogInput.h.

## ◆ readMaximumCounts()

uint16_t SerialWombatAnalogInput::readMaximumCounts | ( | bool | resetAfterRead = false | ) |
| inline

    \brief Retreive the maximum single sample A/D value in counts

    The maximum value the Serial Wombat chip has seen on that pin since last reset of Min/Max

/

Parameters

  resetAfterRead | If True, maximum value is set to 0 after read so that subsequent values become maximum. Also resets minimum to next sample.

Returns
  A 16 bit unsigned value indicating maximum A/D Counts

Definition at line 260 of file SerialWombatAnalogInput.h.

## ◆ readMinimum_mV()

uint16_t SerialWombatAnalogInput::readMinimum_mV | ( | bool | resetAfterRead = false | ) |
| inline

    \brief Retreive the minimum single sample A/D value in mV

    The minimum value the Serial Wombat chip has seen on that pin since last reset of Min/Max

/

Parameters

  resetAfterRead | If True, minimum value is set to 0 after read so that subsequent values become minimum. Also resets maximum to next sample.

Returns
  A 16 bit unsigned value indicating measurement in mV

Definition at line 281 of file SerialWombatAnalogInput.h.

## ◆ readMinimumCounts()

uint16_t SerialWombatAnalogInput::readMinimumCounts | ( | bool | resetAfterRead = false | ) |
| inline

Retreive the maximum single sample A/D value in counts.

The maximum value the Serial Wombat chip has seen on that pin since last reset of Min/Max

Parameters

  resetAfterRead | If True, maximum value is set to 0 after read so that subsequent values become maximum. Also resets minimum to next sample.

Returns
  A 16 bit unsigned value indicating maximum A/D Counts

Definition at line 298 of file SerialWombatAnalogInput.h.

## ◆ readVoltage_mV()

uint16_t SerialWombatAnalogInput::readVoltage_mV | ( |  | ) |
| inline

Retreive a raw A/D measurement and convert it to mV.

Conversion is based on the most recent A/D conversion taken by the Serial Wombat A/D at the command time and the last reference measurement made on the Serial Wombat chip using the SerialWombatChip.readSupplyVoltage_mV() method.

Returns
  A 16 bit unsigned value indicating measurement in mV

Definition at line 124 of file SerialWombatAnalogInput.h.

## ◆ updateSupplyVoltage_mV()

uint16_t SerialWombatAnalogInput::updateSupplyVoltage_mV | ( |  | ) |
| inline

Provides a wrapper around the readSupplyVoltage_mV() method for the SerialWombat chip hosting this pin mode.

Definition at line 223 of file SerialWombatAnalogInput.h.