PDA

View Full Version : Do the caps in a 4 mhz clock make a difference



Snap
- 25th April 2007, 18:35
I am trying to make a slot car timing system and I am using a 16f84a. I have already set it up to do the timing using the internal interupts but it is not 100% accurate, it is close (about 1 second per min off). I set the prescaler at 8 and load the tmro with 131 to give 1 sec on paper but it is a bit slow. I can adjust for it in the software but I was wondering if the caps I put on the external clock have anything to do with it. I wanted .22pf just as the schematics said but could not find any so I used .20pf ( I am not quite sure of the exact difference but I know I was close). Any way I was wondering if the clock depended on a R/C circuit or if the caps were only there for filtering.
Any help would be apreciated and sorry for the spelling.
Snap

skimask
- 25th April 2007, 18:45
I am trying to make a slot car timing system and I am using a 16f84a. I have already set it up to do the timing using the internal interupts but it is not 100% accurate, it is close (about 1 second per min off). I set the prescaler at 8 and load the tmro with 131 to give 1 sec on paper but it is a bit slow. I can adjust for it in the software but I was wondering if the caps I put on the external clock have anything to do with it. I wanted .22pf just as the schematics said but could not find any so I used .20pf ( I am not quite sure of the exact difference but I know I was close). Any way I was wondering if the clock depended on a R/C circuit or if the caps were only there for filtering.
Any help would be apreciated and sorry for the spelling.
Snap

You're probably losing a cycle here and there at the PIC level that you're forgetting about or not seeing or something...but yes, you might be able to 'drag' a 4Mhz cystal up to say 4.1Mhz or down to 3.9Mhz by using different load caps...but it won't be stable...in other words, it might be 4.1Mhz today, but it might be 4.05Mhz tomorrow.
Best to get the crystal locked down with the recommended cap's and dial in the timing by adding or subtract a 'leap count'/'leap second'/whatever whenever it's needed.

mister_e
- 25th April 2007, 18:48
The capacitor shouldn't affect too much, btw their tolerance is often high... so don't worry too much.

This will help if we see your actual code.

'Beer is proof that God loves us and wants us to be happy. This also make ugly people looking better ;)

Snap
- 25th April 2007, 19:05
Thank you for the help I will try and get the right caps for the crystal. I am new to electronics but can help with water problems if anyone needs them.
Snap

paul borgmeier
- 25th April 2007, 21:25
Are you counting 1000 overflows to equal 1 second?
[(256-131*8)*1000 = 1000000uS]

If so, you need to realize that TMRO has a 2 cycle delay after you write to it (see the datasheet). This would equate to [2*1000*60 = 120000uS (or .12S)] of your error (per minute). The other (part of the erro) from the fact that after you detect the overflow, TMRO is still counting ... you probably have some latency before getting to it to rewrite the 131. I bet this latency is the rest of your error (i.e., you are resetting a TMRO that has interrupted and carried on with counting when you re-write to it).

Options
1) adjust in software
2) free running TMRO - does not stop TMRO http://www.picbasic.co.uk/forum/showthread.php?t=2129

Lastly, you want XTAL caps of 15-33 pF (not 0.20pF or 0.22pF). It should not matter the value as long as you are in the ballpark – they should run your XTAL near the stated tolerance for the XTAL. I cannot image persuading the XTAL to vary by a percent or so day to day as suggested earlier in this thread – maybe I have been lucky the last 10 years, who knows.

Good Luck,

skimask
- 25th April 2007, 21:34
Lastly, you want XTAL caps of 15-33 pF (not 0.20pF or 0.22pF). It should not matter the value as long as you are in the ballpark – they should run your XTAL near the stated tolerance for the XTAL. I cannot image persuading the XTAL to vary by a percent or so day to day as suggested earlier in this thread – maybe I have been lucky the last 10 years, who knows.
Good Luck,

I was throwing out ideas earlier. I've never tried to see how far I could 'pull' a crystal or even if I could do it.
But you're definetly right about reloading the timer. A guy should add a number to the timer rather than reload it with a fixed value in a case like this.

And I think it would really help in this case to see some more code...

Snap
- 26th April 2007, 00:28
I Used the code from Dogan Ibrahims book Pic Basic programming and projects.
Project 16 I copied the code onto my laptop and do not have the time to copy the entire thing out here. The main point of my question was if the caps could effect the clock and I understand (by the answers) they can if they are way out I really apprecate all the help and will publish the code if you want it but I just wanted to understand the relationship between a clock and the 22pf caps.
Thanks again
Snap

sayzer
- 26th April 2007, 08:30
...

'Beer is proof that God loves us and wants us to be happy. This also make ugly people looking better ;)



That means, the beer is a religious drink given by God.

Therefore, it is also the proof that God exists.

To atheists, let it be provided as an evidence of God, then.

WoW!