Edit3: As requested I'm going to be more specific about my issue, previous description is still below
A motor must not be activate more than MAX_TIME hours (20hours - consecutive or not) during a sliding time window of WINDOW_TIME hours (72hours). Every SAMPLE_TIME minutes (1minute), the software check if the motor must be ON or OFF. My idea was to create timestamp on rising/falling event of the motor state and store them in a buffer. This buffer will be evaluated every SAMPLE_TIME to check if the sum of the timestamp is not greater than MAX_TIME. Because of the sliding window, the buffer must also be updated to remove timestamp that are too old and add new ones.
I have limited memory (around 60bytes). I'm looking for somekind of algorithm that could be use to handle this problem (with an embedded approach if possible, at least for the memory footprint)
According to comments I should:
- reduce the SAMPLE_TIME period to reduce the memory footprint of my buffers. If I evaluate the state of the motor every 10 minutes which is the maximum time for my application, I still have (72*60)/10 = 432 data to store if it's the worst case scenario and the motor is toggled ON and OFF every 10 minutes. It can be stored as bits (ON or OFF), so that's 54 bytes. Problem with this solution is that when the software check if the motor is ON, it might be the case, even if the last 9minutes it was OFF, and this will still count as 10minutes of motor activation
Previous description:
I have an embedded software project where I need to check if a motor was not activated too often during a time window. Every minute the program acquire data that tells if the motor must or must not be activated. During a 72hours time window, the motor should not be activated more than 20hours in total (it doesn't need to be 20hours consecutive), that's why I need to get a warning when this happens.
I'm using a microcontroler from Renesas (RL78) and I don't have any OS.
Since I have limited ressources and the time window is huge, I though of using somekind of timestamp. When the system activate the motor a timestamp is saved, and it's deactivated another timestamp is saved and it goes on. Once i reached the first 72 hours i can compute how long the motor was activated thanks to the multiple timestamps. The timestamps are erased when there are out of the window (since it's 'moving').
I guess there is something easier but I don't know where to start.
Edit1: I need to check if the 20hours period is reached within the 72hours, and if it's the case, set a flag.
Edit2: I have a really limited RAM size, around 60bytes available