Get a 16mhz Clock from Arduino

Hey there,

I am currently working on a Project where I want to read out an Sensor with my Arduino Mega.
This Sensor needs to be fed with a 16mhz Clock Cycle. Maybe it was just my own stupidty but I found nothing really useful about this neither on the Arduino Site nor Forum nor in the endless vast of the so called Web.

However, here is my Question: Is there any possibility to get a 16mhz frequenzy out of this beautiful, tiny Arduino Mega? May it be Hardware- or Software-wise. A 50% duty cycle would be perfect.

So if you got an idea concerning this, I would highly appreciate if you would share it with me, because sharing is what it's all about, right?

Thank you in advance!

Arduinojoey

PS: I really hope this is the right Place to ask such a question :roll_eyes:

1 Like

The crystal is connected to a clock output and clock input.
Normally the crystal runs at a lower voltage, but it is possible to set a "full swing" with a fuse.

Do you have a Arduino Mega board, or a Arduino Mega 2560 board ?
I assume it is a Arduino Mega 2560 board.
See here for the fuses, select the ATmega2560.
http://www.engbedded.com/fusecalc/

In the file "boards.txt" are the fuses definition, you can find what they are now.

However, you probably need a buffer, since you don't want to disturb the crystal. So you might just as well buy a crystal oscillator of 16MHz (I forgot the name, they are in a metal case).

This Sensor needs to be fed with a 16mhz Clock Cycle.

Why, is it giving you data at that rate?
It would help if you posted a link to the sensor then we can avoid the x-Y problem that this is sounding like:-
http://xyproblem.info/

And you don't mean millihertz, you mean megahertz. MHz hertz is Hz, m is milli, M is mega.

You see I very much doubt if 16MHz is the lowest frequency that the sensor will work at, I suspect it is the absolute maximum frequency the sensor will work at. Therefore the last thing you want to do is to actually run it at 16MHz.

First of all, thank you very much for your answers.
I mean of course MHz, mHz would be quite slow...

The sensor is an TAOS TSL1412, Datasheet available here:
http://ams.com/eng/content/download/250185/975733/142519

And yes, 16 MHz is the maximum frequency, which I actually wanted to use, because speed is quite important for what I am planning to do. (A highspeed-linefollowing robot) I also know that an Arduino isn't probably the right choice for this. However, I'd like to give it a try. As I understood, the Arduino can generate a 4 MHz Clock using its PWM, which is not that bad.
Of course I could run the sensor at this frequency, but in the long term I really would like to have it as fast as possible.

I think I will just use an external 16 MHz Crystal, as it really seems the easiest way to me.

Arduinojoey

From the datasheet:
"Although the linear array is capable of running over a wide range of operating frequencies up to a maximum
of 8 MHz, the speed of the A/D converter used in the application is likely to be the limiter for the maximum clock
frequency. The voltage output is available for the whole period of the clock, so the setup and hold times required
for the analog-to-digital conversion must be less than the clock period."

Are you using the 10-bit, 110uS converstion internal ADC? Or a faster external ADC?

Since most arduino instructions require multiple clock cycles you wouldn't be able to process the data at the clock speed of the uC. Even if you could do a read in 1 cycle, how does that help if you spend the next
30 to 50 cycles taking action based on what you read ? You would do just as well reading at a slower speed
because you gain nothing by using the 16 Mhz clock speed.

Update – Based on JimS’s timing code (see comments): digitalRead() = 58 cycles and direct pin read = 1 cycle.

arduino I/O process times

AnalogReads are even slower.

Wouldn't programming the CKOUT fuse give you a 16MHz clock out on digital pin 8?

Right idea. Wrong pin.

Oops, you're right, didn't see the Mega in the original post (digital 8 would be correct for an Uno or other 328-based arduino). PE7 then, whatever that breaks out to (edit - seems to be an unused pin so would have to connect directly to the pad).

PE7 then, whatever that breaks out to

PE7 is pin-9

ATMEGA 2560 DATASHEET

It doesn't seem to breakout to anything
ARDUINO ATMEGA 2560 PINOUT

I mean to arduino header pins.

Ok I got it. I think I will stick with the 976Hz from the fast PWM mode.

I mean to arduino header pins.

Yeah right. The 16 Mhz clock broken out to a header pin ? In your dreams...
I think you can get a Timer output with Prescaler of 1 that will give you 16 Mhz , but that isn't a "breakout" per se because it is only that frequency when configured whereas a "breakout" is always the same.

Schemmel, if you even bothered to read the data sheet the device won't work at 16Mhz, so your point is moot

Although the linear array is capable of running over a wide range of operating frequencies up to a maximum
of 8 MHz, the speed of the A/D converter used in the application is likely to be the limiter for the maximum clock
frequency. The voltage output is available for the whole period of the clock, so the setup and hold times required
for the analog-to-digital conversion must be less than the clock period.

If you connect to one of Mega's 16-bit timers you will have lots of flexibility. Haven't done a Mega, but my 32U4 project which has a 10-bit timer would count at 64Mhz through use of the PLL. Whatever clock you run at, and the datasheet gives you formulae, the A/D will be the limiting factor in the application.

You can output 8 MHz with a prescaler of 1 and a count of zero. That way it toggles at 16 MHz but that represents an 8 MHz frequency.

He can use your suggestion Nick, but I'll still be waiting to see how he can convert samples at 8Mhz. That's why I suggested he use the timer so he can experiment with different clock rates. The device appears to be a CCD array so speed vs. output will be a factor.

The OP wants to use it for "line following" for his robot. That being said, he would do well if he could process a correction every 100mS or so. If bandwidth is a concern, I would start with the DUE, not the 2560.

I understand. It sounds like another X-Y question. Pity the words "line following robot" weren't in the thread subject.