ADC: ADC Class Reference

ADC 8.0 Analog to Digital Conversor library for the Teensy 3.6 microprocessor

Classes | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
ADC Class Reference

`#include <ADC.h>`

## Classes
struct | Sync_result
| Struct for synchronous measurements. More...

## Public Member Functions
| ADC ()
int | analogRead (uint8_t pin, int8_t adc_num=-1)
| Returns the analog value of the pin. More...
int | analogRead (ADC_INTERNAL_SOURCE pin, int8_t adc_num=-1)
| Returns the analog value of the special internal source, such as the temperature sensor. More...
int | analogReadDifferential (uint8_t pinP, uint8_t pinN, int8_t adc_num=-1)
| Reads the differential analog value of two pins (pinP - pinN). More...
bool | startSingleRead (uint8_t pin, int8_t adc_num=-1)
| Starts an analog measurement on the pin and enables interrupts. More...
bool | startSingleDifferential (uint8_t pinP, uint8_t pinN, int8_t adc_num=-1)
| Start a differential conversion between two pins (pinP - pinN) and enables interrupts. More...
int | readSingle (int8_t adc_num=-1)
| Reads the analog value of a single conversion. More...
bool | startContinuous (uint8_t pin, int8_t adc_num=-1)
| Starts continuous conversion on the pin. More...
bool | startContinuousDifferential (uint8_t pinP, uint8_t pinN, int8_t adc_num=-1)
| Starts continuous conversion between the pins (pinP-pinN). More...
int | analogReadContinuous (int8_t adc_num=-1)
| Reads the analog value of a continuous conversion. More...
void | stopContinuous (int8_t adc_num=-1)
| Stops continuous conversion. More...
Sync_result | analogSynchronizedRead (uint8_t pin0, uint8_t pin1)
| Returns the analog values of both pins, measured at the same time by the two ADC modules. More...
Sync_result | analogSyncRead (uint8_t pin0, uint8_t pin1)
| Same as analogSynchronizedRead. More...
Sync_result | analogSynchronizedReadDifferential (uint8_t pin0P, uint8_t pin0N, uint8_t pin1P, uint8_t pin1N)
| Returns the differential analog values of both sets of pins, measured at the same time by the two ADC modules. More...
Sync_result | analogSyncReadDifferential (uint8_t pin0P, uint8_t pin0N, uint8_t pin1P, uint8_t pin1N)
| Same as analogSynchronizedReadDifferential. More...
bool | startSynchronizedSingleRead (uint8_t pin0, uint8_t pin1)
| Starts an analog measurement at the same time on the two ADC modules. More...
bool | startSynchronizedSingleDifferential (uint8_t pin0P, uint8_t pin0N, uint8_t pin1P, uint8_t pin1N)
| Start a differential conversion between two pins (pin0P - pin0N) and (pin1P - pin1N) More...
Sync_result | readSynchronizedSingle ()
| Reads the analog value of a single conversion. More...
bool | startSynchronizedContinuous (uint8_t pin0, uint8_t pin1)
| Starts a continuous conversion in both ADCs simultaneously. More...
bool | startSynchronizedContinuousDifferential (uint8_t pin0P, uint8_t pin0N, uint8_t pin1P, uint8_t pin1N)
| Starts a continuous differential conversion in both ADCs simultaneously. More...
Sync_result | readSynchronizedContinuous ()
| Returns the values of both ADCs. More...
void | stopSynchronizedContinuous ()
| Stops synchronous continuous conversion.
void | resetError ()

## Public Attributes
ADC_Module *const | adc0 = &adc0_obj
| Object to control the ADC0.
ADC_Module *const | adc1 = &adc1_obj
| Object to control the ADC1.
ADC_Module *const | adc [ADC_NUM_ADCS] = {adc0, adc1}
| Array with the ADC Modules.

## Static Public Attributes
static const uint8_t | channel2sc1aADC0 [ADC_MAX_PIN+1]
| Translate pin number to SC1A nomenclature.
static const uint8_t | channel2sc1aADC1 [ADC_MAX_PIN+1]
| Translate pin number to SC1A nomenclature.
static const uint8_t | sc1a2channelADC0 [ADC_MAX_PIN+1]
| Translate pin number to SC1A nomenclature for differential pins.
static const uint8_t | sc1a2channelADC1 [ADC_MAX_PIN+1]
| Translate pin number to SC1A nomenclature for differential pins.
static const ADC_Module::ADC_NLIST | diff_table_ADC0 [ADC_DIFF_PAIRS]
| Translate differential pin number to SC1A nomenclature.
static const ADC_Module::ADC_NLIST | diff_table_ADC1 [ADC_DIFF_PAIRS]
| Translate differential pin number to SC1A nomenclature.

## Detailed Description

Class ADC: Controls the Teensy 3.x, 4 ADC

## Constructor & Destructor Documentation

## ◆ ADC()

ADC::ADC | ( |  | ) |

Default constructor

## Member Function Documentation

## ◆ analogRead() [1/2]

int ADC::analogRead | ( | ADC_INTERNAL_SOURCE | pin,
|  | int8_t | adc_num = `-1`
| ) |  |
| inline

Returns the analog value of the special internal source, such as the temperature sensor.

It calls analogRead(uint8_t pin) internally, with the correct value for the pin for all boards. Possible values: TEMP_SENSOR, Temperature sensor. VREF_OUT, 1.2 V reference (switch on first using VREF.h). BANDGAP, BANDGAP (switch on first using VREF.h). VREFH, High VREF. VREFL, Low VREF.

Parameters

  pin | ADC_INTERNAL_SOURCE to read.
  adc_num | ADC_X ADC module

Returns
  the value of the pin.

## ◆ analogRead() [2/2]

int ADC::analogRead | ( | uint8_t | pin,
|  | int8_t | adc_num = `-1`
| ) |  |

Returns the analog value of the pin.

It waits until the value is read and then returns the result. If a comparison has been set up and fails, it will return ADC_ERROR_VALUE. This function is interrupt safe, so it will restore the adc to the state it was before being called If more than one ADC exists, it will select the module with less workload, you can force a selection using adc_num. If you select ADC1 in Teensy 3.0 it will return ADC_ERROR_VALUE.

Parameters

  pin | can be any of the analog pins
  adc_num | ADC_X ADC module

Returns
  the value of the pin.

## ◆ analogReadContinuous()

int ADC::analogReadContinuous | ( | int8_t | adc_num = `-1` | ) |

Reads the analog value of a continuous conversion.

Set the continuous conversion with with analogStartContinuous(pin) or startContinuousDifferential(pinP, pinN). If single-ended and 16 bits it's necessary to typecast it to an unsigned type (like uint16_t), otherwise values larger than 3.3/2 V are interpreted as negative!

Parameters

  adc_num | ADC_X ADC module

Returns
  the last converted value.

## ◆ analogReadDifferential()

int ADC::analogReadDifferential | ( | uint8_t | pinP,
|  | uint8_t | pinN,
|  | int8_t | adc_num = `-1`
| ) |  |

Reads the differential analog value of two pins (pinP - pinN).

It waits until the value is read and then returns the result. This function is interrupt safe, so it will restore the adc to the state it was before being called If more than one ADC exists, it will select the module with less workload, you can force a selection using adc_num

Parameters

  pinP | must be A10 or A12.
  pinN | must be A11 (if pinP=A10) or A13 (if pinP=A12).
  adc_num | ADC_X ADC module

Returns
  the differential value of the pins, invalid pins return ADC_ERROR_VALUE. If a comparison has been set up and fails, it will return ADC_ERROR_VALUE.

## ◆ analogSynchronizedRead()

Sync_result ADC::analogSynchronizedRead | ( | uint8_t | pin0,
|  | uint8_t | pin1
| ) |  |

Returns the analog values of both pins, measured at the same time by the two ADC modules.

It waits until the values are read and then returns the result as a struct Sync_result, use Sync_result.result_adc0 and Sync_result.result_adc1. If a comparison has been set up and fails, it will return ADC_ERROR_VALUE in both fields of the struct. This function is interrupt safe, so it will restore the adc to the state it was before being called

Parameters

  pin0 | pin in ADC0
  pin1 | pin in ADC1

Returns
  a Sync_result struct with the result of each ADC value.

## ◆ analogSynchronizedReadDifferential()

Sync_result ADC::analogSynchronizedReadDifferential | ( | uint8_t | pin0P,
|  | uint8_t | pin0N,
|  | uint8_t | pin1P,
|  | uint8_t | pin1N
| ) |  |

Returns the differential analog values of both sets of pins, measured at the same time by the two ADC modules.

It waits until the values are read and then returns the result as a struct Sync_result, use Sync_result.result_adc0 and Sync_result.result_adc1. If a comparison has been set up and fails, it will return ADC_ERROR_VALUE in both fields of the struct. This function is interrupt safe, so it will restore the adc to the state it was before being called

Parameters

  pin0P | positive pin in ADC0
  pin0N | negative pin in ADC0
  pin1P | positive pin in ADC1
  pin1N | negative pin in ADC1

Returns
  a Sync_result struct with the result of each differential ADC value.

## ◆ analogSyncRead()

Sync_result ADC::analogSyncRead | ( | uint8_t | pin0,
|  | uint8_t | pin1
| ) |  |
| inline

Same as analogSynchronizedRead.

Parameters

  pin0 | pin in ADC0
  pin1 | pin in ADC1

Returns
  a Sync_result struct with the result of each ADC value.

## ◆ analogSyncReadDifferential()

Sync_result ADC::analogSyncReadDifferential | ( | uint8_t | pin0P,
|  | uint8_t | pin0N,
|  | uint8_t | pin1P,
|  | uint8_t | pin1N
| ) |  |
| inline

Same as analogSynchronizedReadDifferential.

Parameters

  pin0P | positive pin in ADC0
  pin0N | negative pin in ADC0
  pin1P | positive pin in ADC1
  pin1N | negative pin in ADC1

Returns
  a Sync_result struct with the result of each differential ADC value.

## ◆ readSingle()

int ADC::readSingle | ( | int8_t | adc_num = `-1` | ) |

Reads the analog value of a single conversion.

Set the conversion with with startSingleRead(pin) or startSingleDifferential(pinP, pinN).

Parameters

  adc_num | ADC_X ADC module

Returns
  the converted value.

## ◆ readSynchronizedContinuous()

Sync_result ADC::readSynchronizedContinuous | ( |  | ) |

Returns the values of both ADCs.

Returns
  the converted value.

## ◆ readSynchronizedSingle()

Sync_result ADC::readSynchronizedSingle | ( |  | ) |

Reads the analog value of a single conversion.

Returns
  the converted value.

## ◆ resetError()

void ADC::resetError | ( |  | ) |
| inline

ERRORS ///// Resets all errors from all ADCs, if any.

## ◆ startContinuous()

bool ADC::startContinuous | ( | uint8_t | pin,
|  | int8_t | adc_num = `-1`
| ) |  |

Starts continuous conversion on the pin.

It returns as soon as the ADC is set, use analogReadContinuous() to read the value.

Parameters

  pin | can be any of the analog pins
  adc_num | ADC_X ADC module

Returns
  true if the pin is valid, false otherwise.

## ◆ startContinuousDifferential()

bool ADC::startContinuousDifferential | ( | uint8_t | pinP,
|  | uint8_t | pinN,
|  | int8_t | adc_num = `-1`
| ) |  |

Starts continuous conversion between the pins (pinP-pinN).

It returns as soon as the ADC is set, use analogReadContinuous() to read the value.

Parameters

  pinP | must be A10 or A12.
  pinN | must be A11 (if pinP=A10) or A13 (if pinP=A12).
  adc_num | ADC_X ADC module

Returns
  true if the pins are valid, false otherwise.

## ◆ startSingleDifferential()

bool ADC::startSingleDifferential | ( | uint8_t | pinP,
|  | uint8_t | pinN,
|  | int8_t | adc_num = `-1`
| ) |  |

Start a differential conversion between two pins (pinP - pinN) and enables interrupts.

It returns immediately, get value with readSingle(). If this function interrupts a measurement, it stores the settings in adc_config

Parameters

  pinP | must be A10 or A12.
  pinN | must be A11 (if pinP=A10) or A13 (if pinP=A12).
  adc_num | ADC_X ADC module

Returns
  true if the pins are valid, false otherwise.

## ◆ startSingleRead()

bool ADC::startSingleRead | ( | uint8_t | pin,
|  | int8_t | adc_num = `-1`
| ) |  |

Starts an analog measurement on the pin and enables interrupts.

It returns immediately, get value with readSingle(). If this function interrupts a measurement, it stores the settings in adc_config

Parameters

  pin | can be any of the analog pins
  adc_num | ADC_X ADC module

Returns
  true if the pin is valid, false otherwise.

## ◆ startSynchronizedContinuous()

bool ADC::startSynchronizedContinuous | ( | uint8_t | pin0,
|  | uint8_t | pin1
| ) |  |

Starts a continuous conversion in both ADCs simultaneously.

Use readSynchronizedContinuous to get the values

Parameters

  pin0 | pin in ADC0
  pin1 | pin in ADC1

Returns
  true if the pins are valid, false otherwise.

## ◆ startSynchronizedContinuousDifferential()

bool ADC::startSynchronizedContinuousDifferential | ( | uint8_t | pin0P,
|  | uint8_t | pin0N,
|  | uint8_t | pin1P,
|  | uint8_t | pin1N
| ) |  |

Starts a continuous differential conversion in both ADCs simultaneously.

Use readSynchronizedContinuous to get the values

Parameters

  pin0P | positive pin in ADC0
  pin0N | negative pin in ADC0
  pin1P | positive pin in ADC1
  pin1N | negative pin in ADC1

Returns
  true if the pins are valid, false otherwise.

## ◆ startSynchronizedSingleDifferential()

bool ADC::startSynchronizedSingleDifferential | ( | uint8_t | pin0P,
|  | uint8_t | pin0N,
|  | uint8_t | pin1P,
|  | uint8_t | pin1N
| ) |  |

Start a differential conversion between two pins (pin0P - pin0N) and (pin1P - pin1N)

It returns immediately, get value with readSynchronizedSingle(). If this function interrupts a measurement, it stores the settings in adc_config

Parameters

  pin0P | positive pin in ADC0
  pin0N | negative pin in ADC0
  pin1P | positive pin in ADC1
  pin1N | negative pin in ADC1

Returns
  true if the pins are valid, false otherwise.

## ◆ startSynchronizedSingleRead()

bool ADC::startSynchronizedSingleRead | ( | uint8_t | pin0,
|  | uint8_t | pin1
| ) |  |

Starts an analog measurement at the same time on the two ADC modules.

It returns immediately, get value with readSynchronizedSingle(). If this function interrupts a measurement, it stores the settings in adc_config

Parameters

  pin0 | pin in ADC0
  pin1 | pin in ADC1

Returns
  true if the pins are valid, false otherwise.

## ◆ stopContinuous()

void ADC::stopContinuous | ( | int8_t | adc_num = `-1` | ) |

Stops continuous conversion.

Parameters

  adc_num | ADC_X ADC module

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

- ADC.h