Aruna
aruna::driver::ADC Class Referenceabstract

Analogue digital converter. More...

#include <ADC.h>

Inheritance diagram for aruna::driver::ADC:

Public Member Functions

template<typename T >
err_t read_raw (T &raw)
 Read raw value from ADC, convert to voltage yourself. More...
 
template<typename T >
err_t read_voltage (T &mV)
 Read voltage level of input. More...
 
size_t get_resolution () const
 Get the resolution in bits of the ADC. More...
 
uint16_t get_reference () const
 Get the reference voltage in micro Voltage. More...
 
virtual int32_t raw_to_voltage (int32_t raw)
 Convert raw data to voltage. More...
 
template<typename T >
aruna::err_t read_raw (T &raw)
 
template<typename T >
aruna::err_t read_voltage (T &mV)
 

Protected Member Functions

err_t set_resolution (size_t bits)
 Set resolution of ADC. More...
 
err_t set_reference (uint16_t mV)
 set reference voltage, used to convert raw data to voltage. More...
 

Private Member Functions

virtual err_t _read (int32_t &raw)=0
 Read analogue value and convert to 32bit signed resolution. More...
 

Private Attributes

size_t resolution = 0
 resolution of the ADC in bits. More...
 
uint16_t reference = 0
 ADC voltage refrence, for convertage to voltage. More...
 

Detailed Description

Analogue digital converter.

Definition at line 19 of file ADC.h.

Member Function Documentation

◆ _read()

virtual err_t aruna::driver::ADC::_read ( int32_t &  raw)
privatepure virtual

Read analogue value and convert to 32bit signed resolution.

Parameters
rawstore result here
Returns
error code

Implemented in aruna::driver::ADS101x.

Here is the caller graph for this function:

◆ get_reference()

uint16_t aruna::driver::ADC::get_reference ( ) const

Get the reference voltage in micro Voltage.

Returns
micro Voltage, used by the ADC as reference.

Definition at line 40 of file ADC.cpp.

40  {
41  return reference;
42  }
uint16_t reference
ADC voltage refrence, for convertage to voltage.
Definition: ADC.h:29

◆ get_resolution()

size_t aruna::driver::ADC::get_resolution ( ) const

Get the resolution in bits of the ADC.

Use this value to pick the right int for the template functions

Returns
resolution of this ADC

Definition at line 23 of file ADC.cpp.

23  {
24  return resolution;
25  }
size_t resolution
resolution of the ADC in bits.
Definition: ADC.h:24

◆ raw_to_voltage()

int32_t aruna::driver::ADC::raw_to_voltage ( int32_t  raw)
virtual

Convert raw data to voltage.

Parameters
rawdata from ADC
Returns
voltage in mV.

Definition at line 27 of file ADC.cpp.

27  {
28  double input, inputLow, inputHigh, outputHigh, outputLow;
29  input = raw;
30  inputLow = 0;
31  inputHigh = INT32_MAX;
32  outputHigh = reference;
33  outputLow = 0;
34 // TODO make convert_range function and replace Actuator::convert_range with this
35 // https://gamedev.stackexchange.com/questions/33441/how-to-convert-a-number-from-one-min-max-set-to-another-min-max-set
36  return ((input - inputLow) / (inputHigh - inputLow)) * (outputHigh - outputLow) + outputLow;
37 
38  }
uint16_t reference
ADC voltage refrence, for convertage to voltage.
Definition: ADC.h:29
Here is the caller graph for this function:

◆ read_raw() [1/2]

template<typename T >
aruna::err_t aruna::driver::ADC::read_raw ( T &  raw)

Definition at line 16 of file ADC.hpp.

16  {
17  return _read(raw);
18 }
virtual err_t _read(int32_t &raw)=0
Read analogue value and convert to 32bit signed resolution.
Here is the call graph for this function:

◆ read_raw() [2/2]

template<typename T >
err_t aruna::driver::ADC::read_raw ( T &  raw)

Read raw value from ADC, convert to voltage yourself.

Parameters
rawstores result
Returns
errors
Here is the caller graph for this function:

◆ read_voltage() [1/2]

template<typename T >
aruna::err_t aruna::driver::ADC::read_voltage ( T &  mV)

Definition at line 21 of file ADC.hpp.

21  {
22  int32_t raw;
23  aruna::err_t err;
24  err = read_raw(raw);
25  if ((bool) err)
26  return err;
27 
28  mV = raw_to_voltage(raw);
29  return aruna::err_t::OK;
30 }
err_t read_raw(T &raw)
Read raw value from ADC, convert to voltage yourself.
virtual int32_t raw_to_voltage(int32_t raw)
Convert raw data to voltage.
Definition: ADC.cpp:27
Here is the call graph for this function:

◆ read_voltage() [2/2]

template<typename T >
err_t aruna::driver::ADC::read_voltage ( T &  mV)

Read voltage level of input.

Parameters
mVint stores microvoltage
Returns
errors
Here is the caller graph for this function:

◆ set_reference()

err_t aruna::driver::ADC::set_reference ( uint16_t  mV)
protected

set reference voltage, used to convert raw data to voltage.

Parameters
mVmicro Voltage
Returns
err_t::OK

Definition at line 18 of file ADC.cpp.

18  {
19  reference = mV;
20  return err_t::OK;
21  }
uint16_t reference
ADC voltage refrence, for convertage to voltage.
Definition: ADC.h:29
Here is the caller graph for this function:

◆ set_resolution()

err_t aruna::driver::ADC::set_resolution ( size_t  bits)
protected

Set resolution of ADC.

All logic still uses 16bit, this is only for reference

Parameters
bitsnew resolution
Returns
err_t::OK

Definition at line 13 of file ADC.cpp.

13  {
14  resolution = bits;
15  return err_t::OK;
16  }
size_t resolution
resolution of the ADC in bits.
Definition: ADC.h:24
Here is the caller graph for this function:

Member Data Documentation

◆ reference

uint16_t aruna::driver::ADC::reference = 0
private

ADC voltage refrence, for convertage to voltage.

Definition at line 29 of file ADC.h.

◆ resolution

size_t aruna::driver::ADC::resolution = 0
private

resolution of the ADC in bits.

Definition at line 24 of file ADC.h.


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