/* Digital VFO with Rotation Dial File: VFOsys2.ino Author: JF3HZB / T.UEBO Created on July 1, 2023 Board manager: esp32 ver. 2.0.9 Board: ESP32 Dev Module Library: LovyanGFX ver. 1.1.16 Ver. 2.00 July 1, 2023 Ver. 2.20 Aug. 3, 2024 1. Changed the font of digital frequency display to Nixie tube like. 2. Added the function for dial lamp emulation. */ #define NAME "VFO System" #define VERSION "Ver. 2.20" #define ID "by JF3HZB" #include "dial.hpp" #include "si5351.h" #include "driver/pcnt.h" LGFX lcd; LGFX_Sprite sp; LGFX_Sprite sprites[2]; bool flip; int sprite_height; DIAL dial; #define PULSE_INPUT_PIN 16 // Rotaty Encoder A #define PULSE_CTRL_PIN 17 // Rotaty Encoder B /*------------------------------------------------------- Frequency settings --------------------------------------------------------*/ #define init_frq 7100000 // Initial Frequncy[Hz] int32_t offset_frq = 9000000; // Offset Frequency[Hz] int32_t car_frq = 8998500; // Carrier Frequncy[Hz] #define max_frq 200000000 // Max frequency[Hz] #define min_frq 10000 // Min frequency[Hz] /*---------------------------------------------------------- Adaptive step control parameters -----------------------------------------------------------*/ #define vth 3 // Velocity threshold for acceleration #define Racc 500 // Rate of acceleration #define Rdec 1000 // Rate of deceleration #define freq_step 10 // Min step[Hz] #define MAX_Step 10000 // [Hz] float L=0.0; float inv_Tacc=Racc*1.0e-8; float MaxL = sqrt( (MAX_Step - freq_step)/inv_Tacc ); int32_t afstp; int16_t RE_Count = 0; /*---------------------------------------------------------------------------------- Control flags -----------------------------------------------------------------------------------*/ uint8_t f_fchange = 1; // if frequency changed, set this flag to 1 uint8_t f_cchange = 1; // if Car frequency and/or "f_carON" changed, set this flag to 1 uint8_t f_carON = 0; // ON(1)/OFF(0) Car signal int32_t Dial_frq; int velocity = 0; int velo[16]; int pt_v = 0; TaskHandle_t H_Task; /*-------------------------------------------------- core 0 Alt_Thread() ---------------------------------------------------*/ void Alt_Thread(void *args) { delay(200); si5351_init(); Dial_frq = init_frq; set_freq(Dial_frq); set_car_freq(car_frq, f_carON, 0); while (1) { // Encoder pcnt_get_counter_value(PCNT_UNIT_0, &RE_Count); #ifdef REV_ENCODER int count=-RE_Count; #else if int count=RE_Count; #endif pcnt_counter_clear(PCNT_UNIT_0); velo[pt_v]=abs(count); pt_v++; if(pt_v>16) pt_v=0; velocity = 0; for(int i=0; i<16; i++) velocity+=velo[i]; // Step control if(count!=0){ afstp=(int32_t)(0.5 + (float)(count)*( (float)freq_step + L*L*inv_Tacc) ); if(velocity >= vth ) L+=1.0*(float)( velocity - vth ); if(L>MaxL) L=MaxL; }else{ L-=(float)Rdec; if(L<0) L=0; } // Update frequency if(afstp!=0){ int32_t tfrq=Dial_frq; tfrq+=afstp; tfrq = (tfrq/freq_step)*freq_step; if(tfrq>max_frq) tfrq=max_frq; if(tfrq