Output Atmel 2560 Clock to pin

Hello,

I was wondering if it is possible to output the clock of the Arduino Mega to a IO pin ? I have done this before with a MSP430 so I'm confident there is a ATMEL solution.

I am looking at the timer documentation in the datasheet but can't figure it out if it is possible.

I have an external IC that requires a clock source. and I would like to use Arduino's 16 MHz clock to clock it.

I would like to avoid using timer interrupts to accomplish this.

Any ideas ?

Sure, just needs a fuse set. See Table 30-5 for the Low Fuse byte: "The CKOUT Fuse allow the system clock to be output on PORTE7. See “Clock Output Buffer” on page 49 for details."

Thank you for the response

I wasn't familiar with the fuses and I've done some googling. I understand that I need to set the fuse bytes in the 'boards.txt' file and burn a new bootloader again.

My target board is a Mega 2560 (Taurino Classic if it matters).

I have modified a line the boards.txt file to reflect the change in the fuses: mega2560.bootloader.low_fuses=0xBF

I'm all set to go .... but I am not sure how to burn a new bootloader onto the Mega. I don't have an ISP programmer. I only have an Arduino Uno board lying around and a couple of jumper wires.

I've tried searching tutorials but all I've found is instructions burning an Uno from a Uno or burning a Uno from a Mega. I need to know how to burn a Mega from an Uno.

Any ideas ?

Thanks,

chuyzoz: I need to know how to burn a Mega from an Uno.

In exactly the same way as doing it the other way around.

Make the following connections:

Mega to Uno Reset to Pin 10 Pin 52 to Pin 13 Pin 51 to Pin 11 Pin 50 to Pin 12

Then download the ArduinoISP sketch to the Uno. Finally connect power to the Mega.

The rest of the instructions are the same for programming the other way around (select the Programmer, Serial port and Board, then click Burn Bootloader)


HOWEVER...

PORTE7, the clock out pin is not broken out. It does not connect to any of the Arduino Mega pin headers.

Thank you for the instructions.

And thank you for that last point .... Guess I'm buying an external clock. :)

If you don't need the PWM pins 44,45 and 46, then you can get Timer5 on the Mega to generate a clock signal which is half the system clock, so 8MHz. Will that suffice? or does it have to be 16MHz.

Edit: You can potentially make two 8MHz clock outputs which are 90 degrees phase shifted and then use an external XOR (or XNOR) gate to combine those into a single 16MHz clock signal. I'm not 100% sure this is possible unless you use two different timers, say Timer4 and Timer5 and can ensure they are in sync. Ignore that last statement, it won't work.

chuyzoz: Thank you for the instructions.

And thank you for that last point .... Guess I'm buying an external clock. :)

I agree with Tom, if 8 MHz is enough, do what he said. Failing that get an Atmega328 (or smaller) and just use it for a clock source. You would just need a resonator or crystal, a couple of capacitors and a resistor to hold it out of reset.

Although maybe you can just hook up a 16 MHz crystal and use that as a clock. I'm not an expert on crystals so I wouldn't know.

[quote author=Nick Gammon link=topic=180382.msg1337454#msg1337454 date=1375304822] Failing that get an Atmega328 (or smaller) and just use it for a clock source. You would just need a resonator or crystal, a couple of capacitors and a resistor to hold it out of reset. [/quote] Probably cheaper to get something like this if you do need 16MHz. (http://uk.farnell.com/ael-crystals/o16m000000l021/crystal-oscillator-16mhz/dp/9510125)

Alternatively, if your 16MHz clock doesn't need to be accurate, you could just use an Attiny85. Set it up to use the internal oscillator with the 2x PLL enabled (gets you ~16MHz) and then output that onto its CLKO pin - all it takes is one component (the Attiny85, you can connect the reset pin directly to VCC).

Or just spend $2 and buy an oscillator http://www.digikey.com/product-detail/en/MXO45HS-3C-16M0000/CTX750-ND/1801865 http://www.digikey.com/product-detail/en/MXO45HST-3C-16M0000/CTX795-ND/1801910

CrossRoads: Or just spend $2 and buy an oscillator

Yup, same type as in the link I posted :)