Hello:
I am doing a design of an add-on board that needs a clock. The 2560 has a clock out on pin 9 of the CPU (PE7). It looks like this signal does not go off-board anywhere. Is that true?
Is there anywhere on the Mega where I can pick up a clock signal?....I really don't want to add a clock chip on my board, but if I have too.....
CrossRoads:
How fast of a signal do you need? 16 MHz, or slower?
Short answer is: Not clear.
I would estimate: 10 MHz <=x<=33 MHz.
I tried the PWM output, 50% duty cycle and basically get 500Hz which is nowhere near sufficient.
Part of the reason for my uncertainty is the tuning of some digital filters that the clock will be driving.
If there was a way to generate 1 MHz, or maybe 5 MHz easily, I could wire that into my design and see how it would perform....
The CLKO signal from the 2560 is (?) mostlikely capped at 16 MHZ, and that would be a reasonable starting point if I could get it up to the daughter board that sits on top of the Mega.
"The CLKO signal from the 2560 is (?) mostlikely capped at 16 MHZ" Yeah, that's what the crystral runs at.
You can do things with the timers directly to create higher frequency outputs.
The code for PWM is set to 490 Hz, duty cycle independent, you can alter that also.
Both require you to access the registers directly tho. The names all look similar to me for doing that, others here can offer correct guidance.
I belive 1,4, 8 MHz are all easy, nice multiples of 16.
(I really should look into understanding this usage more ...)
You should be able to play with the timers and PWM outputs to get far faster than 500Hz.
60kHz is easy, if you play the the TOP register you should be able to get it very fast indeed.
I've had one of my attiny85v chips putting out a nice 1MHz PWM. Should be able to go a lot higher than that too, at the cost of reduced PWM resolution. (1MHz still had ~90 steps between 0 and 100%. For 10 steps you ought to be able to get 9MHz or so in theory.)
If you just need a signal you could slam the TOP nearly all the way down and get >10MHz in theory. I'm making the happy assumption that if the attiny85 can do it, the atmega2560 can do it.
I think it'll still cap at 16MHz (or a bit less), as the timer/counter ticks with the main CPU(AVR? whatever) clock.
CrossRoads:
You can do things with the timers directly to create higher frequency outputs.
The code for PWM is set to 490 Hz, duty cycle independent, you can alter that also.
Both require you to access the registers directly tho. The names all look similar to me for doing that, others here can offer correct guidance.
I belive 1,4, 8 MHz are all easy, nice multiples of 16.
I (generally) know how to do that with timers. Being new to the arduino platform (but certainly not to high-end micros) if I have access to the assembler, I could do it. Just don't know how to make it live in the arduino environment...
Guess I have to start the doc search.
Any pointers for this would be much appreciated.
Thanks,
J
Bobnova:
You should be able to play with the timers and PWM outputs to get far faster than 500Hz.
60kHz is easy, if you play the the TOP register you should be able to get it very fast indeed.
I've had one of my attiny85v chips putting out a nice 1MHz PWM. Should be able to go a lot higher than that too, at the cost of reduced PWM resolution. (1MHz still had ~90 steps between 0 and 100%. For 10 steps you ought to be able to get 9MHz or so in theory.)
If you just need a signal you could slam the TOP nearly all the way down and get >10MHz in theory. I'm making the happy assumption that if the attiny85 can do it, the atmega2560 can do it.
I think it'll still cap at 16MHz (or a bit less), as the timer/counter ticks with the main CPU(AVR? whatever) clock.
Thanks for the suggestion. Unfortunately I don't know what the TOP register is or how to manipulate it...
In modifying this register can the duty cycle be fixed at 50% - I want that for the clock signal...
-J
I don't have an atmega2560 in front of me, (or at all) but the following is for an attiny85. It should be very similar for the atmega2560. You'll need to figure out which timer does which PWM pins, and make sure it has a TOP register (the datasheet will tell you), some timers do and some timers don't.
PLLCSR |= ((1<<PLLE) ); /* Enable PLL */
{
unsigned char counter;
/* Wait at least 100 us for PLL to stabilize */
for(counter = 0; counter < 250; counter++)
{
asm("nop"); /* Each NOP should take 500 ns -- MCU Clock at 2MHz */
}
}
while(bit_is_clear(PLLCSR,PLOCK)) ; /* Wait for PLL to lock (approx. 100ms) */
PLLCSR |= (1<<PCKE); /* Set PLL as PWM clock source */
//The following for 25khz
OCR1C = 160; // TOP value, the lower the TOP value the faster the PWM frequency. Half the top value is 50% duty cycle.
TCCR1 |= ((1<<PWM1A) | (1<<COM1A1) | (0<<CS13) | (1<<CS12) | (0<<CS11) | (1<<CS10)); //this line sets the timer divider, 0001 should be full speed. The current setting gives 25KHz.
After that, you can use standard analogWrite (pin, halfOfOCR1) to set the duty cycle to 50%, and presto!