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:
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?
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.
... 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.
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?
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.
NEED HELP AGAIN!
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 (http://arduino.cc/forum/index.php/topic,114412.0.html) 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.
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!!!