bypass quarts crystal with microprocesser controlled frequency generator

Thread Starter

rudyauction8

Joined Jan 27, 2012
250
I would for my own personal reasons like to bypass a ~32khz quartz crystal with a transistor(s) powered by a microcontroller generating 20-40khz. I don't know how the crystal works so I'm not sure how to bypass it. Could I just hook the collector and emmitter of the transistor to where the legs of the crystal were, using a multimeter to determine the direction of the electricity and drive it with the microcontroller, or is it more complicated than that? This is a personal no-reason experiment that I have been wanting to do for a while and am finally getting around to. I'm not really worried about burning anything up, the circuit with the crystal only cost $2.50 and the microcontrollers are $1 each so if it goes up in smoke for some reason I haven't really lost anything.
 

#12

Joined Nov 30, 2010
18,224
It's usually easier than that. The instructions for the microcontroller should tell you where to connect a collector (only) as a clock input.
 

Thread Starter

rudyauction8

Joined Jan 27, 2012
250
I'm not trying to change the microcontroller's clock speed, its running on a 20mhz ceramic resonator. I want to basically use it as a quartz crystal for something that isn't designed to use anything other than what it came with (a ~32khz quartz crystal) and make it run at different speeds, instead of buying dozens of different crystals over different speed ranges and hoping one from each desired speed has the right capacitance to work. (the origional only says 32k on the side)
 

#12

Joined Nov 30, 2010
18,224
Well, if the something isn't designed to use anything but a crystal, there's your answer, it isn't designed to use anything but a crystal.
 

Thread Starter

rudyauction8

Joined Jan 27, 2012
250
The thing is, I'm not going to settle for that just yet. I know that a crystal gives out a series of pulses, and I want to simulate that using a microcontroller and a transistor. I'm just not sure what kind of circuit to use to let the pulses through, because I don't know what exactly the pulses need to "look" like for the circuit to use them. I'm hoping that it'll be simple and I can just feed a frequency signal directly into the transistor, which will replace the crystal.
 

#12

Joined Nov 30, 2010
18,224
So, you want to build a circuit that looks like a crystal to the something's crystal connections. It might be easy if you tell what the something is. Crystal oscillators are usually made with inverters, and they can be fooled...maybe. If the something is just a black box, no diagrams available, it's hard to tell which pin needs to be fooled.
 

THE_RB

Joined Feb 11, 2008
5,438
I've done similar, just connect the digital squarewave through a resistor to either of the xtal pins (xtal removed!) and one pin should be an "input" which will drive the device that previously used the xtal.

Start with a higher value resistor (say 22k) and gradually reduce that resistor value until it is working. :)
 

MrChips

Joined Oct 2, 2009
30,806
So you don't know what the signal of the crystal looks like but you still want to replace the crystal with a transistor? hmm.

Take a CMOS 555 timer circuit and replace the crystal.
The question is which pin is the input?
 

MaxHeadRoom

Joined Jul 18, 2013
28,686
As you may know, the reason for the 32.768Khz is the fact that 32,768 is a power of 2 and is represented by 15 bits.

So typically in the case of a Microprocessor, this is input into a 16 bit timer such as T1 on the Picmicro, the timer takes one second to rollover.
You can either use divisions of the count by pre-loading the timer or change the crystal to some thing more ideal to your application.
Max.
 

ScottWang

Joined Aug 23, 2012
7,400
If you want to simulating the waveform more like 32768Hz, then you should using DAC and the frequency of uC must be more higher and maybe your uC can't reach that high.

If you just want to simulating the pulse, that's more easier, it may generate around 20khz~40Khz, but you can't get a precisely frequency, you just output high and low as following to do the test, you may using the language to match your uC:

========Exp1=======
start:
....mov p1,00h ;send low to port 1
....mov p1,01h ;send high to port 1
....jmp start
....end
========Exp2=======
start:
....mov p1,01h
....mov p1,01h
....mov p1,00h
....mov p1,00h
....jmp start
....end
========Exp3=======
start:
....mov p1,01h
....mov p1,01h
....mov p1,01h
....mov p1,00h
....mov p1,00h
....jmp start
....end
========Exp4=======
start:
....mov p1,01h
....mov p1,01h
....mov p1,01h
....mov p1,00h
....mov p1,00h
....mov p1,00h
....jmp start
....end

Then you can using a bjt to drive the signal from uC.
 

Thread Starter

rudyauction8

Joined Jan 27, 2012
250
If you want to simulating the waveform more like 32768Hz, then you should using DAC and the frequency of uC must be more higher and maybe your uC can't reach that high.

If you just want to simulating the pulse, that's more easier, it may generate around 20khz~40Khz, but you can't get a precisely frequency, you just output high and low as following to do the test, you may using the language to match your uC:

========Exp1=======
start:
....mov p1,00h ;send low to port 1
....mov p1,01h ;send high to port 1
....jmp start
....end
========Exp2=======
start:
....mov p1,01h
....mov p1,01h
....mov p1,00h
....mov p1,00h
....jmp start
....end
========Exp3=======
start:
....mov p1,01h
....mov p1,01h
....mov p1,01h
....mov p1,00h
....mov p1,00h
....jmp start
....end
========Exp4=======
start:
....mov p1,01h
....mov p1,01h
....mov p1,01h
....mov p1,00h
....mov p1,00h
....mov p1,00h
....jmp start
....end

Then you can using a bjt to drive the signal from uC.
Exactly what I was looking for, I'll start testing tonight or tomorrow. Thanks. I'm thinking I can also add a 10uS pause between high and low commands (using basic language) and change the microcontroller's clock speed to change the actual frequency output until I get a result, as I have many crystals between 4 and 27mhz.
 

Thread Starter

rudyauction8

Joined Jan 27, 2012
250
Well it was simpler than I thought. I powered the microcontroller and circuit with crystal from the same power source and hooked the pulse output directly to both the input and output by 10Kohm resistors. I now have my first test circuit running 3x its normal speed. The microcontroller is a pic12f617 overclocked to 24mhz to allow for higher frequencies, the code is:

Rich (BB code):
do
high gpio.2
pauseus 20
low gpio.2
pauseus 20
loop
the compiler is set for 4mhz so the it takes a 6 uS pause in code to get a 1 uS pause in real life, that allows for more precise control of the output frequency. Any faster than what I have here and the circuit won't recognize the pulses.
 

ScottWang

Joined Aug 23, 2012
7,400
Did you measure the fastest frequency of output pulse? (output one high and one low instruction)
Could you attach the circuit?
 

Thread Starter

rudyauction8

Joined Jan 27, 2012
250
I have no way of measuring frequency, other than seeing that the circuit is running 3x normal speed. I'll build a circuit diagram and anyone with an oscilloscope can build it and measure the output frequency. I know that with a 3.3uS real life pause (20uS pause in code timed to 4mhz) and microcontroller running at 24mhz it is around 2.5-3 times the stock crystal speed, which was 32.768khz.
 

Thread Starter

rudyauction8

Joined Jan 27, 2012
250
So I should be able to get near 2x that, or ~300khz with my setup. I should only need about 130khz. I'm working on a diagram now, I have a limited program and am not very good at building schematics so some components may be mis-labled and it'll probably be somewhat messy.
 

ScottWang

Joined Aug 23, 2012
7,400
Your code looks like picBasic if it's true, then the frequency can't be x2, because the asm code is fastest way, and then the c and the basic is the lowest one, so your frequency could be down a little.

The frequency is a little higher up to 153Khz, the following infos are the frequency and time that I measured it about 4 years ago with a 500Mhz frequency counter, uC-AT89S92/11.0952 Mhz/asm code.

;test pulse out from P1
;send 1 LO and 1 Hi -- output frequency 153.765 Khz 6.5034 uS
;send 2 Lo and 2 Hi -- output frequency 92.259 khz 10.839 uS
;send 3 Lo and 3 Hi -- output frequency 65.899 khz 15.177 uS
;send 4 Lo and 4 Hi -- output frequency 51.254 khz 19.511 uS
;send 5 Lo and 5 Hi -- output frequency 41.936 khz 23.846 uS

;send 6 Lo and 5 Hi -- output frequency 35,485 khz 28.181 uS
;send 7 Lo and 5 Hi -- output frequency 30.753 khz 32.517 uS
;send 8 Lo and 5 Hi -- output frequency 27.135 khz 36.853 uS
;send 9 Lo and 5 Hi -- output frequency 24.279 khz 41.188 uS
;send 10 Lo and 5 Hi -- output frequency 21.966 khz 45.525 uS

;send 11 Lo and 5 Hi -- output frequency 20.056 khz 49.860 uS
;send 12 Lo and 5 Hi -- output frequency 18.452 khz 54.195 uS
;send 13 Lo and 5 Hi -- output frequency 17.085 khz 58.531 uS
;send 14 Lo and 5 Hi -- output frequency 15.907 khz 62.865 uS
;send 15 Lo and 5 Hi -- output frequency 14.880 khz 67.204 uS

;send 16 Lo and 5 Hi -- output frequency 13.979 khz 71.536 uS
;send 17 Lo and 5 Hi -- output frequency 13.179 khz 75.878 uS

;send 18 Lo and 5 Hi -- output frequency 18.452 khz
;send 19 Lo and 5 Hi -- output frequency 18.452 khz
;send 20 Lo and 5 Hi -- output frequency 18.452 khz

;send 21 Lo and 5 Hi -- output frequency 18.452 khz
;send 22 Lo and 5 Hi -- output frequency 18.452 khz
;send 23 Lo and 5 Hi -- output frequency 18.452 khz
;send 24 Lo and 5 Hi -- output frequency 18.452 khz
;send 25 Lo and 5 Hi -- output frequency 18.452 khz

;send 26 Lo and 5 Hi -- output frequency 18.452 khz

And how is the crystal circuit, are you trying to input the 32.768Khz from GP2?
You can decreasing the 10K resistor to 2.2K~4.7K .
 
Last edited:

Thread Starter

rudyauction8

Joined Jan 27, 2012
250
I'll try reducing the values of the resistors, but I'm worried about overloading the circuit if I reduce them to much. I'll try 4.7k now.
 
Top