I want to try the WIN AVR example herehttp://home.att.net/~geobra/blinkScratch.html
Will this code work from the Arduino IDE?
and while you are there, can you tell me if i can activate isr of timer 2 by
ISR (TIMER1_OVF_vect);
Cheers,
Pracas
I want to try the WIN AVR example herehttp://home.att.net/~geobra/blinkScratch.html
Will this code work from the Arduino IDE?
and while you are there, can you tell me if i can activate isr of timer 2 by
ISR (TIMER1_OVF_vect);
Cheers,
Pracas
The code will not work "as written."
The first problem is surprising - the compile doesn't like the extra spaces in #include < inttypes.h >
Perhaps this is a version or environment dependent thing? Or maybe the code got pretty-formatted for the web page without checking to make sure that didn't bother anything...
The second problem is that the arduino environment already defines an interrupt based on timer0 (this is what runs millis() and related timing functions. So trying to include another ISR for timer0 results in an error:
multiple definition of `__vector_16'
The arduino core does NOT use timer1 or timer2 interrupts, so you can in theory convert this to use one of them. Bringing us to your second question:
can I activate isr of timer 2 by ISR (TIMER1_OVF_vect);
I'm pretty sure that for timer 2 you'd need TIMER2_OVF_vect
Defining the vector does not actually "activate" the timer; it just provides code at the appropriate location to catch the timer interrupt once you have manually enabled it by writing the appropriate bits to the appropriate timer control and interrupt control registers...
So I cannot play around with timer0 from the arduino ide? apart from that the rest will work?(ignoring the formatting) and given i change it to timer1 or timer2?
cheers,
pracas
So I cannot play around with timer0 from the arduino ide?
Well, you can change the timing and PWM (capture/compare) values and stuff like that, but you can't provide your own interrupt service routine.
apart from that the rest will work? and given i change it to timer1 or timer2?
I didn't actually try it; I just fiddled till it compiled. But I don't see any reason that it shouldn't work.
Note that it operates fundamentally differently than blink.pde
It might be interesting to have a whole series of "blink" sketches, all of which do the same thing in different ways...
(ok, I tried the "obvious" replacements of 0 --> 1 in code statements having to do with the timer, and actually loaded the code on a real arduino board. It DOES work, although it looks like the blink is running about half the speed that is expected (2s or so on and off.) A good excercise in debugging, left to the student (Note that the three timers on the ATmega168 are each slightly different...) Let me know if you get stuck, and I'll post the code...)
Oh. You have to rename main() to setup() and provide a blank loop() function, or the equivalent.
I knew I left out something...
thanks... I'm just starting out on playing around with the timer... end objective: to try and create a function to generate pwm on any pin. but then i've been studying so much of it that it didn't occur to me that i could've simply tried dumping the code anyways thanks for the efforts.
Quote:
So I cannot play around with timer0 from the arduino ide?
Well, you can change the timing and PWM (capture/compare) values and stuff like that, but you can't provide your own interrupt service routine.
Actually I think that if you provide your own interrupt service routine for timer0 in the sketch then this will override the "standard" ISR. But then all timing functions will stop working, and other veird things can happen, so use caution.