View previous topic :: View next topic |
Author |
Message |
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Sat Dec 18, 2010 12:55 am |
|
|
You don't have any delays in any interrupt handlers? _________________ Andrew |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Sat Dec 18, 2010 8:55 am |
|
|
Not in the code I just posted. The only delay was in Main.
My real code has some delays in timer2 int, but I can probably get rid of those. The delay in main will be hard to get rid of, I plan on taking sensor readings as close to exactly once a second as possible so I use a delay to tune the timing. Does it make sense that delay messes up the timer? I thought it counted clock cycles and kept counting no matter else was going on.
Ringo _________________ Ringo Davis |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Sun Dec 19, 2010 12:31 am |
|
|
The timer will keep counting, but if your delays are long enough to miss two interrupts, the second interrupt will not be counted. This is the time between interrupts, or in your case, a little over 13ms.
If interrupts are disabled for longer than that (which applies inside interrupt handlers), then you will lose time. Delays in your mainline are OK, so long as you haven't disabled interrupts at the same time you're doing the delay. _________________ Andrew |
|
|
ünloco
Joined: 02 Oct 2011 Posts: 12 Location: Tunisia
|
|
Posted: Thu Nov 17, 2011 11:30 am |
|
|
Should days and months be reset to 1 rather than 0 ?? :p
Thanks a lot for the code ) _________________ for(;;); |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Nov 17, 2011 6:41 pm |
|
|
Yes, days and months should start at 1. Nice find!
A shame no one else noticed this bug in the last 5 years.
I'll edit the posted code. |
|
|
salanki
Joined: 28 Apr 2012 Posts: 2 Location: New York, NY
|
Other interrupts |
Posted: Sat Apr 28, 2012 11:26 am |
|
|
How is this affected by other interrupts? Say I have an RS232 interrupt that executes fairly frequently. Would the timer interrupt still be executed timely? I would want to increase the granularity of this timer to 1/10 of a milisecond. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Apr 28, 2012 3:43 pm |
|
|
The special feature of this algorithm is that it is accurate over a long period of time, unaffected by other interrupts happening in between. A second feature is that you can use whatever crystal frequency you want, i.e. it doesn't have to be an exact multiple of the clock dividers avoiding the 'funny' clock frequencies like 32768Hz.
A disadvantage is that for short periods of time it is possible the clock is reporting the time a little bit too late. So the moment the clock says a new second is started may be a little off but the total number of seconds will be correct in the long term. This means you can not use the timer as an accurate timing source for starting a precisely timed action if that is what you intend to do.
I'm not sure what you want to do with the 0.1ms timer but it sounds wrong for this algorithm. If one of your other interrupts would ever take more than 0.1ms, then your clock would be missing a tick and would run behind.
For accurate timing in the 0.1ms range I would recommend to use one of the hardware timers directly. Just make sure the RS232 interrupt is never going to take more than 0.1ms. If that can't be guaranteed you could use a PIC18 processor which has the feature of High Priority interrupts that can be used to interrupt a lower level interrupt like your RS232.
I hope this answers your question? |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
Awesome! |
Posted: Sat Jul 14, 2012 3:39 pm |
|
|
I just used your Timer ISR for my program... but im driving it from TMR1 internal 32.768 Osc...
i gotta say, beautiful work man... i got this running in less than 2 minutes....
you just saved me some cash on RTC chips...
THANK YOU! and great work!
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
tnt.vlad
Joined: 28 May 2012 Posts: 1
|
thx for the code |
Posted: Wed Aug 21, 2013 1:52 pm |
|
|
nice code! works perfectly!
tested with 16f628a, at the beginning i tried with internal osc at 4MHz, but the error was too big, like 1 second/min with one chip, 0.5 sec/min with another 2.5 sec/min.....but with an external osc at 20MHz it is simply perfect
thank you |
|
|
mr.njt
Joined: 30 Oct 2013 Posts: 4
|
|
Posted: Fri Nov 08, 2013 2:43 am |
|
|
I used that codes in my pic24fj256ga006 based project. I am simulating the circuit on Proteus VSM.
Proteus says :
-[PIC24] Invalid word adress range 0x0002ABF8-0002ABFF in program data.
-Disassembly requested for an invalid number of bytes.
Does someone know how i can solve that problem?
Thx. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Nov 08, 2013 4:18 am |
|
|
Simple. Don't use Proteus.
Read the comments about ISIS/Proteus on this forum.
Mike |
|
|
yzq707
Joined: 04 Jul 2014 Posts: 1
|
|
Posted: Fri Jul 04, 2014 9:22 pm |
|
|
i am looking for CCS C code example |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Jul 05, 2014 3:43 pm |
|
|
CCS code is provided in this thread.
Mike |
|
|
|