Hi all
A member of this forum kindly wrote this code for me and now I need to test it. The original thread is here https://forum.allaboutcircuits.com/showthread.php?p=368578#post368578 and I consider it complete.
However it does not entirely function as I originally intended. I need to make sure I understand the flow of the data.
The complete code is at the end of the thread.
Originally I wanted to power the device on while holding swB and that would trigger the adc to read the voltage attached to the circuit which would be a variable power supply set to the desired low voltage and this would then be saved to EEPROM so if the device was powered on without the button held it would poll an2 for the voltage level all the time and switch off the relay when the value in EEPROM was reached.
Also as far as the switches I was going to set it up so swA incremented the timer by 5 minutes and as a result the single led would flash the corresponding number of times. and swB would be just a start button to initiate the timer function set by swA
The way I read the code it is now set up so that swA increments offtime and swB increments ontime but both seem to flash the led and I cannot see why that is necessary
swB also seems to only set a timer up to a minute and it turns off the relay however I am not sure of its purpose as the turn on codecovers activating the relay for the required time.
The way I originally intended it the psuedo code was
Is swB held while device powered on
if so do adc conversion and store result in EEPROM
if not read EEPROM for lvc setting and monitor voltage. Cutoff circuit below this value. Also read EEPROM for timer setting and led flashes and flash led to indicate timer setting.
if swA pressed increment timer by 5 minutes and flash led a number of times to represent the time interval set. Copy both timer setting and led flashes to EEPROM and save for future use next time device powered on.
if swA incremented past 6 go back to 1
if swB pressed then start 1 minute timer to allow moving device into water then start timer interval for relay afterwards
if swB held again turn device off
The way it has now been set up seems to be
Read EEPROM for flashes, time on and time off and put display results on led
If swA pressed increment flashes and use same value to increment timer and store in EEPROM then flash led corresponding number of times and debounce button
If swB pressed then setup 6 minute timer? and copy to EEPROM and then flash led again?
There seem to be a few issues as I see it
Can someone confirm, all the EEPROM locations read at the beggining seem to be the same address. How does the code differentiate between reading flashes, offtimer and on timer?
What is the purpose of the ontimer and how long is it set for?
I have built the circuit and tested it and it seems to increment the timer and flashes each time I power on and off.
If it does the adc conversion at the start of the code as it presently does then it will keep setting the current battery voltage as the low voltage cutoff point and never run the timer wont it?
I need to sort this out and also get help setting up the first low voltage cutoff setting. I have a dc power pack that outputs 8.9V so I was going to use that as the first setting point for the low voltage cutoff.
Any help with this would be appreciated.
A member of this forum kindly wrote this code for me and now I need to test it. The original thread is here https://forum.allaboutcircuits.com/showthread.php?p=368578#post368578 and I consider it complete.
However it does not entirely function as I originally intended. I need to make sure I understand the flow of the data.
The complete code is at the end of the thread.
Originally I wanted to power the device on while holding swB and that would trigger the adc to read the voltage attached to the circuit which would be a variable power supply set to the desired low voltage and this would then be saved to EEPROM so if the device was powered on without the button held it would poll an2 for the voltage level all the time and switch off the relay when the value in EEPROM was reached.
Also as far as the switches I was going to set it up so swA incremented the timer by 5 minutes and as a result the single led would flash the corresponding number of times. and swB would be just a start button to initiate the timer function set by swA
The way I read the code it is now set up so that swA increments offtime and swB increments ontime but both seem to flash the led and I cannot see why that is necessary
swB also seems to only set a timer up to a minute and it turns off the relay however I am not sure of its purpose as the turn on codecovers activating the relay for the required time.
The way I originally intended it the psuedo code was
Is swB held while device powered on
if so do adc conversion and store result in EEPROM
if not read EEPROM for lvc setting and monitor voltage. Cutoff circuit below this value. Also read EEPROM for timer setting and led flashes and flash led to indicate timer setting.
if swA pressed increment timer by 5 minutes and flash led a number of times to represent the time interval set. Copy both timer setting and led flashes to EEPROM and save for future use next time device powered on.
if swA incremented past 6 go back to 1
if swB pressed then start 1 minute timer to allow moving device into water then start timer interval for relay afterwards
if swB held again turn device off
The way it has now been set up seems to be
Read EEPROM for flashes, time on and time off and put display results on led
If swA pressed increment flashes and use same value to increment timer and store in EEPROM then flash led corresponding number of times and debounce button
If swB pressed then setup 6 minute timer? and copy to EEPROM and then flash led again?
There seem to be a few issues as I see it
Can someone confirm, all the EEPROM locations read at the beggining seem to be the same address. How does the code differentiate between reading flashes, offtimer and on timer?
What is the purpose of the ontimer and how long is it set for?
I have built the circuit and tested it and it seems to increment the timer and flashes each time I power on and off.
If it does the adc conversion at the start of the code as it presently does then it will keep setting the current battery voltage as the low voltage cutoff point and never run the timer wont it?
I need to sort this out and also get help setting up the first low voltage cutoff setting. I have a dc power pack that outputs 8.9V so I was going to use that as the first setting point for the low voltage cutoff.
Any help with this would be appreciated.
Last edited: