Synth & Freq Measure T4

dslocum

Well-known member
I'm hoping someone can direct me to a solution...

I want to accurately detect the frequency of an external VCO source (using something like Freq Measure library) and track some Teensy synth Waveform objects to it.

In theory (my theory at least), it should be easy to take the frequency output of FreqMeasure and simply feed to to the Waveform object. It seems from my limited knowledge however, that the two processes are competing for CPU time and BOTH have critical time requirements.

From what I've read, the T4 CPU only has one core, so I couldn't even wish for a CPU hardware level solution.

One thought, was to use one of Teensy's (32 bit?) timer / counters as a phase accumulator to measure the period of the external frequency source, thus starting to count on an input zero crossing, and then stopping it again on the next. This "gating" could be handled by simple external circuitry. What I'd be left with is reading the counter / phase accumulator into a variable, passing that number to the Waveform frequency parameter, then resetting the counter. Yet, I'm not sure if that's possible with the Teensy.

An alternative might be to have an external hardware CMOS counter / phase accumulator circuit, and then read it in parallel into the Teensy - but this seems wasteful of pins and external hardware - if I can do it in the CPU.

FWIW, I'm NOT trying to track pitch of complex waveforms - just a simple square wave input.

Guys - I'm open to ideas here.

Thanks
 
have you checked and tried out the "notefreq" method in the Teensy Audio Library?
https://www.pjrc.com/teensy/gui/index.html?info=AudioAnalyzeNoteFrequency

Thanks for your reply.

I did think of that, but since it makes heavy use of interrupts, it would interfere with all the audio synth stuff - which also uses interrupts - that I need to happen at the same time.

I ordered some 16 bit counter chips to test my hardware version idea. That way, I can read the HW counter in the LOOP code section. Should be able to wire up something to test in a few days.
 
Wow, thanks again for your suggestion!

That was actually the first thing I tried before trying NoteFrequency. Unfortunately, that also uses interrupts which completely messes up the audio stuff.

The more I've thought about it, I really don't think there's going to be a good CPU based solution. The control signals that are required to start and stop the period counter (accumulator) can't be interrupt driven if you're using the audio engine.

I'm more than happy to be proven wrong on this point however.
 
One crazy idea might be, us an adruino nano to measure the time with interrups and so on, and send the reesult via I2C when ready. An additional IO can send a ready signal, so the teensy can pick it up
 
The Audio library has no problem with additional interrupts. Any Teensy 3.x or 4 is fast enough, and the 128 Samples buffer is large enough.
Also, there is no requirement for a 2nd core.
I think you are significantly underestimating an ARM Cortex.
 
Frank & Recyclestudio,

Thanks for the input. Maybe I gave up on my initial tests too soon. Now with your feedback, I'll spend some more time on this without hardware.

It's always so great to have helpful folks around giving advice and suggestions! Most appreciated. :)
 
One concern...

Are the timers in the FreqCount library used in the Audio library? Will they interfere at all?
 
Maybe you think it's a speed problem, but it isn't... :) We don't know what you did exactly, so, it's hard to give a advice.
Note, the Audio interrupt is the lowest priority one. There are already a whole bunch of other, higher priority interrupts (USB, Systick, etc etc) running, without any influence... the audio interrupt runs at a 2.9ms frequency. 2.9 ms is a very long time.

The audio does not use any timers (as long you don't use the A/D (which is no good on the T4 anyway))
 
Good info sir! I'll be giving it a try.

But what's the concern with the A/D? I'll be needing to read a few pots in this app. Workarounds?
 
Back
Top