Using a potenciometar to set variable value

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}
circuit

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

The problem is that it takes time to read the analogue input pin, about 10mS. This will interfere with your signal timing.
One way round it might be to set the A/D into free running mode and read if the conversion has finished in your loop, if the A/D reading is a different value by say four from the last time you took a reading.

If it has then read the full value and calculate the new value. This would cause any signal disruption only to new readings.

1 Like

I moved your topic to an appropriate forum category @bronga.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

@pert
sure thing, sorry i missed it. Thank you for your help

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.