View Single Post
Old 08-07-2018, 02:07 PM
Matthew Jones's Avatar
Matthew Jones Matthew Jones is offline
Platinum Member
Join Date: Dec 2007
Posts: 2,738
I would think you could use a "WHILE" loop. I don't think it would end up being complicated.

I would put the reading of the battery into a function "ReadBat1", "ReadBat2"

Then Where both IF/Else statement I would drop into a "WHILE" loop with no parameter "WHILE (0);. Do a voltage read test. If it fails it would drop out reset the switch's to the other direction and go into the next While loop testing until it fails.

So the test can be inside the while loop, if Bat is discharging to Bat2

If ReadBat1 == 12v and ReadBat2 is greater than ReadBat1 Exit loop

So making sure Bat2 is greater than bat1 Would guarantee a good switch and vice versa for the other direction.
Then you could also have fail safe for the voltage levels, you mention that in your code. You could also have a minimum time to run like 1 minute no matter what.

I think the problem now is as they get low there readings switch each other so quick it just turns into a loop. There is no minimum time or not enough.

I hope I am thinking right, its easier when its set up in front of you.

ADD BROMIKEY TO YOUR IGNORE LIST He is a saboteur bent on the systematic distraction of every good topic on this forum and since he has been here most working threads have shut down. He is the enemy. If you have blocked him already add this to your signature and encourage others to block him as well. His onslaught of rambling in large text and his constant attempts to misinform at the excuse of being stupid should no longer be tolerated.

USER CP/Ignore list.
Reply With Quote