Hello world. I'm working on a project that has a timer and a fuel gauge and have been banging my head against the wall trying to figure out a formula. I had a hard time researching and the best term that describes it is "Non-Linear Equation". I've been staring at X's and Y's for a couple days.
First, the fuel gauge is current driven. The needle reads Empty with 12V @ 10ohm on the signal line. Full is around 220ohm. I am using an MCP4728 DAC to output a nice smooth analog signal. The DAC has a 12-Bit resolution (0-4095 in DEC, 0-5V Vref). I have a timer that counts down starting from 240(4 Min).
:DAC Output(0-4095):
@720 Needle reads Full
@735 Needle reads 3/4ths
@760 Needle reads 1/2
@800 Needle reads 1/4th
@1100 Needle reads Empty
As you can see I cannot simply map the DAC output to a percentage of the total time left. What happens is the needle reads 1/4th and I still have 3 minutes left hence the Non-Linear equation. Here is a quick snippet of my state machine:
case RUNNING:
status = "RUNNING";
timer.Timer();
//Calculate gauge values.
unsigned long TotalSeconds;
TotalSeconds = timer.ShowTotalSeconds();
quadDACVoltVal = map(TotalSeconds, 0, ((timerMinutes * 60) + timerSeconds), quadDACVoltLow, quadDACVoltHigh);
quadDACSpeedVal = map(TotalSeconds, 0, ((timerMinutes * 60) + timerSeconds), quadDACSpeedLow, quadDACSpeedHigh);
quadDACFuelVal = map(TotalSeconds, 0, ((timerMinutes * 60) + timerSeconds), quadDACFuelLow, quadDACFuelHigh);
quadDAC.voutWrite(quadDACFuelVal, quadDACVoltVal, quadDACSpeedVal, 0);
if (timer.TimeHasChanged() )
{
//Dump timer value to Serial port.
Serial.print("Time Left> ");
Serial.print(timer.ShowMinutes());
Serial.print(":");
Serial.println(timer.ShowSeconds());
Serial.print("Total Clock: ");
Serial.println(timer.ShowTotalSeconds());
Serial.println("");
Serial.print("Volt: ");
Serial.println(quadDACVoltVal);
Serial.print("Speed: ");
Serial.println(quadDACSpeedVal);
Serial.print("Fuel: ");
Serial.println(quadDACFuelVal);
//Check if timer has ended.
if (timer.TimeCheck() == true )
{
Serial.println("Timer has finished!");
machine = STOPPED;
}
}
break;
After talking to a buddy he was stating that I should have a ramping X that increases based on time taken. So lets say X = DAC Multiplier/Divider?. First step should occur after 4 seconds (X= X * 1.01), second step after 4 seconds (X= X * 1.02) and so on. I'm hoping someone has ran into this and I'm looking at this wrong. Any help would be much appreciated. Thank you.