I need to provide 0-100mV for another electronic device, regulating its state of charge (SOC). The mV represents a SOC of 0-100%. The controlled device does its own SOC calculation (which is incorrect at the top and bottom by up to 7%.
I have an UNO which runs runs related code and I want to give it the task to produce the 0-100mV very accurately and constantly.
The processing pseudo code:
setup() {
set mV_Output to OFF
}
loop() {
read 60 bytes on serial
determine battery SOC
send correct value in mV to controlled device (continuously)
}
Now the circuit for the mV source... I understand that I can use common op amps, but to not know how to configure their peripherals to produce a a stable mV value based on a float calculation.
void controlSOC(float controlValue) {
/*
* SoC value to control charger
* analog out is 0-5V with 255 steps or 5V/255 steps = 0.0196mV/step
* 100mv ~
* input: AHR = amp hour value for charge (+) and discharge (-) value
* -400 ~ 0% SoC to 0 = 100% SoC
* Battery capacity 400 AH
* calc: ((-AHR / AH) + 1) * 100 | (-172/400 = -0.43 - 1 = .57 * 100 = 57%
*/
// calc A/D output value
controlValueOut = ((controlValue / BATT_CAPACITY_AH) + 1) * 100;
analogWrite(PIN_SOC_OUT, controlValueOut * 2.56);
return;
}
Anyone keen to suggest a circuit I can hang of the analog out?
I have seen a PWM out can be used to DAC?
I am open to suggestions WRT the circuit,but it has to be low noise, stable though variable Voltage.