Tone function and multitasking

Hi Folks,

I am currently undertaking a project where I need to read a frequency and multiply it for a given value.
Originally I was planing to use the tone function but now that i got back to it I realized perhaps the tone does actually keep the CPU busy toggling the digital pins.

Is my assumption correct? What other methods do i have available?

Regards

I wouldn't say it keeps the CPU busy,,, for example, you can see that using analogWrite() to a digital pin doesn't block your code pulsing your PWM pin

try your tone() and see what happens....

I tried earlier for a piezzo buzzer, and the code doesn't move forward until the buzzer finishes whatever time I set it for.
Just like having a delay.

I would be more inclined in using a free timer.
I have a few useless timers on the arduino mega, whose some connections weren't brought out to any external pin. From memory timers 2 and 3.

Even if I have to toggle a pin using direct port access it shouldn't take that much time, perhaps pre-load some value to the counter to make it overflow more often...?

and the code doesn't move forward

What code?

I have a few useless timers on the arduino mega

Bullpoop. Unused, maybe. Useless, no!

PaulS:

and the code doesn't move forward

What code?

The code I wrote, what else?

PaulS:

I have a few useless timers on the arduino mega

Bullpoop. Unused, maybe. Useless, no!

For my application they are useless. Surely I could come out with lots of other uses from PWM to delays.

You're not saying I should, perhaps, attach a servo or a few LED's being driven by PWM just to make use of them are you?

The code I wrote, what else?

Oh, that code. Well, then you should rewrite it so that it doesn't block.

We can't see it, so you are on your own.

For my application they are useless.

OK. So are all those unused pins. You should definitely cut them off.

PaulS:

The code I wrote, what else?

Oh, that code. Well, then you should rewrite it so that it doesn't block.

Looking into that now. Probably less hassle setting a timer in CTC mode
The tone documentation doesn't say anything about PWM pins, so I am wondering if it makes a difference if I select a PWM pin. I love the abstraction on the arduino and how no technical details on how things really work. I remember digging a few threads months ago to figure out why the minimum frequency was 30Hz.

PaulS:

For my application they are useless.

OK. So are all those unused pins. You should definitely cut them off.

Certainly, but having the choice to so so at will. I certainly could do with the Tx and ICx inputs on the timers and the missing interrupts. (Oh yes, to use the interrupts I need to give in one serial port :grin:) Clearly this is out of the Arduino "language" scope, but i don't know how much they saved by leaving a dozen pins unconnected.
For example the iteduino mega has all the pins available http://imall.iteadstudio.com/im120410003.html

Not to forget how much they save by replacing the crystals with resonators. What's wrong with leaving the PCB space for one as the STM NUCLEO boards do?