Hi,
Im currently working on an analog polysynth and one of the most crucial things is tuning of vcos. They will need quickly tweaing as the thing gets used and teperature changes. As good as some of these vco chips are, theyre not digital!
I have managed to use freqMeasure to successfully tune the various octaves of my voltage controlled oscilators but I have to use many cycles and I have had to filter out some odd readings. I think these are due to interupt issues. Regardless, for a deep tune this method works, however, for a quick tune, its far too long. By the time ive checked 8 voices with 2 vcos and 11 octaves itll take a while, probably several minutes.
The prophet 5 takes less than 10 seconds to tune.
I have done more digging and these machines and others had been using 8253 programmable interval timers and measuring just one cycle from the oscillator and they seem to be good enough and super quick. I couldn't get freqMeasure to work properly on just one cycle. freqCount is also going to bring its own problems with trying to get fast freq reads and is also not suitable for a quicktune algorithm.
Im sure with a modern mcu i shouldnt need to resort to something like a 8253 and today, having read round many forums i tried a new approach using ccnt cycle counter on a teensy 4.1 However ive had some rather unexpected results.
The plan is to wait until pin 22 goes high, log cycles count. wait for pin to go low, then when the pin goes high again, log the cycle counter again.
Measure the difference.
Eventually calculate the frequency of my input waveform based on the frequency of the cycle counter.
Heres the critical code with
setup(){
ARM_DEMCR |=ARM_DEMCR_TRCENA;
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA;
}
------------------------------------------------
loop(){
int timeStampStart = 0;
int timeStampEnd = 0;
int cycles = 0;
noInterrupts();
while (digitalReadFast(tunerSignal)==0);
timeStampStart = ARM_DWT_CYCCNT;
while (digitalReadFast(tunerSignal)==1);
while (digitalReadFast(tunerSignal)==0);
timeStampEnd = ARM_DWT_CYCCNT;
cycles = timeStampEnd - timeStampStart;
Serial.println(cycles);
interrupts();
}
--------------------------------------------------
This works to a point, however, this is the data im getting. (ive been testing the routine with my siglent sig gen so Im pretty sure the source freq is ok).
As you can see, certain frequencies seem to measure brilliantly and I can calculate the frequency of the cycle counter. for 1046hz and 16744hz the predicted cycle counter frequency comes out at 600mhz. Which is fab.However, you can see from the other figures, that the predicted cycles is all over the shop which means i cant get to my measured frequency by assuming that the cycle count is being performed at 600mhz.
I cant see why it would work perfectly at 1046hz and 16744hz but not say 523hz or 2093hz.
I half expected there to be a gradual drift in one direction, probably as the measured frequency got higher due to my digital reads fasts and while loops but as you can see its very unpredictable ( although for any given frequency its actually really consistant). I have double checked my results and as yet I cant find experimental error.
Any ideas?
Thanks
Im currently working on an analog polysynth and one of the most crucial things is tuning of vcos. They will need quickly tweaing as the thing gets used and teperature changes. As good as some of these vco chips are, theyre not digital!
I have managed to use freqMeasure to successfully tune the various octaves of my voltage controlled oscilators but I have to use many cycles and I have had to filter out some odd readings. I think these are due to interupt issues. Regardless, for a deep tune this method works, however, for a quick tune, its far too long. By the time ive checked 8 voices with 2 vcos and 11 octaves itll take a while, probably several minutes.
The prophet 5 takes less than 10 seconds to tune.
I have done more digging and these machines and others had been using 8253 programmable interval timers and measuring just one cycle from the oscillator and they seem to be good enough and super quick. I couldn't get freqMeasure to work properly on just one cycle. freqCount is also going to bring its own problems with trying to get fast freq reads and is also not suitable for a quicktune algorithm.
Im sure with a modern mcu i shouldnt need to resort to something like a 8253 and today, having read round many forums i tried a new approach using ccnt cycle counter on a teensy 4.1 However ive had some rather unexpected results.
The plan is to wait until pin 22 goes high, log cycles count. wait for pin to go low, then when the pin goes high again, log the cycle counter again.
Measure the difference.
Eventually calculate the frequency of my input waveform based on the frequency of the cycle counter.
Heres the critical code with
setup(){
ARM_DEMCR |=ARM_DEMCR_TRCENA;
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA;
}
------------------------------------------------
loop(){
int timeStampStart = 0;
int timeStampEnd = 0;
int cycles = 0;
noInterrupts();
while (digitalReadFast(tunerSignal)==0);
timeStampStart = ARM_DWT_CYCCNT;
while (digitalReadFast(tunerSignal)==1);
while (digitalReadFast(tunerSignal)==0);
timeStampEnd = ARM_DWT_CYCCNT;
cycles = timeStampEnd - timeStampStart;
Serial.println(cycles);
interrupts();
}
--------------------------------------------------
This works to a point, however, this is the data im getting. (ive been testing the routine with my siglent sig gen so Im pretty sure the source freq is ok).
As you can see, certain frequencies seem to measure brilliantly and I can calculate the frequency of the cycle counter. for 1046hz and 16744hz the predicted cycle counter frequency comes out at 600mhz. Which is fab.However, you can see from the other figures, that the predicted cycles is all over the shop which means i cant get to my measured frequency by assuming that the cycle count is being performed at 600mhz.
I cant see why it would work perfectly at 1046hz and 16744hz but not say 523hz or 2093hz.
I half expected there to be a gradual drift in one direction, probably as the measured frequency got higher due to my digital reads fasts and while loops but as you can see its very unpredictable ( although for any given frequency its actually really consistant). I have double checked my results and as yet I cant find experimental error.
Any ideas?
Thanks