The Godfather talking
You think I am funny guy huh?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 09, 2016, 12:30:46 12:30


Login with username, password and session length


Pages: [1]
Print
Author Topic: ON/OFF timer using PIC with simulation  (Read 3131 times)
0 Members and 1 Guest are viewing this topic.
micropcb
Junior Member
**
Offline Offline

Posts: 63

Thank You
-Given: 29
-Receive: 150


« on: August 02, 2013, 03:50:23 15:50 »

Hello everyone.

Here is an accurate ON/OFF timer using PIC16F877. The simulation is included. The times in simulation are obviously not accurate but the real hardware does a good job.

The howto file included explains how to use it.

Best regards.

--micropcb

Logged
micropcb
Junior Member
**
Offline Offline

Posts: 63

Thank You
-Given: 29
-Receive: 150


« Reply #1 on: August 02, 2013, 04:56:22 16:56 »

Hi,

I remember it was generated using CCS C . It is an old project and I am trying to find the source.

Cheers.
« Last Edit: August 02, 2013, 05:51:44 17:51 by bbarney » Logged
solutions
Hero Member
*****
Offline Offline

Posts: 1446

Thank You
-Given: 591
-Receive: 851



« Reply #2 on: August 02, 2013, 05:12:30 17:12 »

How accurate is it?
Logged
bbarney
Moderator
Hero Member
*****
Offline Offline

Posts: 2403

Thank You
-Given: 405
-Receive: 544


Uhm? where did pickit put my mute button


« Reply #3 on: August 02, 2013, 05:53:23 17:53 »

Hey Solutions
I made Reply # 2 easier for you to see so you don't report it again  Wink
Logged

Ever wonder why Kamikaze pilot's wore helmet's ?
micropcb
Junior Member
**
Offline Offline

Posts: 63

Thank You
-Given: 29
-Receive: 150


« Reply #4 on: August 03, 2013, 05:29:43 05:29 »

@Solutions,
The timer was not implemented using software loops but we had used the internal timer of the pic to get  the programmable timings generated. It was made for an application (air conditioner) in which the client was happy with even +/- 10 sec for a 10 min delay. He was more interested in having a programmable timer. However  I remember we landed up with +/- 1 sec for around 20 min. We did not improve the code further.



@bbarney
It was a fairly simple program and I am no more tied up with my then employer . Please give me a day or two and I will surely provide the source the moment I locate it.

Best regards.
Logged
gan_canny
Junior Member
**
 Warned
Offline Offline

Posts: 85

Thank You
-Given: 98
-Receive: 25


« Reply #5 on: August 03, 2013, 02:35:08 14:35 »

With PIC timers there are things to be aware of. The accuracy of the timer can't be more accurate than the PIC clock. It's best to use a Xtal but even Xtals are subject to temperature and to a drift cause by aging. The hardware timers within the PIC are for accuracy most often run of the external xtal processor clock. Some PIC timers can run of an secondary xtal such as a watch xtal (32768 hz). For very short duration timers instruction time to read the timer is relevant. The PIC has very deterministic instruction times so they can be counted and allowed for. This is specially of relevance for timer interrupts where the time to save and restore registers can be a factor effecting the frequency of measurements.
Logged
bbarney
Moderator
Hero Member
*****
Offline Offline

Posts: 2403

Thank You
-Given: 405
-Receive: 544


Uhm? where did pickit put my mute button


« Reply #6 on: August 03, 2013, 07:10:26 19:10 »

Quote
@bbarney
It was a fairly simple program and I am no more tied up with my then employer . Please give me a day or two and I will surely provide the source the moment I locate it.

Best regards
.

Not me who want's it - someone complained because it wasn't included
Logged

Ever wonder why Kamikaze pilot's wore helmet's ?
Gallymimu
Hero Member
*****
Offline Offline

Posts: 579

Thank You
-Given: 101
-Receive: 151


« Reply #7 on: August 03, 2013, 08:03:16 20:03 »

1 sec in 20 min is about 800ppm for the posted project. 

for comparison...

general use stuff:
PIC RC oscillators are usually about 1-2% or 10000 to 20000ppm
typical crystal is about 100ppm
watch crystal is about 20ppm

now the fancy stuff:
OXCO oven controlled crystal is 0.001ppm
Rubidium 0.000001ppm
Cesium 0.0000001ppm

so, no offense, but even for use of conventional crystals the accuracy of this isn't very good assuming you are using a crystal.  I'd imagine the 800ppm is due to error in the timer period calculation.

Logged
Vineyards
Active Member
***
Offline Offline

Posts: 130

Thank You
-Given: 36
-Receive: 25


« Reply #8 on: August 04, 2013, 12:23:28 00:23 »

I use RTC chips such as DS1302 or DS1307 for equipment to be left outdoors in industrial areas. When I get back to check them say 6 months later, I observe that they are fast or slow between 20 mins and sometimes upto a full hour. Unless you have a means to automatically update them you will always end up with a result like that. Invest in low ppm crystals to make it as accurate as possible. The comprimise here is between cost and practicality. You can invest in expensive gear and provide room for it in the housing as well as satisfying the increased power demand if the design necessitates it. Otherwise, you neex to be happy with what you can achieve with the run of the mill components.
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #9 on: August 04, 2013, 12:34:20 00:34 »

That's an interesting post, while reading it came to me asking about commercial products which use 32KHz crystals, then they suffer the same drifts, I wonder how they achive better accuracy then?
Logged

nothing to say..
Gallymimu
Hero Member
*****
Offline Offline

Posts: 579

Thank You
-Given: 101
-Receive: 151


« Reply #10 on: August 04, 2013, 04:27:27 04:27 »

That's an interesting post, while reading it came to me asking about commercial products which use 32KHz crystals, then they suffer the same drifts, I wonder how they achive better accuracy then?

did you have something in mind that is better without going to something really fancy?
Logged
Vineyards
Active Member
***
Offline Offline

Posts: 130

Thank You
-Given: 36
-Receive: 25


« Reply #11 on: August 04, 2013, 07:50:41 07:50 »

It is just a matter of how high accuracy is on your list of priorities. For example one of my devices has to work at high altitude and put up with drastic temperatures. The relay needs to stay open for 20 minutes once a day. What matters for me is not whether it goes on and off at exactly the designated times. 20 mins part is more important for me. So I can live with the error margin here. Commercial applications do vary significantly when it comes to time keeping accuracy.
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #12 on: August 04, 2013, 02:45:40 14:45 »

did you have something in mind that is better without going to something really fancy?
Actually no, I am not an expert in this field, may be some sort of compensation is used, I wish I knew how commercial companies implement it.
Logged

nothing to say..
Mentor
Newbie
*
Offline Offline

Posts: 20

Thank You
-Given: 58
-Receive: 3



« Reply #13 on: August 04, 2013, 05:00:39 17:00 »

I worked with some equipments that had GPS modules to keep a good timekeeping. I think that this solution is becoming cheaper every day.
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #14 on: August 04, 2013, 07:10:57 19:10 »

I had a bad experience with DS1307 left outdoor in a metal box which have some ventilation holes, the clock drift more than 1 hour a day - the problem is we have a very humid air, the board is dewy in the morning. The problem solved by coating the RTC area mainly the x'tal with several coat of clear acrylic spray paint.

Since then i switched to DS3221 with 3ppm internal x'tal, i hate it is expensive..

-ichan
Logged

There is Gray, not only Black or White.
Checksum8
V.I.P
Junior Member
*****
Offline Offline

Posts: 71

Thank You
-Given: 44
-Receive: 53


« Reply #15 on: August 04, 2013, 08:10:09 20:10 »

I have not tried this but it may be helpful.

http://www.romanblack.com/one_sec.htm
Logged
Vineyards
Active Member
***
Offline Offline

Posts: 130

Thank You
-Given: 36
-Receive: 25


« Reply #16 on: August 04, 2013, 09:07:08 21:07 »

Since then i switched to DS3221 with 3ppm internal x'tal, i hate it is expensive..

-ichan
Never tried that one.  Any differences in microcontroller communication?
Logged
pickit2
Moderator
Hero Member
*****
Offline Offline

Posts: 3816

Thank You
-Given: 567
-Receive: 2049


There is no evidence that I muted SoNsIvRi


« Reply #17 on: August 04, 2013, 09:32:18 21:32 »

why not make a crystal oven, set it over your highest temperature you expect to see.
Logged

Note: If you have no posts other than, I want or reporting a dead link Then you can't complain If I remove your post So Stop Leeching
LabVIEWguru
Senior Member
****
Offline Offline

Posts: 267

Thank You
-Given: 223
-Receive: 553



« Reply #18 on: August 04, 2013, 10:33:25 22:33 »

Well, you must be using AC so steal some AC from one leg of your transformer and use a voltage divider to get an acceptable voltage. Now your micro can count the pulses or use a divider to give you a pulse per second or per minute. Software overhead goes up but hardware overhead goes way down. Set the time in software and 1 pulse per second gives you really accurate time. Downside is if you lose power your system doesn't know what time it is, unless you use a micro in low power mode with batteries. If we suddenly lose 60 Hz we have much bigger problems than air conditioning.
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #19 on: August 05, 2013, 12:27:28 00:27 »

Any differences in microcontroller communication?

No, as i remember i did not change the code, probably the slave id is different - and sorry i mean DS3231.

-ichan
Logged

There is Gray, not only Black or White.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #20 on: August 05, 2013, 03:21:44 03:21 »

How can I use PPM value to calculate the actual change in time for a given period of time counting? I mean how can I expect the change in given time after 3 days for example?
Logged

nothing to say..
h0nk
Active Member
***
Offline Offline

Posts: 120

Thank You
-Given: 90
-Receive: 83



« Reply #21 on: August 05, 2013, 06:07:16 06:07 »


P.P.M. := Parts Per Million

3 days: 3 * 24 * 60 * 60 are 259200 sec.

259200 / 1000000 = 0.2592 sec

A crystal with 100 PPM deviation will result in an error of 25.92 sec.


Best Regards
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #22 on: August 05, 2013, 11:39:13 11:39 »

wow, in a year this will drift nearly an hour..!
Logged

nothing to say..
max
Active Member
***
Offline Offline

Posts: 223

Thank You
-Given: 603
-Receive: 32


« Reply #23 on: August 05, 2013, 10:47:30 22:47 »

we can also use the analog quartz clock watches module, which gives an accurate 1 sec reference with built in temperature compensation and the deviation is less than +/- 1 min in a year. see the attached files.
« Last Edit: August 05, 2013, 10:56:26 22:56 by max » Logged

Fate arrived and made the conscious unconscious It silenced the activity of life.
micropcb
Junior Member
**
Offline Offline

Posts: 63

Thank You
-Given: 29
-Receive: 150


« Reply #24 on: August 09, 2013, 07:42:23 07:42 »

Finally managed to locate the source. Compiled it with CCS 4.130. Since it is "as is where is"  ,may require modifications for improvement.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC