I'm working on a project where I need to map an incoming reading to an actual reading which is a float variable.
I have a power supply where I want to see the set voltage compared to the actual voltage been displayed. The reading are been taken from an MCP4822 12bit dac and been read by 16bit adc along with the input voltage coming in from the power supply.
But the trouble I'm having is that the set voltage does not match the actual voltage.
The incoming voltage reading from Dac is 1.869 and the actual voltage from the power supply is 18.43 volts and using the map function that I've seen on the map reference site but the set reading is showing 19.31 not sure if this is the correct way or miss understood what I have read.
I thought that it would be closer to 18.41 than 19.31 ?
This is my simple test code where I'm just checking and comparing by input the actual dac reading coming in.
#include <LiquidCrystal_I2C.h> // I2C LCD display only for intial setup
#include <Wire.h> //Wire libary
int DAC_input = A0; // select the input pin for the potentiometer
//#########################
//# CHANNEL ONE VARIABLES #
//#########################
float volts_Set_disp_Ch1;
float Set_volts_temp = 0;
float Set_volts_1_in_min = 0.805; //This what the incoming min set voltage from Dac reading with 16bit ADC
float Set_volts_1_in_max = 2.464; //This what the incoming max set voltage from Dac reading with 16bit ADC
float Set_volts_1_out_min = 0.00; //start of near 0
float Set_volts_1_out_max = 30.05; //Actual maxium voltage output
//####################################################
//# Specifying the CE and CS pins & LCD Pins #
//####################################################
LiquidCrystal_I2C lcd(0x03f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
void setup() {
Serial.begin(9600);
// lcd.setBacklight(HIGH);//debuging only used for I2C LCD
lcd.begin(16, 2); // General LCD 2 x 8 with backlight
lcd.clear();
}
//####################################################
//# Main Lop starts here #
//####################################################
void loop() {
Set_volts_temp = 1.869; // This is the actual voltage coming in from dac,
//Map float the actual voltage reading on display is 18.41 and with 1.869 coming in form dac teh set voltage reading is 19.31
volts_Set_disp_Ch1 = (Set_volts_temp - Set_volts_1_in_min) * (Set_volts_1_out_max - Set_volts_1_out_min) / (Set_volts_1_in_max - Set_volts_1_in_min ) + Set_volts_1_out_min;
lcd.setCursor(0, 0);
lcd.print(Set_volts_temp , 3); // 2 dp's
lcd.print(" ");
if ( volts_Set_disp_Ch1 >= 9.99) {
lcd.setCursor(0, 1);
lcd.print(volts_Set_disp_Ch1 , 2); // 2 dp's
lcd.print(" ");
} else {
lcd.setCursor(0, 1);
lcd.print(volts_Set_disp_Ch1 , 3); // 3 dp's
lcd.print(" ");
}
}
