Hi there,
i´m pretty sure this problem got mentioned elsewhere, but i can´t find a proper solution to this and somehow in can´t accept that this is it now ....
I´m into building a CV controlled FM Radio for modular synthesizers with an Arduino DIY and SMT assembled.
I got everything running pretty well, but there´s one thing on arduino´s side that kills it all.
It´s about the clicking / ticking while reading out the analog in for adjusting the frequency.
I kinda know why it happens, but i don´t know how to prevent.
Does anyone in here have a solution?
#include <Wire.h>
unsigned char frequencyH = 0;
unsigned char frequencyL = 0;
unsigned int frequencyB;
double frequency = 0;
void setup()
{
Wire.begin();
frequency = 106.8; //starting frequency
setFrequency();
//Serial.begin(9600);
}
void loop()
{
int reading = analogRead(0);
frequency = map((float)reading, 0.0, 1024.0, 87.5, 108.0);
frequency = ((double)reading * (108.0 - 87.5)) / 1024.0 + 87.5;
frequency = ((int)(frequency * 10)) / 10.0;
setFrequency();
Serial.println(frequency);
}
void setFrequency()
{
static byte freqH=0;
static byte freqL = 0;
frequencyB = 4 * (frequency * 1000000 + 225000) / 32768;
frequencyH = frequencyB >> 8;
frequencyL = frequencyB & 0XFF;
if ((frequencyH == freqH) && (frequencyL == freqL)) return; // no change
freqH= frequencyH;
freqL= frequencyL;
Wire.beginTransmission(0x60);
Wire.write(frequencyH);
Wire.write(frequencyL);
Wire.write(0xB0);
Wire.write(0x10);
Wire.write((byte)0x00);
Wire.endTransmission();
delay(120);
}