Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How can you tell in which frequency your PIC is running?

Status
Not open for further replies.

electroRF

Member
Hi,

I've set my PIC to use internal clock at 8MHz.

How can I verify it is running at 8MHz?

Can it be done without additional HW as Scope?

I got Pickit3.

Thanks.
 
Hi,

Well there are a couple of ways. For one you can set up the PIC to output a square wave with a very small program and check the frequency of the square wave. Knowing the instruction time should be 1/4 of the set frequency you can determine if it is really running at 8MHz using a frequency counter.

If you dont have a frequency counter, you either have to get one or build one with another PIC chip.
You can build one and then check it with a crystal oscillator divided down using TTL counters. Once you get it working, you can check your other chips and any other chips. It's easy to build one too and it does not have to have a display (like a 7 segment display). You can loose the display by setting up a single LED to blink at a certain rate (fast) when the PIC chip gets the right frequency range, or blink slow when it does not get the right range.
So for example if your chip expects a 10kHz signal and gets 9.95kHz to 10.05kHz it blinks fast, but if it gets 9.90kHz it blinks slow. So one LED becomes your window to the world :)
You can use two LED's to detect other ranges, and more LED's if you like for more ranges. This saves you the work of having to interface to an entire display.
 
Or, you could write a short delay routine, say for 0.5 second, and time two events, such as the blink of an LED. Here's a link to a handy calculator for delays:

Of course, that won't give the precision of an oscilloscope to calibrate the PIC internal oscillator, but it will tell you whether it is operating at 8 MHz or something way different. You can easily time to 0.1 S, so a 10-second delay would allow 1% precision.

Edit: Do you have a frequency generator?

John
 
Last edited:
Hi,I've set my PIC to use internal clock at 8MHz.
How can I verify it is running at 8MHz?
Can it be done without additional HW as Scope?
I got Pickit3.Thanks.
Write a simple program to flash a LED once per second. Use the DELAY subroutine in your library to generate a 500msec delay so that the LED has a 50% duty cycle. Count flashes vs your wristwatch.

Use a short wire to the antenna terminal of a short wave receiver as a probe. Just lay the wire over the PIC's pcb. There should be strong birdies at 4, 8, 16 and 32MHz. Set the receiver up to receive CW or SSB
 
I don't know about your PIC, but I use PIC24H, and it has a register, which you can use to adjust internal clock.

I use watch crystal connected to SOSCI/SOSCO and I set up a timer to produce an interrupt every second. I also have a timer based on internal clock. I check the value of this timer every second and if it wonders away of the expected value, I adjust the internal clock accordingly. Gives me good 8MHz.

I also found that PIC's internal clock is usually more precise than specified +-2%.
 
you could do it in code i think, do 2 Nop(); set a break point at both then use the stopwatch to time it, there is an equation in the datasheet that tells you how long each instruction should take depending on the clock frequency, i hope that makes sense i dont think i have explained it very well :oops:
 
the other thing i thought of is on pic 18's you can set it so the OSC2 pin produces a square wave that is fosc/4 and some DMM's have a frequency function so use that and you should get 2Mhz output on the DMM
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top