This is my first post here, so i apologize if i am posting in the wrong section. I am following this tutorial http://www.engblaze.com/microcontroller-tutorial-avr-and-arduino-timer-interrupts/, but I cannot get the frequency up to 16MHz (i am using a arduino uno).
With no prescaler i only get about 125Hz max.
I DO NOT have an external power supply connected (I am running off USB power), will that affect the timer?
well, i thought it would be obvious i was using the code on the link provided ON THE FIRST POST, but apparently obvious is not a very well understood word....
In any event, using the code on the link and just changing the pin number to pin 10, i can generate 121.8Hz.
If I use the code below, i can reach 363kHz.
On the link's code is right below the TCCR1B |= (1 << CS10) line. On the code I posted i have none, since, as far as i understood, I am not using any interrupts.
hpupo:
well, i thought it would be obvious i was using the code on the link provided ON THE FIRST POST
It is more work (and time) to click your link than to read code when you post it here. Make it as easy as possible for people to help you. There are 100 other questions also waiting for an answer.
An instruction takes 62.5us for 16Mhz UNO
You want 2MHz which is 500ns which is 8 instructions, see any problems?
In any event, using the code on the link and just changing the pin number to pin 10, i can generate 121.8Hz.
If I use the code below, i can reach 363kHz.
If you:
void loop()
{
PINB |= _BV(PINB2); // Toggle digital pin D10
}