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.

Frequency divider with PIC and quartz oscillator

Status
Not open for further replies.

stefangs

New Member
Hello! I'm trying to build a simple frequency divider that involves a PIC and a quartz oscillator. It is not my domain so i kinda need some help in choosing and programming the pic. The ideea is that i should get a random frequency from the quartz oscillator (it is a didactic project so the division and the main freq doesnt need to have a certain value) and that freq to be divided by the pic and displayed on to a LCD or a oscilloscope. I would appreciate if you guys can help me with a schematic and a source code for the pic. As I said , im not that good at these things. Thanx!
 
What frequency crystal?

What is the range of frequencies you would like to get at the output?

Do you really want a puesdo-random frequency, or do you want to set the frequency with a knob or switches?
 
I'll make myself more specific but because I don't know many thinks about this kind of project it may not be enough for you. Let's say I have a 800 Hz freq from the quartz oscillator. The PIC i have to use must divide this freq by lets say 8 times, so i can get on the LCD ( yes, its a part of the pic circuit) or if i dont have an LCD , on the oscilloscope the same signal but with a 100 Hz frequency (divided by 8).

The pic it's supposed to be programmed and implemented on the circuit, not to be programmed in real time. So i would have the same division every time.
 
First, the lowest frequency crystal that is commonly available is 32.768 KHz, called a "Watch crystal". Many PICs can use this as the primary clock, and can easily divide this frequency by an integer factor, or a factor which can be expressed as a ratio of two integers. If you use a much higher crystal frequency, say 8.000MHz, then the division factor can be much larger, and then the divided frequency can be controlled to a much higher resolution (smaller frequency steps).

The PIC can even count the divided frequency and display it on an LCD.
 
If you juts want a "divide by 8" circuit, you can do it with a 4017 IC, setup to reset at 8 pulses, and take the output signal from one of it's output pins.

The 4017 can easily be used for /2 /3 /4 /5 /6 /7 /8 /9 and /10 and is a cheap common IC.
 
Is it frequency divider code with a quartz crystal driven PIC we are talking abt? Where the frequency to be divided can come from any available source?

Or is the PIC being fed a frequency from a crystal which it has to divide and output?

Is the division an integer or a fp?
 
RE Mosaic

Yes, the PIC must take the freq from the crystal. I had to made a comparativ study between a JK flip flop freq devider and a PIC programmed freq divider. I made the flip flop one, but i dont know many thing about pogramming PIC, but someone said to me i just need a crystal and a pic, my problem is to programm that pic and to choose it, i dont think all pic's can divide frequencys. The ideea looks simple, i just need to program that pic to divide my freq by 8 times. I see ur asking about the crystals freq..it can be any crystal with any freq..i can modify the code if u guys have one for a certain freq.
 
How did u feed the freq. signal to the flip flop?

PICs have both analog and dig inputs to make reading a freq easy. Plus can be interrupt driven by external signals for time critical response .
I recently did a tachometer using the T0CK input and derived the rpm from the number of T0CK counts sampled over a fixed int. clked time period.
If all u want to do is input a dig. signal and div by 8, I'd do it via the interrupt routine....which counts to 8 before outputting a pulse on the IO pin you will be measuring. The PIC can alter the duty cycle of the output pulse as well if u wish.

The crystal is often used by a PIC to run its clock. However it's not required as most modern PICs have internal clocks. Interestingly, you can actually have the PIC run off it's internal clock, say 4Mhz, and generate a 1Khz PWM output from its internal hardware, then sample this freq. via another PIC input PIN to divide by 8 and then output the result on a 3rd pin. So the PIC does both the signal generation and input & divide by 8 function for your project. No Xtal necessary.
 
Last edited:
... So the PIC does both the signal generation and input & divide by 8 function for your project. No Xtal necessary.

Yeah, but... have you ever looked at the tolerance on the internal non-crystal clock? +-1% is about as good as they get. Hardly equivalent to a crystal oscillator.
 
Uart only needs 4% but there are pic that have better internal osc

Maybe if your a ham you may get wrote up for being off by 1%
 
I use a PIC chip to produce DTMF so the int oscillator is perfectly suited for this close-tolerance requirement.
 
I use a PIC chip to produce DTMF so the int oscillator is perfectly suited for this close-tolerance requirement.

Well, since I am old enough to remember telephones (and I still have some) with L-C oscillators to make DTMF tones, obviously the central-office DTMF tone-decoders are not very fussy. In fact, +-1.5% is still a valid tone, and +-3.5% is not. Doesn't particularly recommend the internal osc inside the PIC.
 

Attachments

  • DTMF.png
    DTMF.png
    11.9 KB · Views: 326
Last edited:
Special Microcontroller Features: • Precision Internal Oscillator: - Factory calibrated
to ±1%, typical
 
Special Microcontroller Features: • Precision Internal Oscillator: - Factory calibrated
to ±1%, typical

Ok, how satisfied would you be with an alarm clock that was based on an oscillator with a +-1% tolerance?
 
It ain't a cesium clock he's trying to build . It's a little project.
 
Last edited:
Ok

let's make it simple :

each leading edge of the input signal creates an INT interrupt ...
you then increment a 8 bit variable
you write the value directly to a Pic Port, if 18 pins, and take output on port.2 ... for 1/8 ratio
or shift value right 3 times and output value.0 bit on your choosen port, if 6 or 8 pins

that's all ... and a 10F200 will do it ...

Pic Osc speed ??? ... no matter for the range you mentionned ! just use the internal default 4 Mhz ...

Alain
 
But, is it really that simple?

PIC oscillator speed probably does make a difference depending on the target crystal frequency. ISR 'overhead' could prevent accurate counter operation but you may be on the right track.

How about feeding the crystal signal into Timer 0 via the T0CKI pin with Timer 0 set up in asynchronous counter mode with 1:1 prescaler. Then copy bit 2 of the TMR0 register onto an output pin (from within a very tight loop)? No, that won't work either. PIC oscillator frequency would still be the limiting factor for crystal frequency...
 
Last edited:
Hi, Mike ...

for Overhead ... have a look to post #3 ...

Pic Osc won't be a limitation for these sloooooooowwwwwww frequencies ...

let's talk about 20µS (! ...) for such an interrupt - LOL ! - ... 50 Khz is far,far,far .... away from what asked for ...

so, it's really that simple HERE ... I do not forget it only matches THIS particular application and not the " general way of doing it " ...

Alain

PS: France : 1 point ; We're equal for " KISS " method , with this one...

Propagation time ??? this probably is the goal of the exercise ... so, shhhhht !!! do not talk about it !
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top