sketch_apr08a.cpp: In function 'void TC0_Handler()':sketch_apr08a:9: error: 'REG_TC0_SR0' was not declared in this scopesketch_apr08a.cpp: In function 'void loop()':sketch_apr08a:42: error: 'REG_PIOB_PDR' was not declared in this scopesketch_apr08a:43: error: 'REG_PIOB_ABSR' was not declared in this scopesketch_apr08a:44: error: 'REG_TC0_CMR0' was not declared in this scopesketch_apr08a:45: error: 'REG_TC0_IER0' was not declared in this scopesketch_apr08a:47: error: 'REG_TC0_RC0' was not declared in this scopesketch_apr08a:48: error: 'TC0_IRQn' was not declared in this scopesketch_apr08a:48: error: 'NVIC_EnableIRQ' was not declared in this scope

sketch_apr08b.ino: In function 'void TC0_Handler()':sketch_apr08b:9: error: 'REG_TC0_SR0' was not declared in this scopesketch_apr08b.ino: In function 'void loop()':sketch_apr08b:42: error: 'REG_PIOB_PDR' was not declared in this scopesketch_apr08b:43: error: 'REG_PIOB_ABSR' was not declared in this scopesketch_apr08b:44: error: 'REG_TC0_CMR0' was not declared in this scopesketch_apr08b:45: error: 'REG_TC0_IER0' was not declared in this scopesketch_apr08b:47: error: 'REG_TC0_RC0' was not declared in this scopesketch_apr08b:48: error: 'TC0_IRQn' was not declared in this scopesketch_apr08b:48: error: 'NVIC_EnableIRQ' was not declared in this scope

It would help to specify what board you have selected, this isn't supposed to be a guessing game.

You need to reset the counter whenever you change the period. What can go wrong is, if you shorten the period, the counter might have already gone past the new period value, and then it won't trigger the interrupt until it has counted all the way to 0xFFFFFFFF, wrapped around to 0 and got to the new period value - which is why it takes a while to speed up.

The line REG_TC0_CCR0=0b101; restarts the counter. You need to put it just after REG_TC0_RC0 = incomingValue*1000000;

You need to reset the counter whenever you change the period. What can go wrong is, if you shorten the period, the counter might have already gone past the new period value, and then it won't trigger the interrupt until it has counted all the way to 0xFFFFFFFF, wrapped around to 0 and got to the new period value - which is why it takes a while to speed up.

The line REG_TC0_CCR0=0b101; restarts the counter. You need to put it just after REG_TC0_RC0 = incomingValue*1000000;

Stimmer! You are awesome! The problem got solved! Special thank to you!

Now, I have one more question and I wonder if you or anyone who reads this can kindly answer to it. As you can see here and the page 871 and 872 of Datasheet for Arduino Due (AT91SAM), there are some special pins to enable the Timer.

Here we use TC0 Channel 0 and pins 2 1nd 13.

I tried Pin 61 and 62 (For PA2 and PA3 for the AT91SAM ) and TC0 channel 1 to get another independent frequency. For example

instead of REG_TC0_SR0 I have used REG_TC0_SR1. But this approach seems doesn't work properly. Do I need to apply other changes?

Do you know how I can get a couple of unique and completely independent frequency out of this?