MIKROE 4-20mA RT Click
|
Class to manage a MIKROE 4-20 mA R Click Board (MIKROE-1387). More...
#include <MIKROE_4_20mA_RT_Click.h>
Public Member Functions | |
R_Click (uint8_t CS_pin, const RT_Click_Calibration calib) | |
Construct a new R Click object. More... | |
R_Click (uint8_t CS_pin, const RT_Click_Calibration calib, uint32_t EMA_interval, float EMA_LP_freq) | |
Construct a new R Click object that uses an exponential moving average (EMA) on the R Click readings. More... | |
void | set_SPI_clock (uint32_t clk_freq_Hz) |
Adjust the initially set SPI clock frequency of 1 MHz to another frequency. More... | |
void | begin () |
Start SPI and set up the cable select pin. | |
float | bitval2mA (float bitval) |
Transform the bit value into a current [mA] given the calibration parameters. More... | |
uint16_t | read_bitval () |
Read out the R Click once and return the bit value. More... | |
float | read_mA () |
Read out the R Click once and return the current in mA. More... | |
bool | poll_EMA () |
This method is crucial for the exponential moving average (EMA) to work correctly. It should be repeatedly called in the main loop, ideally at a faster pace than the given oversampling interval EMA_interval . More... | |
float | get_EMA_bitval () |
Return the exponential moving average value of the R Click readings in bit value. More... | |
float | get_EMA_mA () |
Return the exponential moving average value of the R Click readings in mA. More... | |
uint32_t | get_EMA_obtained_interval () |
Return the last obtained interval of the oversampled R Click readings of the exponential moving average in microseconds. More... | |
Class to manage a MIKROE 4-20 mA R Click Board (MIKROE-1387).
R_Click::R_Click | ( | uint8_t | CS_pin, |
const RT_Click_Calibration | calib | ||
) |
Construct a new R Click object.
Methods read_bitval() and read_mA() can be used to get the instanteneous R Click reading.
CS_pin | Cable select SPI pin |
calib | Structure holding the [bitval] to [mA] calibration parameters |
R_Click::R_Click | ( | uint8_t | CS_pin, |
const RT_Click_Calibration | calib, | ||
uint32_t | EMA_interval, | ||
float | EMA_LP_freq | ||
) |
Construct a new R Click object that uses an exponential moving average (EMA) on the R Click readings.
It does this by oversampling the R Click readings at a desired interval given by EMA_interval
. Subsequently, it will low-pass filter the readings using a smoothing factor that is calculated from the low-pass filter cut-off frequency given by EMA_LP_freq
.
Method poll_EMA() should be repeatedly called in the main loop, ideally at a faster pace than the desired oversampling interval.
Methods get_EMA_bitval() and get_EMA_mA() can be used to get the moving average value.
CS_pin | Cable select SPI pin |
calib | Structure holding the [bitval] to [mA] calibration parameters |
EMA_interval | Desired oversampling interval [µs] |
EMA_LP_freq | Low-pass filter cut-off frequency [Hz] |
void R_Click::set_SPI_clock | ( | uint32_t | clk_freq_Hz | ) |
Adjust the initially set SPI clock frequency of 1 MHz to another frequency.
The maximum SPI clock frequency listed by the datasheet of the MCP3201 ADC chip of the R Click Board is 1.6 MHz.
clk_freq_Hz | The SPI clock frequency in Hz |
float R_Click::bitval2mA | ( | float | bitval | ) |
Transform the bit value into a current [mA] given the calibration parameters.
Currents less than 3.8 mA are considered to indicate a fault state, such as a broken wire, a disconnected device or an error happening at the transmitter side. In that case the return value will be NAN.
bitval | The bit value to transform |
uint16_t R_Click::read_bitval | ( | ) |
Read out the R Click once and return the bit value.
float R_Click::read_mA | ( | ) |
Read out the R Click once and return the current in mA.
bool R_Click::poll_EMA | ( | ) |
This method is crucial for the exponential moving average (EMA) to work correctly. It should be repeatedly called in the main loop, ideally at a faster pace than the given oversampling interval EMA_interval
.
EMA_interval
and EMA_LP_freq
must have been passed to the R_Click() constructor. float R_Click::get_EMA_bitval | ( | ) |
Return the exponential moving average value of the R Click readings in bit value.
EMA_interval
and EMA_LP_freq
must have been passed to the R_Click() constructor and poll_EMA() must have been repeatedly called. float R_Click::get_EMA_mA | ( | ) |
Return the exponential moving average value of the R Click readings in mA.
EMA_interval
and EMA_LP_freq
must have been passed to the R_Click() constructor and poll_EMA() must have been repeatedly called. uint32_t R_Click::get_EMA_obtained_interval | ( | ) |
Return the last obtained interval of the oversampled R Click readings of the exponential moving average in microseconds.