DS1302 hangs after power loss
Falcon
Posts: 191
Hello,
I'm using Chris's LCD Demo code in Slot 0 of a BS2px to create a time stamp when a sensor is triggered. The Sensor code is spread out in Slots 1 thru 5. I then use RUN statements to skip from Slot 5 back to Slot 1 skipping the initialization in Slot 0 so it only occurs at the start. I placed a copy of the Get Time subroutine in each Slot to minimize jumping back and forth among the 5 "active" Slots. I also have a battery on the DS1302 to keep the time.
The problem I'm having is that when I lose power, the DEBUGIN command waits for an input, and the remainder of the code does not execute until I press either the "1" to re-enter the Date/Time, or the "2" button to display the Date/Time . When I press "2' the time is recorded correctly so the battery back-up is working.
How can I skip the initialization of the Date/Time after a brief power outage (since it is backed-up with the battery) and have the main code execute? Do I need to add a loop and couter to skip out of the loop if the Date/Time isn't input within a certain time?
falcon
I'm using Chris's LCD Demo code in Slot 0 of a BS2px to create a time stamp when a sensor is triggered. The Sensor code is spread out in Slots 1 thru 5. I then use RUN statements to skip from Slot 5 back to Slot 1 skipping the initialization in Slot 0 so it only occurs at the start. I placed a copy of the Get Time subroutine in each Slot to minimize jumping back and forth among the 5 "active" Slots. I also have a battery on the DS1302 to keep the time.
The problem I'm having is that when I lose power, the DEBUGIN command waits for an input, and the remainder of the code does not execute until I press either the "1" to re-enter the Date/Time, or the "2" button to display the Date/Time . When I press "2' the time is recorded correctly so the battery back-up is working.
How can I skip the initialization of the Date/Time after a brief power outage (since it is backed-up with the battery) and have the main code execute? Do I need to add a loop and couter to skip out of the loop if the Date/Time isn't input within a certain time?
falcon
Comments
Actually the Trickle Charger Resistor and Diode Select register has a power on state of 5C (hex) which can be changed afterwards.
So if the program changes that register earlier and then is reset, that register will hold that value if its got battery backup and the program can check that value and continue its data collection.
Page 7 of the manual
As Mike has suggested, I use a flag to let the main program ( slot 0) know whether the clock (slot 1) has been set. If so, continue without waiting.
I've attached my programs for you to have a look at. The main program is quite long and involved, but the the Initialization section is up near the beginning. The clock program also has been modified to correct for Daylight Saving Time.
I'll have to look at the suggestions and try to work my way through that code.
I haven't used the DS1302's RAM yet so that might be a good exercise to help me learn about that.
Thank you to all,
Falcon
http://forums.parallax.com/showthread.php?133886-Six-Digits-of-Doom
Stamptrol,
I like the suggestion using the ippdump_main_final...... code that you and Mike suggested.
I have this code in Slot 0:
That code is intended to jump to Slot 6 if the clock has been recently read (which will be a no after a restart).
I put the clock initialization code into Slot 6, then jump to Slot 1 to begin the main code.
My main code is in Slots 1 thru 5. I have the "PUT" line of code at the end of each Slot's code before the RUN statement that directs it to the next Slot. See that code for Slot 1 below:
A similar statement at the end of Slot 5 jumps back to Slot 1.
However, my code is still waiting for the "Press 1, 2 or 3" on the DEBUG screen.
Question 1: Is the following code snippet necessary for my purpose? Specifically the "PUT Restart, 5" part?
Question 2: How is the clkrun variable initially set? I assume clkrun will be a 0 when the code is first run.
falcon
Glad to see you're still at it!
Qu1: The code was used to give the operator a clue that the system had restarted. Without the SEROUT, you still need the GET and PUT for proper operation.
Qu2: It is initially at 0 which lets the system immediately go and read the clock. If its not zero,(set every time clock is read) it means the system is running and ready to read the barcodes, etc. After each barcode is read, it gets set back to 0 so the clock is re-read before the next barcode is scanned.
Cheers
Stamptrol,
Won't the Clkrun variable stored in the Clk_rd (Con 105) location be lost during a power loss since it is saved in a scratchpad RAM location? If so, that would place a 0 in Clkrun every time power is lost, sending the program to the RTD initialization code in Slot 6.
falcon
On a power failure, the system will see the 0, go get current time and return. It only goes to the time set routine if the operator has signaled that he wants to set the clock.
Cheers,
A huge value of this forum is receiving help with a question, but, as in this case, I still had to work through the solution to get it to work in my application.
Thanks again to all that made suggestions.
falcon
Could you share how you solved it?