View previous topic :: View next topic |
Author |
Message |
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
Question for problem solvers #2 |
Posted: Thu Dec 19, 2019 12:59 am |
|
|
Hi all.
I know this is not the right place to ask.. but please bare with me.
I am building a device that sprays perfume during the day in predefined intervals and hours.
For example:
Prog1: 08:00 - 14:00
Prog2: 17:00 - 20:00
Prog3: 21:00 - 22:00
I convert all starting and ending times to seconds (Hour*3600+Minute*60) so the above is:
Prog1: 28800 - 50400
Prog2: 61200- 72000
Prog3: 75600- 79200
Now the problem is that I have to make a sanity check if the programs overlap (common spray times). For example:
Prog1: 08:00 - 14:00
Prog2: 09:00 - 20:00
or
Prog1: 08:00 - 14:00
Prog2: 07:00 - 15:00
I have totally burned my mind trying to figure this out...so any help appreciated _________________ George. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 19, 2019 3:33 am |
|
|
Use Google to search for this:
Quote: | site:stackexchange.com how to tell if two time ranges overlap
|
Use that site for all non-CCS code related questions.
The answer will likely be in their archives. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Thu Dec 19, 2019 4:33 am |
|
|
Thanks for the stackexchange tip. _________________ George. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu Dec 19, 2019 6:12 am |
|
|
Just a comment on the 'times controller' ...
Converting times into seconds will need 32 bit variables and maths ( 86400 seconds in a day).
If you can afford to use '1/4 hour times' (8:00,8:15,8:30,9:00 ) then on/off times can be stored in a byte, actually 7 bits. The 8th bit can be used as a 'flag' to control an operation, like 'pulse the perfume valve'.
I've used this method for 30+ years for remote control HVAC systems. Back then we didn't have PICs,memory was costly and really no need for 'second by second' control.
If the project is a 'one-off' or 'home use' you can afford a bigger PIC, but if it's a commercial product where the smallest (cheapest) PIC has to be used, then using my method greatly reduces memory requirements AND speeds up the main() program loop.
Jay |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
|
|
|