So i have built a type of AM radio signal generator. It currently uses a preset value to generate the carrier signal, it is very simple ill add pictures of the circuit it has a voltage divider using 2x 10k ohm resistors with wires connecting them from-to::
{1: headphone ground wire to ground pin}
{2: positive headphone wire (over a 10uf capacitor) to A0 pin}
{3: a jumper wire connectig to the analog reference pin AREF}
here is the code i have got working for me on a Arduino uno SMD.
As i said earlier i have a preset value "fTransmit" for the carrier signal, and by changing it i therby change the transmission frequency because what i have done to calculate the transmision frequency is i first calculate "C" which i store in the OUTPUT COMPARE REGISTER x A
C= cpu_clock_speed/2nsignal-1
and now ican calculate the frequency
fw = cpu_clock_speed/(2nC+1)
my question is, if possible at all, how could i instead of having a preset value use a potenciometer to set the value for "fTransmit"
and also if it can be done continiouslly without having to reset the arduino in order to "wiggle" the transmission frequency
Blockquote
#define ANTENNA_PIN PB3 //Arduino Nano/Uno D11
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(250000);
//scalar//
int N;
N = 1024; //prescalar
//Kod za frekvenciju signala nosaca 'carier signal'
uint32_t fTransmit = 650; //KHz
DDRB |= (1 << ANTENNA_PIN);
TCCR2A = (0 << COM2A1) + (1 << COM2A0);
TCCR2A |= (1 << WGM21) + (0 << WGM20);
TCCR2B = (0 << CS22) + (0 << CS21) + (1 << CS20);
//frekvencija signala sacuvana u "OUTPUT COMPARE REGISTER x A//
OCR2A = (F_CPU / 2*N* fTransmit - 1;
int AMfrekvencija;
AMfrekvencija = F_CPU/(2*N*OCR2A+1);
Serial.println(AMfrekvencija);
//PWM Signal
TCCR1A |= (1 << WGM11) + (1 << WGM10); //"Fast PWM" 10 Bit
TCCR1B = (1 << WGM12);
TCCR1B |= (0 << CS12) + (0 << CS11) + (1 << CS10);
TIMSK1 = (1 << OCIE1A) + (1 << TOIE1);
//ADC Settings
ADMUX = (1 << REFS1) + (1 << REFS0); // Referenca je interna 1.1 v (analog reference pin AREF)
ADCSRA = (1 << ADEN) + (1 << ADSC) + (1 << ADATE);
ADCSRA |= (1 << ADPS2) + (1 << ADPS1) + (0 << ADPS0); Brzina samplovanja
DIDR0 = (1 << ADC0D);
}
ISR(TIMER1_OVF_vect) {
uint8_t adcl = ADCL;
uint8_t adch = ADCH;
OCR1A = (adch << 8) + adcl;
DDRB |= (1 << ANTENNA_PIN);
}
ISR(TIMER1_COMPA_vect) {
DDRB &= ~(1 << ANTENNA_PIN);
}
void loop() {
}
Blockquote