How can a PIC tell the time?

Status
Not open for further replies.

Hippogriff

Member
Tied in with a previous thread I created...

I am creating a RGB LED strip wall wash / accent lighting thingie... when it starts off I have just added a slow fade from R, G and B all being off and fading up to the first colour in the colour list that I fade between... this is cool because the light strip turns on very gradually and not abruptly.

In a perfect world, I would like this to be connected to the mains power all the time and for the user to not have to worry about physically switching it on, but for it to come on either when it is a) a certain time or - maybe - b) when the ambient light falls below a certain level. Ideally, it would automatically come at at 18:00 and automatically go off at 23:00.

Concentrating on the first one, time... this would be easy to do by putting one of those mains timer things between the plug and the socket, simple and it would work a treat. However, is there also a way of doing this via something I could plug(!) into my PIC, so it knows the time? A component? And then it knows to turn on, or it provides power to the PIC at the right time or whatever?

If it is a component that is on all the time and also my PIC is powered too, then thinking "green", this might not be the way people would recommend I go these days, as I guess the circuit is on and is consuming power 24-7, but is it possible and, assuming it is, what kind of kit would I need? Also, I wonder if this is a programming task too... would my JAL code need a tight loop to check the time and then start up when the time is reached?

A lot easier on a computer, with its inbuilt time, isn't it?
 
you could use a watch crystal in conjunction with a timer module of the PIC (usually Timer 1 or Timer 2 of the PIC) to generate an interrupt every 1 second. You could have a several registers to keep track of the minutes, hours and seconds. But the RTC will have to be initialized by a PC. Also you may have to use a battery to keep the RTC ticking even after the system has been shutdown.

Another method is to use a dedicated RTC chip, such as the DS 1305, see the data sheet https://www.electro-tech-online.com/custompdfs/2010/02/DS1305.pdf

thanks
 
Thank you. That (the DS1305) certainly looks interesting... the interrupt facility looks good... but it's rather big! Does it have a simpler, littler brother? I will have a gander around...

Would this interface easily with a PIC? I see mention of SPI (some serial interface) and wonder how simple that would be, working with something like a PIC 12F683.
 
Last edited:
Some PICs have a real time clock (RTC). I think that they are all 16 bit or more, but something like a PIC24F08KA102 is quite cheap.

You could add a GPS module which will give you the time of day without needing a user interface to set the clock.

In terms of power consumption, a PIC will use hardly any power at all when just running the 32768 Hz crystal oscillator, so the standby consumption really depends on how much power is used by your power supply when on no load.
 
Last edited:
You could add a GPS module which will give you the time of day without needing a user interface to set the clock.

That sounds like the nuts... but, without doing my research, it also sounds expensive... am I right? I will go and look anyway...

I'll also check out the PIC24F08KA102.

Thanks!
 
It depends what you call expensive.



We use **broken link removed** (without the plastic case) on the vehicle tracking equipment. You can supply them with 5 V or 3.3 V and get a 0 - 3 V serial signal. You can have one for £20 + postage if you want. PM me.

The huge advantage of a GPS is that you don't need to have anything to set the time, and you only have to turn it on occasionally to find the time. A real time clock is cheap, but you need to set it. For that, you need some way of showing the time, and adjusting it.

It is quite common to use a GPS receiver as an accurate time reference. It's probably less common to use one for a general purpose time of day clock, but as they become cheaper, there is less reason not to use them.
 
Wow, that really is cool, ..."It can provide you with superior sensitivity and performace even in urban canyon and dense foliage environments."... but how about inside the front room? ;-)

I currently have little idea about how to interface something like this with a PIC and my language of choice... JAL.

£20 (or £34) is not what I'd call expensive... but it is when compared to the rest of the gubbins I'm using, like 90p PICs... well, apart from the 5m of RGB LED strip, but I did some serious haggling on that.
 
We usually have no problem getting the GPS receivers to get a lock inside a building. The time of day is usually the first thing that they find from a cold start, and they say when the data is good.

Most, if not all, GPS receivers output the GPRS strings every second whenever they are on. **broken link removed** shows a typical GPS sentence. To read it in the PIC, you use a USART to receive individual characters, then wait for "GPRMC". Then you store the numbers that arrive, and wait for a decimal point. The last 6 numbers before the point are your time.

You can also bit-bash if you don't have a USART.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…