Commit 697f9e26 authored by Patrick's avatar Patrick

set the start/end values for 4-20mA ADC readings globaly

parent 237b8f00
......@@ -147,6 +147,7 @@ void red_peg::sensorsOff()
float red_peg::degC(t_SensorData data_record)
{
if (data_record.the_sensor == TMP) {
// convert 0-32767 reading to 10mV/degC conversion w/ 0.5V offset from zero
return float( ((data_record.the_reading * (2.048/32767.0)) - 0.5) * 100.0 );
} else {
return -1.0;
......@@ -167,7 +168,7 @@ float red_peg::volts(t_SensorData data_record)
float red_peg::mA(t_SensorData data_record)
{
if (data_record.the_sensor == MA4_20) {
return float( data_record.the_reading * 20.48 / 32767.0 );
return float( data_record.the_reading * 20.0 / float(MAX_20MA) );
} else {
return -1.0;
}
......@@ -182,10 +183,9 @@ float red_peg::level(t_SensorData data_record, double max_level)
float red_peg::level(t_SensorData data_record, float max_level)
{
if (data_record.the_sensor == MA4_20) {
long zero_reading = 6553L;
// subtract the
long reading = long(data_record.the_reading) - zero_reading;
float level = float(reading) * ( max_level / (26214.0));
// subtract the minimum level value
long reading = long(data_record.the_reading) - MIN_4MA;
float level = float(reading) * ( max_level / float(MAX_20MA - MIN_4MA) );
return level;
} else {
return -max_level;
......@@ -201,10 +201,7 @@ long red_peg::level(t_SensorData data_record, int max_level)
long red_peg::level(t_SensorData data_record, long max_level)
{
if (data_record.the_sensor == MA4_20) {
long zero_reading = 6553L;
// subtract the
long reading = long(data_record.the_reading) - zero_reading;
long level = map(reading, 0, 26214L, 0, max_level);
long level = map(data_record.the_reading, MIN_4MA, MAX_20MA, 0, max_level);
return level;
} else {
return -max_level;
......@@ -214,7 +211,7 @@ long red_peg::level(t_SensorData data_record, long max_level)
float red_peg::distance(t_SensorData data_record)
{
if (data_record.the_command == ANA) {
long distance = map(data_record.the_reading, 0, 32767L, 0, 765L);
long distance = map(data_record.the_reading, 0, MAX_20MA, 0, 765L);
return distance;
} else {
return -1.0;
......
......@@ -35,6 +35,15 @@ enum sensor_e {EMPTY, AVAILABLE, OK, RTC, ADC1, ADC2, ADC3, SDI_12, SET_RTC};
#define ANA ADC2
#define TMP ADC3
// min and max values for 4-20mA readings
// ADC max is 2.048V
#ifndef MIN_4MA
#define MIN_4MA 6400L // theoretical 0.4V
#endif
#ifndef MAX_20MA
#define MAX_20MA 31999L // theoretical 2.0V
#endif
typedef struct{
uint8_t start_byte = START_BYTE;
union {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment