Hi, I am a new user. I am trying to generate a 1.6Mhz frequency from Mega 2560 board. With dealy or tone, I can only generate less than 100Khz signal. Does any one knows how to do it?
Besides, I want to generate a 14 bit signal with shiftout function. Does anyone knows how to let it work also at 2Mhz?
I guess it may need to change the work frequency, but I don't know how.
Thanks!
I don't know about the first part, dividing the 16 MHz internal clock by 10 might be tricky. Dividing by 2,4,8,16 seems more common.
Shiftout; if you used SPI (built in hardware) at divide by 8 speed would work well - but it clocks out 8 bits at a time, are you sure you can't use 16 bits? Maybe have 2 bits be zero all the time?
Otherwise, do a software shiftout so you can stop after 14 bits - don't think you will see 2 MHz tho.
Have an array from 0 to 13 and create a clock pulse after changing the datapin state:
data_array[14];
// fill it somehow
data_array[0] = 0;
data_array[1] = 1;
// etc. Probably better ways to do that.
data_array[] = 1,0,1,0,1,0,1,0,1,0,1,0,1,0; // something along those line, read the Reference section
shiftClk = 0;
x=0;
while (x<14){ // loop thru the array, writing the value and making a clock pulse.
digitalWrite(datapin, data_array[x]);
digitalWrite (shiftclk, HIGH);
digitalWrite (shiftclk, LOW);
x=x+1;
}
gulu2065:
Hi, I am a new user.
Hi. Welcome.
I am trying to generate a 1.6Mhz frequency from Mega 2560 board.
16,000,000/(21(1+4)) = 1,600,000
You will need to configure: one of the timers to run in "Clear Timer on Compare Match (CTC) Mode"; with a prescaler of 1; an output compare of 4; and one of the two associated output pins set to toggle.
Thanks for your reply!
However, I am just try to use arduino and do you know how to configure? Could you explain a little more in detail?
Thanks,
The timer could also be configured in a PWM mode with TOP set to 10 - this allows various duty cycles of 10%, 20% .. 90% should that be useful. It does mean reading the datasheet or finding existing code to do similar configuration though.
To do this in software, see if you can get ideas from the thread here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230286016