Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 19, 2024, 01:20:43 01:20


Login with username, password and session length


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

Posts: 113

Thank You
-Given: 53
-Receive: 390


« on: August 02, 2013, 02:50:23 14: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
Active Member
***
 Muted
Offline Offline

Posts: 113

Thank You
-Given: 53
-Receive: 390


« Reply #1 on: August 02, 2013, 03:56:22 15: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, 04:51:44 16:51 by bbarney » Logged
solutions
Hero Member
*****
Offline Offline

Posts: 1823

Thank You
-Given: 655
-Receive: 900



« Reply #2 on: August 02, 2013, 04:12:30 16:12 »

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

Posts: 2430

Thank You
-Given: 405
-Receive: 545


Uhm? where did pickit put my mute button


« Reply #3 on: August 02, 2013, 04:53:23 16: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
Active Member
***
 Muted
Offline Offline

Posts: 113

Thank You
-Given: 53
-Receive: 390


« Reply #4 on: August 03, 2013, 04:29:43 04: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
**
Offline Offline

Posts: 89

Thank You
-Given: 101
-Receive: 26


« Reply #5 on: August 03, 2013, 01:35:08 13: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: 2430

Thank You
-Given: 405
-Receive: 545


Uhm? where did pickit put my mute button


« Reply #6 on: August 03, 2013, 06:10:26 18: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: 704

Thank You
-Given: 151
-Receive: 214


« Reply #7 on: August 03, 2013, 07:03:16 19: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: 168

Thank You
-Given: 62
-Receive: 37


« Reply #8 on: August 03, 2013, 11:23:28 23: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: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #9 on: August 03, 2013, 11:34:20 23: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
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #10 on: August 04, 2013, 03:27:27 03: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: 168

Thank You
-Given: 62
-Receive: 37


« Reply #11 on: August 04, 2013, 06:50:41 06: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: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #12 on: August 04, 2013, 01:45:40 13: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
Mentor
Newbie
*
Offline Offline

Posts: 20

Thank You
-Given: 61
-Receive: 3



« Reply #13 on: August 04, 2013, 04:00:39 16: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: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #14 on: August 04, 2013, 06:10:57 18: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
Active Member
***
Offline Offline

Posts: 129

Thank You
-Given: 123
-Receive: 100


« Reply #15 on: August 04, 2013, 07:10:09 19: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: 168

Thank You
-Given: 62
-Receive: 37


« Reply #16 on: August 04, 2013, 08:07:08 20: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: 4647

Thank You
-Given: 826
-Receive: 4207


There is no evidence that I muted SoNsIvRi


« Reply #17 on: August 04, 2013, 08:32:18 20:32 »

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

Note: I stoped Muteing bad members OK I now put thier account in sleep mode
LabVIEWguru
Senior Member
****
Offline Offline

Posts: 300

Thank You
-Given: 270
-Receive: 593



« Reply #18 on: August 04, 2013, 09:33:25 21: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: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #19 on: August 04, 2013, 11:27:28 23: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: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #20 on: August 05, 2013, 02:21:44 02: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
h0nk
Senior Member
****
Offline Offline

Posts: 256

Thank You
-Given: 208
-Receive: 230



« Reply #21 on: August 05, 2013, 05:07:16 05: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: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


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

wow, in a year this will drift nearly an hour..!
Logged
max
Senior Member
****
Offline Offline

Posts: 314

Thank You
-Given: 1598
-Receive: 52


« Reply #23 on: August 05, 2013, 09:47:30 21: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, 09:56:26 21:56 by max » Logged

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

Posts: 113

Thank You
-Given: 53
-Receive: 390


« Reply #24 on: August 09, 2013, 06:42:23 06: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