I took and old version and added conditional assembly code. Have not done it for a real recent version.
You add stuff in setup to get interrupt going too.
You substitute the tuning code.
you add the interrupt
Here is the original "dotunning" for Pot. I made the same function so it interfaces with original code.
This is just a hack to get rotary working and be able to switch back with commenting out #define ENCODER
My bump switch sets the "Step" Hz amount. This (for now) clobbers out stuff on line 2.
So this is just a start, but runs with an Encoder.
this is NOT Encoder, see below code for tuning with encoder'
I am ON PAGE 100 of Jacks wonderful C Book!
Mike, WA6ISP
.........................................................................................................
#ifndef ENCODER
//***
/**
The Tuning mechanism of the Raduino works in a very innovative way. It uses a tuning potentiometer.
The tuning potentiometer that a voltage between 0 and 5 volts at ANALOG_TUNING pin of the control connector.
This is read as a value between 0 and 1000. By 100x oversampling ths range is expanded by a factor 10.
Hence, the tuning pot gives you 10,000 steps from one end to the other end of its rotation. Each step is 50 Hz,
thus giving maximum 500 Khz of tuning range. The tuning range is scaled down depending on the limit settings.
The standard tuning range (for the standard 1-turn pot) is 50 Khz. But it is also possible to use a 10-turn pot
to tune accross the entire 40m band. In that case you need to change the values for TUNING_RANGE and baseTune.
When the potentiometer is moved to either end of the range, the frequency starts automatically moving
up or down in 10 Khz increments
*/
void doTuning() {
long knob = knob_position(); // get the current tuning knob position
// the knob is fully on the low end, move down by 10 Khz and wait for 200 msec
if (knob < -80 && frequency > LOWEST_FREQ) {
baseTune = baseTune - 10000L;
frequency = baseTune + (50L * knob * TUNING_RANGE / 500);
updateDisplay();
setFrequency(frequency);
delay(200);
}
// the knob is full on the high end, move up by 10 Khz and wait for 200 msec
else if (knob > 10120L && frequency < HIGHEST_FREQ) {
baseTune = baseTune + 10000L;
frequency = baseTune + (50L * knob * TUNING_RANGE / 500);
setFrequency(frequency);
updateDisplay();
delay(200);
}
// the tuning knob is at neither extremities, tune the signals as usual ("flutter fix" by Jerry, KE7ER)
else if (knob != old_knob) {
static byte dir_knob;
if ( (knob > old_knob) && ((dir_knob == 1) || ((knob - old_knob) > 5)) ||
(knob < old_knob) && ((dir_knob == 0) || ((old_knob - knob) > 5)) ) {
if (knob > old_knob) {
dir_knob = 1;
frequency = baseTune + (50L * (knob - 5) * TUNING_RANGE / 500);
} else {
dir_knob = 0;
frequency = baseTune + (50L * knob * TUNING_RANGE / 500);
}
old_knob = knob;
setFrequency(frequency);
updateDisplay();
}
}
if (vfoActive == VFO_A)
vfoA = frequency;
else
vfoB = frequency;
}
#endif
This is new Do Tunning for Encoder
//***
#ifdef ENCODER
void doTuning() {
//****
//Read Encoder Bump Switch
if (!digitalRead(BUTTONSW)) {
delay(1);
unsigned long Time = millis();
while ( !digitalRead(BUTTONSW) && ( (millis() - Time) < 1000) ) {
delay(1);
T1++;
}
if (digitalRead(BUTTONSW)) {
Bumps++;
}
}
if (Bumps > 3) Bumps = 0;
#ifdef DEBUG
Serial.print("Bumps = ");
Serial.println(Bumps);
#endif
lcd.setCursor(0, 1);
lcd.print("Step=");
switch (Bumps) {
// case 0:
// Steps = TENS;
// lcd.print(msgten);
// break;
case 0:
Steps = HUND;
lcd.print(msgh);
break;
case 1:
Steps = KIL001;
lcd.print(msg1k);
break;
case 2:
Steps = KIL010;
lcd.print(msg10k);
break;
case 3:
Steps = KIL100;
lcd.print(msg100k);
break;
default:
Steps = KIL001;
lcd.print(msg1k);
Bumps = 0;
break;
}
if (frequency >= 7350000UL) frequency = 7350000UL;
if (frequency <= 7000000UL) frequency = 7000000UL;
/*
if (Move == -1) {
frequency += Steps; //1KHz = 1000
}
if (Move == +1) {
frequency -= Steps;
}
*/
setFrequency(frequency);
updateDisplay();
Move = 0;
if (vfoActive == VFO_A)
vfoA = frequency;
else
vfoB = frequency;
}
#endif
Then the interrupt....
// The Interrupt from Rotary Lib
// Increments or Decriments Move variable
ISR(PCINT2_vect) {
unsigned char result = r.process();
if (result == DIR_CW) {
// Serial.println("ClockWise");
frequency += Steps; //1KHz = 1000
}
else if (result == DIR_CCW) {
// Serial.println("CounterClockWise");
frequency -= Steps; //1KHz = 1000
}
}
And in SETUP>>>>>>>>>>>>>>>//***
//Encoder
//
#ifdef ENCODER
pinMode(BUTTONSW, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
PCICR |= (1 << PCIE2);
PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
sei();
#endif
--
Mike Hagen, WA6ISP
10917 Bryant Street
Yucaipa, Ca. 92399
(909) 918-0058
PayPal ID "MotDog@..."
Mike@...