greenleaf
Well-known member
As an update to the above issue I reported, the main problem turns out to be not in the interrupt interval. Rather, the bug is in the condition that activates when the start and end times of the DelayTimer are set such that they straddle across midnight (e.g. 11pm to 1am). When the times straddle across midnight, the charging will not stop at the specified time.greenleaf said:I received the OpenEVSE built by Glenn last Friday. He did a very good job.
I have a question regarding the DelayTimer.
This morning, I tested out the "delay charge" timer. I had set it to start at 22:00 and end at 06:00. At 6:30, I woke up to find the car still charging. I thought the OpenEVSE should have cut the charging at 6:00.
Existing Code
I looked at the code for DelayTimer::CheckTime(). The condition to stop charging is when (m_CurrTimeSeconds == m_StopTimerSeconds) is true.
Now, the definition of m_StopTimerSeconds and m_CurrTimeSeconds are
uint16_t m_StopTimerSeconds = m_StopTimerHour * 360 + m_StopTimerMin * 6;
uint16_t m_CurrTimeSeconds = m_CurrHour * 360 + m_CurrMin * 6;
Also, CheckTime() is set to execute by a timer interrupt every minute.
What I think happened
Because the condition to stop charging is checked by a timer interrupt, it is possible that the checking is missed at 6:00. For example, the two consecutive checks this morning could have been at 5:59:59 and 6:01:00. This misses 6:00.
What can be done?
If the above is true, then we can either
a) reduce the timer interrupt interval, say to every 55 seconds, or
b) change the check condition to
(m_CurrTimeSeconds == m_StopTimerSeconds) || (m_CurrTimeSeconds == m_StopTimerSeconds+6)
Another comment
It seems like the factor of 6 in m_CurrTimeSeconds is not needed since the seconds are never tracked. So the code could have been the following instead
uint16_t m_StopTimerMinutes = m_StopTimerHour * 60 + m_StopTimerMin;
uint16_t m_CurrTimeMinutes = m_CurrHour * 60 + m_CurrMin;
Any comments?