|
|
View previous topic :: View next topic |
Author |
Message |
Blob
Joined: 02 Jan 2006 Posts: 75 Location: Neeroeteren, Limburg, Belgium
|
RTC with events |
Posted: Wed Sep 11, 2013 8:00 am |
|
|
Hello All,
I am planning to build a little control unit based on the RTC by ckielstra.
http://www.ccsinfo.com/forum/viewtopic.php?p=59789
I want to control the lights on my shrimp tank.
In memory I will define data blocks with this format:
Months F 1-12
Days F 1-7
Hours FF 0-23
Minutes FF 0-59
Seconds FF 0-59
Instruction FF
Instruction option FF
So in total
F F FF FF FF FF FF
12 bytes / data string
I will then define some instructions, for example:
Feb 01 06:30 main light 0% => start sunrise
Feb 01 08:00 main light 80% => end sunrise
Feb 01 12:00 main light 100% => noon
Feb 01 14:00 main light 100% => start afternoon
Feb 01 18:00 main light 75% => start evening
Feb 01 20:00 secondary light 0% => start moon rise
Feb 01 21:00 main light 0% => start night
Feb 01 22:00 secondary light 100% => full moon
Feb 02 03:30 secondary light 100% => start moon fall
Feb 02 05:00 secondary light 0% => end moon fall
Other instructions may be cloud simulator/ lightnings/ rain (engage extra pump) etc.
With this module it will be possible to simulate the seasons etc.
I plan to define this data chronologically sorted in memory.
Than have a "pointer" pointing to the first instruction set, retrieving date and instruction
check the date with the actual time
if actual time lies between this and next data entry => do instructions
(fe calculate dimming proportion etc)
if not => go to next data entry and check again.
When the year has passed, the pointer will return to the beginning of the stack.
I have some 18F2620 here,
If there are not to many instructions, I will have enough memory to store them.
Maybe I won't need the seconds, so that will decrease memory usage.
Does this setup makes sense?
Or is there an easier way to determine time controlled events?
Thanks in advance,
Blob |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Wed Sep 11, 2013 6:27 pm |
|
|
One idea,which I've used for 20+ years, is to take the day (24hrs) and split into 15 minute intervals. 24 hrs *4, 15minute periods=96, which easily fits into a single byte, thus saving a lot of memory. If you only require 1/2hr 'units', then 6 bits of a byte will contain the 'time' element, giving you 2 bits for 'light intensity'control bits.00=off, 01=75%, 10=80%, 11=100%. Now a single byte contains both the 'time' AND 'light' variables.
You'll have to cut code to 'encode' and 'decode' the 'time/light' byte but that's rather simple and well worth the effort considering all the memory you'll save.
If you require more 'control bits', simply use another byte for another 8 'features'.
hth
jay |
|
|
Blob
Joined: 02 Jan 2006 Posts: 75 Location: Neeroeteren, Limburg, Belgium
|
|
Posted: Thu Sep 12, 2013 1:09 am |
|
|
Hello,
Following temtronics idea, I am thinking to count minutes
24*60/day = 1440
1440/day*365 = 525600/year.
this takes only 5 bytes
if I take 3 bytes for the instruction and options this will make 8 bytes / block
I think I can live with that. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Sep 12, 2013 3:01 am |
|
|
Blob wrote: | 24*60/day = 1440
1440/day*365 = 525600/year.
this takes only 5 bytes | Wrong, it fits in 20 bits --> 2.5 bytes.
In your example day schedule you defined 10 switching moments, assume you want to control waterpump and some other devices as well then a minimum of 25 switching moments per day.
366 days in a year (leap year).
366 days * 25 switching moments = 9125 data entries.
The PIC18F2620 has 64kbyte of Flash memory. Be on the save side and assume 50kbyte is available for the data table. Then you have 50 kbyte / 9125 data entries = 5 bytes per entry (rounded down to whole bytes).
Take 3 bytes for the date/time and 2 bytes for the commands. You have 4 bits left in the date/time for future extensions. |
|
|
Blob
Joined: 02 Jan 2006 Posts: 75 Location: Neeroeteren, Limburg, Belgium
|
|
Posted: Thu Sep 12, 2013 3:57 am |
|
|
awch,
painful mistake...
FF = 1 byte
F = 1 nibble
I see I made the same mistake in my first post |
|
|
Blob
Joined: 02 Jan 2006 Posts: 75 Location: Neeroeteren, Limburg, Belgium
|
|
Posted: Thu Sep 19, 2013 7:11 am |
|
|
Works as a charm, thanks guys!
I found the rise and set times of the sun and the moon of my location of interest at www.timeanddate.com
the site also provides info about solar noon and distance of the sun/moon and phase of the moon etc.
I made some calculations on it to simulate sun strength in summer/winter and strength of the moon light.
I putted all data chronological and converted it to my "data package" format
Only with the sun and moon simulation, I now have 2895 entries.
so, enough space to make rain - lightning - temperature extensions... working on that
sun and moon brightness is controlled with the PWM outputs of my pic18f2620
sun and moon rise and set nicely.
I hope the shrimps will like it too...
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|