View previous topic :: View next topic |
Author |
Message |
ldalcol
Joined: 11 Mar 2015 Posts: 3
|
Precision timer1 in milliseconds |
Posted: Mon Sep 07, 2015 7:01 pm |
|
|
I am looking to have the accuracy of timer1 in milliseconds for PIC16F877A.
Tks. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 07, 2015 7:53 pm |
|
|
If you use a 4 MHz crystal with the 16F877A, the slowest clock that you
can use for Timer1 is 125 KHz. That gives a clock period of 8 usec.
You can't clock it at 1 ms intervals using the oscillator derived clock. |
|
![](templates/subSilver/images/spacer.gif) |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Tue Sep 08, 2015 9:34 am |
|
|
PCM programmer wrote: | If you use a 4 MHz crystal with the 16F877A, the slowest clock that you
can use for Timer1 is 125 KHz. That gives a clock period of 8 usec.
You can't clock it at 1 ms intervals using the oscillator derived clock. |
You have 2 options that come in mind:
Either use a external oscillator (slow) for timer1 clock source (if supported)
Or have a free running timer that increment a int8 then use the desired value to trigger your 1 ms timing code. (at 8 usec timer 1 firing rate, you know that int8 will overflow at about 2.04 ms)
ex (8 usec trigger rate):
Code: |
int8 count;
#int_timer1
void timer1_ISR(){
if (count > 125)
{
// code to execute at 1 ms
count =0;
}
else count++;
}
|
_________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Sep 08, 2015 11:39 am |
|
|
Quote: |
external oscillator (slow) for timer1 |
actually that is not correct.....
to get a 1 msec rollover in timer one
the MINIMUM frequency with a DIVDE by one prescalar is
65.536 Mhz ....... 32.768 mhz will yield 2msec rollover and so on
and increasing the prescalar divisor only make the problem worse.
so going lower in clock frequency is not helpful.
Higher is the only direction and the 877 won't clock that fast.
AND using INTS to do it with a timer1 register preload is sure to increase jitter ..over unfettered"rollover" |
|
![](templates/subSilver/images/spacer.gif) |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Tue Sep 08, 2015 11:43 am |
|
|
asmboy wrote: | Quote: |
external oscillator (slow) for timer1 |
actually that is not correct.....
to get a 1 msec rollover in timer one
the MINIMUM frequency with a DIVDE by one pescalar is
65.536 Mhz
and increasing the prescalar divisor only make the problem worse.
so going lower in clock frequency is not helpful.
AND using INTS to do it with a timer1 register preload is sure to increase jitter ..
over unfettered"rollover" |
I don't know this chip (that's why I wrote if supported)...
What's your take on that problem asmboy? _________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Sep 08, 2015 11:44 am |
|
|
Given a good choice of master clock - he should consider using timer2 ;-))
master clock 4.096 mhz crystal
timer 2 prescale 4 - postscale 1 -compare register 255
for precise 1 msec TMR2IF rollover
Last edited by asmboy on Tue Sep 08, 2015 4:53 pm; edited 3 times in total |
|
![](templates/subSilver/images/spacer.gif) |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Tue Sep 08, 2015 11:51 am |
|
|
asmboy wrote: | Given a good choice of master clock - he should consider using timer2 ;-)) |
Yeah but he mentioned timer 1
Let's wait for his reason to stick with timer1 at the first place ![Smile](images/smiles/icon_smile.gif) _________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Sep 08, 2015 12:00 pm |
|
|
because it says '877 - this has the arbitrary glowing aura of school /Proteus
shining back at me..... |
|
![](templates/subSilver/images/spacer.gif) |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Tue Sep 08, 2015 12:03 pm |
|
|
asmboy wrote: | because it says '877 - this has the arbitrary glowing aura of school /Proteus
shining back at me..... |
Weird, I've never touch a pic16 in my whole life (even at school, we worked on 2550)...
I feel they are outdated compared to the features pic18/dspic/pic24 have...
I started with a PIC18F2550 (launched around 2001-2002) powerful enough for many projects!
Money aside I prefer to stick with few chips but fully featured so I know them well.
Nope I don't work in manufacturing so cost per chip ain't an issue.
EDIT: i guess I'm just a fresh meat and skipped the 877 bandwagon ![Very Happy](images/smiles/icon_biggrin.gif) _________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Wed Sep 09, 2015 10:31 pm |
|
|
asmboy wrote: | because it says '877 - this has the arbitrary glowing aura of school /Proteus
shining back at me..... |
My thoughts exactly. He may as well use a hammer and chisel as these are tools of the same period. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
![](templates/subSilver/images/spacer.gif) |
|