Уважаемые коллеги,
собрал вот такой простой синтезатор на SI5351 + ArduinoUno: (https://amoghdesai.com/technology/el.../#comment-3487), вроде бы работает корректно, на LCD меняется частота и шаг, но частотомер на выходах CL0, CL1, CL2 ничего не показывает. Скетч ниже:
#include <Rotary.h>
#include <si5351.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#define F_MIN 1000000L // Lower frequency limit
#define F_MAX 30000000L
#define OLED_RESET 4
#define ENCODER_A 3 // Encoder pin A
#define ENCODER_B 2 // Encoder pin B
#define ENCODER_BTN 11
#define LCD_RS 5
#define LCD_E 6
#define LCD_D4 7
#define LCD_D5 8
#define LCD_D6 9
#define LCD_D7 10
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7); // LCD - pin assignement in
Si5351 si5351;
Rotary r = Rotary(ENCODER_A, ENCODER_B);
volatile uint32_t vfo = 14200000L; //start freq - change to suit
volatile uint32_t LSB = 8999500L; //change these to suit your needs
volatile uint32_t USB = 9001500L;
volatile uint32_t bfo = 9001500L; //start bfo freq
volatile uint32_t radix = 100; //start step size
boolean changed_f = 0;
String tbfo = "USB";
/******************** ******************/
/* Interrupt service routine for */
/* encoder frequency change */
/******************** ******************/
ISR(PCINT2_vect) {
unsigned char result = r.process();
if (result == DIR_CW)
set_frequency(1);
else if (result == DIR_CCW)
set_frequency(-1);
}
void set_frequency(short dir)
{
if(dir == 1)
vfo += radix;
if(dir == -1)
vfo -= radix;
if(vfo > F_MAX)
vfo = F_MAX;
if(vfo < F_MIN)
vfo = F_MIN;
changed_f = 1;
}
boolean get_button()
{
if(!digitalRead(ENCO DER_BTN))
{
delay(20);
if(!digitalRead(ENCO DER_BTN))
{
while(!digitalRead(E NCODER_BTN));
return 1;
}
}
return 0;
}
void display_frequency()
{
uint16_t f, g;
lcd.setCursor(4, 0);
f = vfo / 1000000; //variable is now vfo instead of 'frequency'
if(f<10)
lcd.print(' ');
lcd.print(f);
lcd.print('.');
f = (vfo % 1000000)/1000;
if(f<100)
lcd.print('0');
if(f<10)
lcd.print('0');
lcd.print(f);
lcd.print('.');
f = vfo % 1000;
if(f<100)
lcd.print('0');
if(f<10)
lcd.print('0');
lcd.print(f);
lcd.print("Hz");
lcd.setCursor(0, 1);
lcd.print(tbfo);
Serial.println(vfo + bfo);
Serial.println(tbfo) ;
}
void display_radix()
{
lcd.setCursor(10, 1);
switch(radix)
{
case 10:
lcd.print(" 10");
break;
case 100:
lcd.print(" 100");
break;
case 1000:
lcd.print(" 1k");
break;
case 10000:
lcd.print(" 10k");
break;
case 100000:
lcd.print("100k");
break;
}
lcd.print("Hz");
}
void setup()
{
Serial.begin(19200);
lcd.begin(16, 2); // Initialize and clear the LCD
lcd.clear();
Wire.begin();
// Start serial and initialize the Si5351
si5351.init(SI5351_C RYSTAL_LOAD_10PF, 0);
// Set CLK0 to output 14 MHz with a fixed PLL frequency
si5351.set_pll(SI535 1_PLL_FIXED, SI5351_PLLA);
si5351.set_freq(vfo, SI5351_PLL_FIXED, SI5351_CLK0);
// Set CLK1 to output 20 MHz
//si5351.set_freq(freq uency1, 0, SI5351_CLK1);
// Set CLK2 to output 15 MHz
si5351.set_freq( bfo, 0, SI5351_CLK2);
si5351.drive_strengt h(SI5351_CLK0,SI5351 _DRIVE_2MA);
si5351.drive_strengt h(SI5351_CLK1,SI5351 _DRIVE_2MA);
si5351.drive_strengt h(SI5351_CLK2,SI5351 _DRIVE_2MA);
pinMode(ENCODER_BTN, INPUT_PULLUP);
PCICR |= (1 << PCIE2); // Enable pin change interrupt for the encoder
PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
sei();
display_frequency(); // Update the display
display_radix();
}
void loop()
{
// Update the display if the frequency has been changed
if(changed_f)
{
display_frequency();
si5351.set_freq(vfo + bfo, SI5351_PLL_FIXED, SI5351_CLK0);
if(vfo >= 10000000L & tbfo != "USB")
{
bfo = USB;
tbfo = "USB";
si5351.set_freq( bfo, 0, SI5351_CLK2);
Serial.println("We'v e switched from LSB to USB");
}
else if(vfo < 10000000L & tbfo != "LSB")
{
bfo = LSB;
tbfo = "LSB";
si5351.set_freq( bfo, 0, SI5351_CLK2);
Serial.println("We'v e switched from USB to LSB");
}
changed_f = 0;
}
// Button press changes the frequency change step
if(get_button())
{
switch(radix)
{
case 10:
radix = 100;
break;
case 100:
radix = 1000;
break;
case 1000:
radix = 10000;
break;
case 10000:
radix = 100000;
break;
case 100000:
radix = 10;
break;
}
display_radix();
}
}
Буду очень благодарен за помощь!