How to generate 16MHz signals with arduino mega 2560

I recently bought a arduino mega 2560 board. On the specifications sheet it says that the frequency is 16MHz. Currently I am using the "delaymicroseconds" function to try to generate functions, but I could only generate signals with up to 15us periods (~60KHz). How do we generate signals with 16MHz frequency?

Thanks for your reply.

You can get up to 8MHz using the timers.

Think about it!

An Arduino does at most one instruction per clock cycle. How could it possibly produce a 16MHz output signal.

...R

Yeah - you can't get output frequencies more than half the main chip frequency (though you can set a fuse to output the 16mhz clock signal on the CLKO pin) - this is true of pretty much all microcontrollers.

The exception to this is if the chip has some way of generating a higher frequency on-chip; within the AVR family, the ATTiny85, ATTiny861, and ATmega64M1 (and the smaller-flash/ram versions of those chips) have a PLL that provides a 64mhz fast peripheral clock from the 8mhz internal clock - these chips usually have one timer that can use this high speed signal as it's clock source, allowing you to use that timer to get a signal as fast as 32mhz. (since it needs to be high or low for one timer clock cycle minimum). Other microcontrollers may or may not have such a feature, consult the datasheet for details.

Could I ask why you need to generate a 16MHz signal?

Take a look at the datasheet - you can get the chip to output its own clock - no software required. Well other than setting a reg on startup.

Mark

holmes4: Take a look at the datasheet - you can get the chip to output its own clock - no software required. Well other than setting a reg on startup.

Sounds like an expensive and pointless use of a microprocessor.

...R

JohnLincoln: Could I ask why you need to generate a 16MHz signal?

We are using the Arduino board to generate timing signals for chip-testing.

Based on simulations, some testmodes would perform best with delays smaller than 100ns.

I was thinking that if the chip executes an instruction serially every clock cycle, then the output could be the same speed as the clock. Ex. Input Ins1(t=0)->Input Ins2(t=1)-> delay-> Output1(t=n)->Output2 (t=n+1).

To AWOL: Thanks, I'll look into the timer functions! To Drazzy: I may need to buy the 32MHz one if this one does not work out! Thanks for your help .

No. If the processor runs one instruction per clock, it takes two instructions to generate HIGH and then LOW so you will get 8MHz. If you want 16MHz, you should get yourself a function generator, not an arduino. Do you intend to do any type of programming on arduino other than having it generate high-frequency pulses? If you're stuck with arduino, then another way to get the frequency, in a nice sine function form, is to modify the fuse to run full-swing oscillator so one of the two XTAL pins (XTAL1? check the datasheet) will be outputting 0-5V signals at 16MHz, strong enough to drive another microcontroller.

This image is taken from an arduino doing low-power oscillator so the total p-p value is about 1V. If you use full-swing oscillator setting, the waveform will go to about 5V.

|500x375