i want to create hysteresis gap using atmega328p or atmega8, for controlling a 12vdc battery charger circuit.
where the mcu will cut off the charger at 13.7vdc and then again the charger start charging at when
the battery discharge to 12.7vdc , i want to create this gap of 13.7dc (cut off), 12.7vdc (again start charging) how
can i create this gap i don't have any idea how to do this? any help will be appreciated.
Basically flow chart this to give you insight into code needed.
If you are charging and see a trend over time, samples of V, that V is increasing
then setting a trip of 13.7 to stop charging trivial..
If battery is discharging, V dropping (even if you are supply charging current)
and you see samples of V over time that V is dropping then you invoke the low
trip.
it's just like schmitt trigger with custom values. i'm trying to solve it with atmega8 using
arduino IDE but facing problem with coding it, using a mosfet based switch with atmega8
so that it may stop/start the charging process by turning on/off through a digital pin of atmega8.
what's i do in my code is as:
step1: define boolean variable as "chgflag = true;" with all other variables as needed.
step2: measure voltage level of 13.7 volts using voltage divider of R1 = 10k & R2 = 5.6k with vin = 13.7vdc
step3: check condition by using
void loop()
{
if(vin >= 13.7)
{chgflag = false;"turn off mosfet switch"
while(vin >= 12.5) {chgflag = false; turn off mosfet switch; } /* start reading battery status by using while loop while battery discharging
to keep the switch off until the condition false*/
}.
/* but if the battery voltage less than 13.7vdc the controller will go to the "else if statement below*/ else if(vin < 13.7 && chgflag == true)
{ turn on mosfet switch; }
} . here there is some problem with my code i'm not identifying. using proteus with arduino IDE simulating this code.
I think with hysteresis there is no need to observe the previous state of the device.
Presumably a condition can exist where the voltage is below 12.5V so you can simply use:
the switch will turn on and the charger will start charging as vin < 13.7 with no hysteresis gap
continuously turn on/off as the voltage < 13.7 - voltage = 13.7. but i think it will be as the above
situation as shown.