hello everybody,
i'm working on this sketch :
http://interface.khm.de/index.php/lab/experiments/arduino-dds-sinewave-generator/
i just change some lines in order to change the frequency according my sensor's value. it works well up to
1000hz then i can hear on the background some strange noise like randomly falling notes. it's quiet.
i think it comes from the fact that current frequency value is sent at a different clock (loop clock) than the one of the interrupt function (sampling rate clock). i believe that i can't put analogRead in the interrupt function because of the process cost.
maybe one of the solution is to ask the time interrupt function to wait the end of a cycle before
updating the frequency value. So if the interrupt function reach the end of a cycle (end of the sine array)
it updates the frequency according to my sensor value. i don't know how to make it...
so how can i synchronize my sensor value with the time interrupt ?
i just change this part :
while(1) {
if (c4ms > 10) { // timer / wait for 40ms
c4ms=0;
//dfreq=analogRead(0); // read Poti on analog pin 0 to adjust output frequency from 0..1023 Hz
dfreq=440+(analogRead(0)); //my sensor value
cbi (TIMSK2,TOIE2); // disble Timer2 Interrupt
sbi (TIMSK2,TOIE2); // enable Timer2 Interrupt
/* Serial.print(dfreq);
Serial.print(" ");
Serial.println(tword_m);*/
}
// calulate DDS new tuning word
tword_m=pow(2,32)*dfreq/refclk;
sbi(PORTD,6); // Test / set PORTD,7 high to observe timing with a scope
cbi(PORTD,6); // Test /reset PORTD,7 high to observe timing with a scope
}
the complete sketch is attached
thank you !
KHMDDSsignalReq.pde (4.56 KB)