In my real program ISR should update a 16bit DAC
If that's the goal, AVR's adc module can be set up to be triggered automatically and periodically. It is fairly easy to set up. I can post a piece of code there if you want.
If I understand well the question, value 32 on PORTB set pin 13. I think it doesn't matter which one is the bit I toggle, pin 13 or another. I know programming timer for fast interrupt, occupy lot of CPU time but if all the CPU job is made by ISR, that is the faster and more precise timing we can obtain and It's what I need. In my real program ISR should update a 16bit DAC, in this code I just set pin 13 for checking the timing on oscilloscope. I haven't tried CTC mode because I don't need really to toggle a bit on a port, I need to update some port and toggle few bits in the interrupt service rountine. But I can't understand why this program doesn't works. I can suppose Arduino compiler puts some extra code on mine but I can't find any confirm to this supposition.
//settingPORTB |= 1 << 5;//clearingPORTB &= ~(1 << 5);
PORTB ^= 1 << 5;
What you did with the 32 was set and reset 4 bytes.
But how does this relate to a DAC???
For debugging purposes. He is trying to try to the code so it flips a pin - to be observed by a scope that signals that the timing portion of the code is working. He can then add the DAC portion of the code.A fairly common way to build up and debug one's code.
So why the complex timing arrangement with two timed interrupts keeping the processor busy all the time?
And, most importantly, if the timing part underestimates the load that driving the DAC will have on the program, ...
First, test the DAC, ...