Hi, I have been trying to set the timer constant of OCR1A to the variable TImer_count so that when I change Sfreq it automatically updates Timer_count and hence OCR1A. Does anyone know how to and what kind of variable I set Timer_count to? Many thanks!
int Sfreq = 100;
unsigned long Timer_count = ceil(((16*10^6) / (Sfreq*1024) - 1));
voidSetup(){
// Previous timer code
OCR1A = 156; //-----> I want to set this number to Timer_count such that OCR1A = Timer_count
//After timer code
}
Because the draw() function is going to be executed roughly 60 times per second, the OCR1A variable is going to be assigned to the Timer_count value that is related to the Sfreq value.
If you used setup() to assign your variables, then the function would only be executed once at startup and it’s not updating in real time.
Your code is from arduino IDE, not Processing IDE.
Try the arduino Forum instead, since your problem is related to arduino code.
Here is the link to it: https://forum.arduino.cc/