[SOLVED] How to use a 2-pin crystal for IC clock?

I need give to a IC (Ay-3-8910) a clock of 2mhz.
In a store I bought a 4mhz crystal because they didn't have a 2mhz crystal, and it has 2 pins
Now I did some research and it seems that what I have is not an oscillator, it's just a crystal and you need extra circuitry in order to get a clock signal.

Is there a way I can use my 2 pin crystal for the IC? Or do I need a 4 pin crystal oscillator?


You need to build a 4MHz oscillator, using the crystal as a stabilizing component, and then divide it by 2 using something like a d-type flip-flop, or a binary counter.

There's a collection of oscillators on this page which are meant to use with the Z80 CPU at 4MHz:


The simplest solution is to output a clock signal from your Arduino.

It would likely be cheaper and certainly easier to just by an oscillator. Chalk it up as a learning experience and keep the crystal for a future project.

Thanks, for the link Majenco!
It seems not so easy, and I don't want to mess with a lot of electronics at this point.

Tomorrow I will see if they have an oscillator in the store.
Out of curiosity, how do you output a clock signal from arduino? I've tried with a counter, everytime it reaches 8 it inverts a signal, so if Arduino is 16mhz, this should be 16/8=2mhz. But I don't think you can rely on it, is there another way?

How about the crystal controlled oscillator at the bottom of this page?
Seems pretty simple to implement.

You could also see Section 9.9 of the '328 data sheet.
The System clock can be output on pin CLK0 if the CKOUT fuse is programmed.
Take that, divide by 8, and voila, 2 MHz.

Out of curiosity, how do you output a clock signal from arduino?

CTC mode on one of the timers...

So it seems that a canned crystal oscillator is not so easy to find here on my city.
I bought 2x 22pF capacitors and a CD40138CN IC for the logic inverter (datasheet: CD4013 pdf, CD4013 Description, CD4013 Datasheet, CD4013 view ::: ALLDATASHEET :::) using also 2x100k R, I will try the the circuit at the bottom of this page Thomas Scherrer Crystal Oscillator Circuits
If that doesn't work I will try doing what Coding Badly proposed.

I'll tell you how this goes...

wait a moment... looking at the CD40138CN datasheet: CD4013 pdf, CD4013 Description, CD4013 Datasheet, CD4013 view ::: ALLDATASHEET :::
I see that you need a clock to drive it... so I'm guessing that doesn't work as an inverter, right?

it seems that at the moment my last option would be to get the clock out of arduino.

CD4013 - Dual D Flip-Flop - National Semiconductor

That’s not a CD40138CN

oh, I got the name wrong, its not an "8", its a "B"
so it is: CD4013BCN - Dual D Flip-Flop.

I was thinking... what about instead of using the inverter, getting that to the arduino so the arduino can invert the signal? Would that work?

… every step I take I realize there is something wrong.

I will try to use arduino as the inverter gate but… Where do I get the Clock output from the last circuit??? From one of the crystal pins? Also is it ok it doesn’t have Vcc? Everything is connected to ground.

You have lost me now.

hahaha... I'm also lost...

I mean, where from the last circuit on this page Thomas Scherrer Crystal Oscillator Circuits do I get the CLOCK OUT signal? On every diagram on that page there is a Vcc, a Vss and a Vout (for the clock I guess) but the last one lacks Vcc and Vout.
From what part I get the CLOCK signal?

Ah, I see what you mean now. I would imagine from the node at the top of Rf - the output of the inverter.

Oh... I never saw there was a clock circuit in the Ay-3-8910 datasheet. Its in Section 4.2 (page 29)

What if I have a 4mhz crystal? The same values of R and C should work, right?

In my case, do I need to connect PIN 13 of the CD4013 to the ground? Because I don't need a clock on my microcomputer (Arduino)

Ok, tomorrow I'll try that!

Thanks, all!

Ok, that's some useful information... from what I see on the clock circuit in the AY-3-8910 datasheet, I should connect PIN 13 to the PSG to get 1mhz.
I have a 4mhz crystal, so PIN 1 should get an output of 2mhz and PIN 13 an output of 1mhz in my case.

Can't wait the store gets open so I can buy what I need! I already have some coding to test a tone.

Ok, I did the clock circuit like the one on page 29 of the Ay-3-8910 datasheet: http://www.michael-george-hart.com/articles/computerscience/AY-3-8910_8912-Programmable_Sound_Generator.pdf
Difference is that I used a 4mhz crystal, and PIN 13 (after the inverter) goes to the PSG (in order to get 1mhz) and PIN 1 goes to PIN 11 because I don't need it's 2mhz output, no other output.
Also, I used a 330ohm R (instead of 300ohm) and 22pF capacitor (instead of 20pF) but that shouldn't be a problem, right?

Now, I think it is not working, if I connect the output to an Arduino PIN and do a Serial.print(digitalRead(1)) the amount of 0's and 1's I get is not even, for instance I get:

00110001100111 and so on...

Is there another way of testing if it works?
I followed the write and read procedures as majenco told me on another post (Arduino Forum) but it's not working right, and of course there is no sound coming from the channels. If it's useful I could paste some code to check if it's right.

Help?? Thanksssssssss!

Thanks a lot for that long and detailed reply, it was very helpful!!!
Now I understand why were the readings like that, so let's suppose that the clock works.

Your connections to the Arduino should be similar to Figure 11 in the data sheet, 8 data lines and 3 control. It's also possible to control the chip with only 2 control lines, see Section 2.3
Next, I would see if I could write to and read from a register. If you can't do that, there's probably something wrong either with your wiring or code.

The connections between PSG and Arduino are like that, and I already tied BC2 to +5v, so I already use only 2 control lines.

YOU KNOW WHAAAAAAT??? I tryed again with your test tone and it WORKS!!!

I will paste entire and corrected code on this post: Arduino Forum