Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

[SOLVED] hysteresis gap using arduino atmega8/atmega328

Status
Not open for further replies.

codemaster11

Member level 5
Joined
Sep 2, 2019
Messages
84
Helped
8
Reputation
16
Reaction score
6
Trophy points
8
Activity points
765
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.
 

danadakk

Advanced Member level 1
Joined
Mar 26, 2018
Messages
404
Helped
79
Reputation
157
Reaction score
89
Trophy points
28
Activity points
2,046
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.


Regards, Dana.
 

BradtheRad

Super Moderator
Staff member
Joined
Apr 1, 2011
Messages
13,643
Helped
2,700
Reputation
5,396
Reaction score
2,619
Trophy points
1,393
Location
Minneapolis, Minnesota, USA
Activity points
101,880
Create a variable called CHGflag.
Set to 1 when charging. Set to 0 when idle.

To stop charging:
If V>13.7 and CHGflag=1 then CHGflag=0

To begin charging:
If V<12.7 and CHGflag=0 then CHGflag=1
 

    codemaster11

    points: 2
    Helpful Answer Positive Rating

codemaster11

Member level 5
Joined
Sep 2, 2019
Messages
84
Helped
8
Reputation
16
Reaction score
6
Trophy points
8
Activity points
765
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*/

if(vin < 12.5 && chgflag == false)

{ chgflag = true; turn on mosfet switch; /* start charging */ }

}.

/* 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.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,358
Helped
4,724
Reputation
9,463
Reaction score
4,492
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,524
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:

if(vin > 13.7) charge=off;
else charge = on.

otherwise use:

if((vin < 13.7) && (vin > 12.5)) charge=on;
else charge=off;

Brian.
 

codemaster11

Member level 5
Joined
Sep 2, 2019
Messages
84
Helped
8
Reputation
16
Reaction score
6
Trophy points
8
Activity points
765
hysteresis gap.jpg
if we turn off the switch by using

if(vin >= 13.7) then switch = off
else

switch on.

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.
 

codemaster11

Member level 5
Joined
Sep 2, 2019
Messages
84
Helped
8
Reputation
16
Reaction score
6
Trophy points
8
Activity points
765
the problem solved using the approach suggested in post#3 by using an external " interrupt/digitalRead(digital pin)",

as according to the image shown in post #6, where lm358 with a define gap, high volt = 13.7vdc (cutoff) & low volt = 12.5vdc.

the output of lm358 is given as digital "high/low" to any digital pin of atmega328p using voltage divider

that fix digital output to 5vdc.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top