VGA: External crystal to indicate pixel clock

Hello all,

Recently, I could generate successfully a 640x480 @70Hz via Mega 2560. I do not focus on pixel information, but on the stable V and H sync. That works good (time to time a small glitch... but it's ok).
The thing is, that code is very tight to current processor speed, full of NOPs and adjustments on calculations according to the standard definition of that particular resolution, so not the best thing in the world and I want to code this properly.

I thought that having an external crystal oscillator at the proper frequency could solve the problem, so I got a few, and tried to connect one of them.
The system is basically:
+3.3 -> Crystal -> Input Pin (2) with attachInterrupt on CHANGE.

The problem is... the ISR is not being fired. I am not an expert in electronics, obviously, so I googled a lot about how to plug crystals into circuits, but not much information about specific details (i.e. you need a resistor blahblah...).

So, basically, I would love if somebody could help me out understanding how a crystal needs to be connected to the Arduino to successfully be able to get its pulses.

Thank you.

A link to what you bought would be a big help. There are crystal oscillators in metal cans and there are just crystals in metal cans. Each can have three leads. Most crystals have two leads, but the can may have a ground wire.

A crystal is NOT and oscillator. An oscillator requires feedback to produce oscillations. The crystal allows oscillations on just one frequency, usually. You do not supply any feedback to the crystal.

I am sure you Googled crystal oscillator. Did you find a circuit that looks like what you described?

Paul

What is the frequency of your "crystal"?

Hi,

thank you for the quick replies. The exact name of what I bought (on ebay) is "15 Mhz HC49/4H crystal HC49S xtal Oscillator", here the link:

As per the name I was expecting an oscillator, but my googling this afternoon made me think I have just a crystal.

Would you have any info / hints on how can I achieve the goal of getting a signal in the Arduino whenever a pulse happens? I guess I will have a build a big circuit around it..

Nevertheless, if I am greatly mistaken by trying to use a crystal / oscilloscope to just signal on an Arduino pin periodically... just tell me :wink:

Thank you!

Do you have the Mega2560 data sheet in hand? If you connect a 15Mhz signal to an input pin, you are expecting some kind of response every 66 ns. Is that realistic considering that it is almost the period of one processor instruction cycle?

Let start over. Exactly how often do you need an external interrupt for your project?

An oscillator such as you attempted produces an AC signal, not a digital 0 and +3.3 signal.

We can help if you are specific.

Paul

Hi both,

aarg:
Do you have the Mega2560 data sheet in hand? If you connect a 15Mhz signal to an input pin, you are expecting some kind of response every 66 ns. Is that realistic considering that it is almost the period of one processor instruction cycle?

Paul_KD7HB:
Let start over. Exactly how often do you need an external interrupt for your project?

Answering both: As what I want to do is a project that can output VGA signals in different formats, more important for me is not the frequency of the particular clock I am using now but actually how to make use of it.
For the beginning I chose the 15 MHz to try to generate a signal that remotely could be like the one from the Amiga. Later on, I plan to use a 32 MHz one to be able to produce a "standard" 640x480 or even 800x600 @ 70 Hz. Only concern for the 32 MHz one is that Mega 2560 is half that speed, so I guess that the ISR would take (most probably...) more time than the interval until the next pulse. In that case I have an M0 waiting to be used.
So basically, code should be the same, getting triggered by an external clock's pulse via ISR. Only things that would differ are the number of pixels per segments of both signals (V and H).

Hope that answered the questions. Anyway, if sticking to 15 Mhz or 32 Mhz is a problem, I can adjust... I have absolutely no knowledge on crystals / oscillators so whatever I can take from this is a very good learning I will make use of, know or in future.

But as said, in case a crystal or an oscillator is not the solution for what I am trying to achieve, I will be happy to know.

Thank you!!

sergiator:
Hope that answered the questions.

Sorry, no it didn't. You just repeated your general objectives. We need to know the details of your design. How will the pixel clock be translated into timing signals? Specifically. I have already pointed out that the pixel clock frequency is too high to be sampled in software.

Ok... My understanding was that I could connect the clock to a pin in the Arduino, assuming the signal would be changing from HIGH to LOW or vice versa, so attaching an interrupt on HIGH, LOW or CHANGE would work for me to act upon a new pulse. If the clock is at 15 MHz, I assume I would get that event triggered every 1/15M sec.

Considering your comments about the AC voltage.. I get that instead of Xv to 0v it will go from Xv to -Xv.. so I do not know how I can mange that in the Arduino. Also I see that it will not produce any rising edge event. Correct? How could then I use it, or if a crystal doesn't fit at all for that purpose, how could I get such a signal tracked in the Arduino? Is there any kind of "known" circuit that can produce such event at a predefined frequency?

Thank you for the help!

Your plan is to get 15,000,000 or 32,000,000 interrupts per second. And your code can handle that?

Paul

I don’t know how fast/frequently you can interrupt, run an ISR, and return, but I think what you’re trying to do will be impossible.

But, the simplest way to get an oscillator is to [u]buy one[/u]. A crystal oscillator doesn’t cost more than a crystal alone.

You are still withholding all the details of your design.

Recently, I could generate successfully a 640x480 @70Hz via Mega 2560

That sounds ... impossible. 640x480x70 is a minimum dot clock of over 21MHz, and you can't get that from a 16MHz AVR.

I do not focus on pixel information, but on the stable V and H sync.

So it's got 640x480 VGA HS/VS timing, but supports some random number of actual pixels on each line? That seems more likely...

The thing is, that code is very tight to current processor speed, full of NOPs and adjustments

That is how such code is usually written; interrupts or even timers have WAY too much overhead.

sergiator:
If the clock is at 15 MHz, I assume I would get that event triggered every 1/15M sec.

50 kHz maybe, 15 MHz is way outside anything remotely possible on any processor anywhere.

You need specialized hardware to generate this sort of signal.

You need your oscillator feeding a shift register parallel in serial out, the shift register is fed with a parallel output of a dual ported RAM chip. Then the address lines on your RAM are fed with a counter derived from the a divide by 8 of the origional oscillator.
At some point you have divided this down enough with the RAM address counter that it is slow enough to trigger an interrupt and have the ISR fill up the RAM through its other port.

Or forget the dual ported RAM and have some logic chips generate a test pattern.

Hi all,

thx so much for the valuable input. I could take away that I was looking for the impossible due to my lack of kt / exp with electronics. I will then forget about that idea of having an oscillator at such frequency feeding the arduino and get back to the NOPs.

Grumpy_Mike:
You need your oscillator feeding a shift register parallel in serial out, the shift register is fed with a parallel output of a dual ported RAM chip. Then the address lines on your RAM are fed with a counter derived from the a divide by 8 of the origional oscillator.
At some point you have divided this down enough with the RAM address counter that it is slow enough to trigger an interrupt and have the ISR fill up the RAM through its other port.

Or forget the dual ported RAM and have some logic chips generate a test pattern.

Thank you Grumpy_Mike. I will check this out!!

Regards.