Added CWL, CWU Mode, need test

This commit is contained in:
phdlee 2018-01-30 13:20:52 +09:00
parent 98c26730c6
commit 0d9ec08bd7
6 changed files with 340 additions and 57 deletions

View File

@ -130,10 +130,21 @@ void CatGetFreqMode(unsigned long freq, byte fromType)
}
//Mode Check
if (cwMode == 0)
{
if (isUSB)
CAT_BUFF[4] = CAT_MODE_USB;
else
CAT_BUFF[4] = CAT_MODE_LSB;
}
else if (cwMode == 1)
{
CAT_BUFF[4] = CAT_MODE_CW;
}
else
{
CAT_BUFF[4] = CAT_MODE_CW;
}
SendCatData(5);
}
@ -198,12 +209,18 @@ void CatSetMode(byte tmpMode, byte fromType)
if (!inTx)
{
if (tmpMode == CAT_MODE_USB)
if (tmpMode == CAT_MODE_CW)
{
cwMode = 1;
}
else if (tmpMode == CAT_MODE_USB)
{
cwMode = 0;
isUSB = true;
}
else
{
cwMode = 0;
isUSB = false;
}
@ -358,10 +375,21 @@ void ReadEEPRom_FT817(byte fromType)
CAT_BUFF[1] = 0xB2;
break; case 0x69 : //FM Mic (#29) Contains 0-100 (decimal) as displayed
case 0x78 :
if (cwMode == 0)
{
if (isUSB)
CAT_BUFF[0] = CAT_MODE_USB;
else
CAT_BUFF[0] = CAT_MODE_LSB;
}
else if (cwMode == 1)
{
CAT_BUFF[0] = CAT_MODE_CW;
}
else if (cwMode == 2)
{
CAT_BUFF[0] = CAT_MODE_CW;
}
if (CAT_BUFF[0] != 0) CAT_BUFF[0] = 1 << 5;
break;

View File

@ -151,6 +151,7 @@ int count = 0; //to generally count ticks, loops, etc
#define CW_SPEED 28
//AT328 has 1KBytes EEPROM
#define CW_CAL 252
#define VFO_A_MODE 256
#define VFO_B_MODE 257
#define CW_DELAY 258
@ -232,7 +233,7 @@ int count = 0; //to generally count ticks, loops, etc
char ritOn = 0;
char vfoActive = VFO_A;
int8_t meter_reading = 0; // a -1 on meter makes it invisible
unsigned long vfoA=7150000L, vfoB=14200000L, sideTone=800, usbCarrier;
unsigned long vfoA=7150000L, vfoB=14200000L, sideTone=800, usbCarrier, cwmCarrier;
unsigned long vfoA_eeprom, vfoB_eeprom; //for protect eeprom life
unsigned long frequency, ritRxFrequency, ritTxFrequency; //frequency is the current frequency on the dial
@ -300,6 +301,10 @@ char inTx = 0; //it is set to 1 if in transmit mode (whatever the
char splitOn = 0; //working split, uses VFO B as the transmit frequency
char keyDown = 0; //in cw mode, denotes the carrier is being transmitted
char isUSB = 0; //upper sideband was selected, this is reset to the default for the
char cwMode = 0; //compatible original source, and extend mode //if cwMode == 0, mode check : isUSB, cwMode > 0, mode Check : cwMode
//iscwMode = 0 : ssbmode, 1 :cwl, 2 : cwu, 3 : cwn (none tx)
//frequency when it crosses the frequency border of 10 MHz
byte menuOn = 0; //set to 1 when the menu is being displayed, if a menu item sets it to zero, the menu is exited
unsigned long cwTimeout = 0; //milliseconds to go before the cw transmit line is released and the radio goes back to rx mode
@ -363,8 +368,10 @@ void setNextHamBandFreq(unsigned long f, char moveDirection)
EEPROM.get(HAM_BAND_FREQS + 4 * findedIndex, resultFreq);
loadMode = (byte)(resultFreq >> 30);
resultFreq = resultFreq & 0x3FFFFFFF;
//loadMode = (byte)(resultFreq >> 30);
//resultFreq = resultFreq & 0x3FFFFFFF;
loadMode = (byte)(resultFreq >> 29);
resultFreq = resultFreq & 0x1FFFFFFF;
if ((resultFreq / 1000) < hamBandRange[(unsigned char)findedIndex][0] || (resultFreq / 1000) > hamBandRange[(unsigned char)findedIndex][1])
resultFreq = (unsigned long)(hamBandRange[(unsigned char)findedIndex][0]) * 1000;
@ -375,7 +382,8 @@ void setNextHamBandFreq(unsigned long f, char moveDirection)
void saveBandFreqByIndex(unsigned long f, unsigned long mode, char bandIndex) {
if (bandIndex >= 0)
EEPROM.put(HAM_BAND_FREQS + 4 * bandIndex, (f & 0x3FFFFFFF) | (mode << 30) );
//EEPROM.put(HAM_BAND_FREQS + 4 * bandIndex, (f & 0x3FFFFFFF) | (mode << 30) );
EEPROM.put(HAM_BAND_FREQS + 4 * bandIndex, (f & 0x1FFFFFFF) | (mode << 29) );
}
/*
@ -471,6 +479,8 @@ void setFrequency(unsigned long f){
setTXFilters(f);
if (cwMode == 0)
{
if (isUSB){
si5351bx_setfreq(2, SECOND_OSC_USB - usbCarrier + f);
si5351bx_setfreq(1, SECOND_OSC_USB);
@ -479,6 +489,18 @@ void setFrequency(unsigned long f){
si5351bx_setfreq(2, SECOND_OSC_LSB + usbCarrier + f);
si5351bx_setfreq(1, SECOND_OSC_LSB);
}
}
else
{
if (cwMode == 1){ //CWL
si5351bx_setfreq(2, SECOND_OSC_LSB + cwmCarrier + f);
si5351bx_setfreq(1, SECOND_OSC_LSB);
}
else{ //CWU
si5351bx_setfreq(2, SECOND_OSC_USB - cwmCarrier + f);
si5351bx_setfreq(1, SECOND_OSC_USB);
}
}
frequency = f;
}
@ -530,11 +552,23 @@ void startTx(byte txMode, byte isDisplayUpdate){
//shif the first oscillator to the tx frequency directly
//the key up and key down will toggle the carrier unbalancing
//the exact cw frequency is the tuned frequency + sidetone
if (cwMode == 0)
{
if (isUSB)
si5351bx_setfreq(2, frequency + sideTone);
else
si5351bx_setfreq(2, frequency - sideTone);
}
else if (cwMode == 1) //CWL
{
si5351bx_setfreq(2, frequency - sideTone);
}
else //CWU
{
si5351bx_setfreq(2, frequency + sideTone);
}
}
//reduce latency time when begin of CW mode
if (isDisplayUpdate == 1)
@ -545,7 +579,11 @@ void stopTx(){
inTx = 0;
digitalWrite(TX_RX, 0); //turn off the tx
if (cwMode == 0)
si5351bx_setfreq(0, usbCarrier); //set back the carrier oscillator anyway, cw tx switches it off
else
si5351bx_setfreq(0, cwmCarrier); //set back the carrier oscillator anyway, cw tx switches it off
if (ritOn)
setFrequency(ritRxFrequency);
@ -788,6 +826,7 @@ void initSettings(){
if (EEPROM.read(VERSION_ADDRESS) != VERSION_NUM)
EEPROM.write(VERSION_ADDRESS, VERSION_NUM);
EEPROM.get(CW_CAL, cwmCarrier);
//for Save VFO_A_MODE to eeprom
//0: default, 1:not use, 2:LSB, 3:USB, 4:CW, 5:AM, 6:FM
@ -937,6 +976,9 @@ void initSettings(){
if (usbCarrier > 12010000l || usbCarrier < 11990000l)
usbCarrier = 11995000l;
if (cwmCarrier > 12010000l || cwmCarrier < 11990000l)
cwmCarrier = 11995000l;
if (vfoA > 35000000l || 3500000l > vfoA) {
vfoA = 7150000l;
vfoA_mode = 2;
@ -1020,7 +1062,7 @@ void setup()
//Serial.begin(9600);
lcd.begin(16, 2);
printLineF(1, F("CECBT v0.32"));
printLineF(1, F("CECBT v0.33"));
Init_Cat(38400, SERIAL_8N1);
initMeter(); //not used in this build
@ -1038,11 +1080,12 @@ void setup()
}
initPorts();
byteToMode(vfoA_mode);
initOscillators();
frequency = vfoA;
saveCheckFreq = frequency; //for auto save frequency
byteToMode(vfoA_mode);
setFrequency(vfoA);
updateDisplay();

View File

@ -37,6 +37,7 @@ void factory_alignment(){
printLine2("#3:Test 3.5MHz");
cwMode = 0;
isUSB = false;
setFrequency(3500000l);
updateDisplay();
@ -59,6 +60,7 @@ void factory_alignment(){
btnWaitForClick();
printLine2("#5:Test 14MHz");
cwMode = 0;
isUSB = true;
setFrequency(14000000l);
updateDisplay();
@ -80,6 +82,7 @@ void factory_alignment(){
printLine2("Alignment done");
delay(1000);
cwMode = 0;
isUSB = false;
setFrequency(7150000l);
updateDisplay();

View File

@ -119,30 +119,56 @@ void menuBand(int btn){
}
//Convert Mode, Number by KD8CEC
//0: default, 1:not use, 2:LSB, 3:USB, 4:CW, 5:AM, 6:FM
//0: default, 1:not use, 2:LSB, 3:USB, 4:CWL, 5:CWU, 6:FM
byte modeToByte(){
if (cwMode == 0)
{
if (isUSB)
return 3;
else
return 2;
}
else if (cwMode == 1)
{
return 4;
}
else
{
return 5;
}
}
//Convert Number to Mode by KD8CEC
void byteToMode(byte modeValue){
if (modeValue == 4)
cwMode = 1;
else if (modeValue == 5)
cwMode = 2;
else
{
cwMode = 0;
if (modeValue == 3)
isUSB = 1;
else
isUSB = 0;
}
}
//Convert Number to Mode by KD8CEC
void byteWithFreqToMode(byte modeValue){
if (modeValue == 4)
cwMode = 1;
else if (modeValue == 5)
cwMode = 2;
else {
cwMode = 0;
if (modeValue == 3)
isUSB = 1;
else if (modeValue == 0) //Not Set
isUSB = (frequency > 10000000l) ? true : false;
else
isUSB = 0;
}
}
//VFO Toggle and save VFO Information, modified by KD8CEC
@ -212,6 +238,7 @@ void menuRitToggle(int btn){
}
}
/*
void menuSidebandToggle(int btn){
if (!btn){
if (isUSB == true)
@ -220,6 +247,7 @@ void menuSidebandToggle(int btn){
printLineF2(F("Select USB?"));
}
else {
cwMode = 0;
if (isUSB == true){
isUSB = false;
printLineF2(F("LSB Selected"));
@ -234,6 +262,108 @@ void menuSidebandToggle(int btn){
menuOn = 0;
}
}
*/
void menuSelectMode(int btn){
int knob = 0;
int selectModeType = 0;
int beforeMode = 0;
int moveStep = 0;
if (!btn){
printLineF2(F("Select Mode?"));
}
else {
delay_background(500, 0);
//LSB, USB, CWL, CWU
if (cwMode == 0 && isUSB == 0)
selectModeType = 0;
else if (cwMode == 0 && isUSB == 1)
selectModeType = 1;
else if (cwMode == 1)
selectModeType = 2;
else
selectModeType = 3;
beforeMode = selectModeType;
while(!btnDown() && digitalRead(PTT) == HIGH){
//Display Mode Name
if (selectModeType == 0)
printLineF1(F("LSB"));
else if (selectModeType == 1)
printLineF1(F("USB"));
else if (selectModeType == 2)
printLineF1(F("CWL"));
else if (selectModeType == 3)
printLineF1(F("CWU"));
knob = enc_read();
if (knob != 0)
{
moveStep += (knob > 0 ? 1 : -1);
if (moveStep < -3) {
if (selectModeType > 0)
selectModeType--;
moveStep = 0;
}
else if (moveStep > 3) {
if (selectModeType < 3)
selectModeType++;
moveStep = 0;
}
}
Check_Cat(0); //To prevent disconnections
}
if (beforeMode != selectModeType) {
printLineF1(F("Changed Mode"));
if (selectModeType == 0) {
cwMode = 0; isUSB = 0;
}
else if (selectModeType == 1) {
cwMode = 0; isUSB = 1;
}
else if (selectModeType == 2) {
cwMode = 1;
}
else if (selectModeType == 3) {
cwMode = 2;
}
//Save Frequency & Mode Information
if (vfoActive == VFO_A)
{
vfoA = frequency;
vfoA_mode = modeToByte();
storeFrequencyAndMode(1);
}
else
{
vfoB = frequency;
vfoB_mode = modeToByte();
storeFrequencyAndMode(2);
}
}
if (cwMode == 0)
si5351bx_setfreq(0, usbCarrier); //set back the carrier oscillator anyway, cw tx switches it off
else
si5351bx_setfreq(0, cwmCarrier); //set back the carrier oscillator anyway, cw tx switches it off
setFrequency(frequency);
delay_background(500, 0);
printLine2ClearAndUpdate();
menuOn = 0;
}
}
void menuSplitOnOff(int btn){
if (!btn){
@ -325,11 +455,13 @@ void menuSetupKeyType(int btn){
if (knob != 0)
{
moveStep += (knob > 0 ? 1 : -1);
if (selectedKeyType > 0 && moveStep < -3) {
if (moveStep < -3) {
if (selectedKeyType > 0)
selectedKeyType--;
moveStep = 0;
}
else if (selectedKeyType < 2 && moveStep > 3) {
else if (moveStep > 3) {
if (selectedKeyType < 2)
selectedKeyType++;
moveStep = 0;
}
@ -709,6 +841,7 @@ void factoryCalibration(int btn){
calibration = 0;
cwMode = 0;
isUSB = true;
//turn off the second local oscillator and the bfo
@ -837,7 +970,7 @@ void printCarrierFreq(unsigned long freq){
strcat(c, ".");
strncat(c, &b[2], 3);
strcat(c, ".");
strncat(c, &b[5], 1);
strncat(c, &b[5], 3);
printLine2(c);
}
@ -889,12 +1022,71 @@ void menuSetupCarrier(int btn){
else
usbCarrier = prevCarrier;
si5351bx_setfreq(0, usbCarrier);
//si5351bx_setfreq(0, usbCarrier);
if (cwMode == 0)
si5351bx_setfreq(0, usbCarrier); //set back the carrier oscillator anyway, cw tx switches it off
else
si5351bx_setfreq(0, cwmCarrier); //set back the carrier oscillator anyway, cw tx switches it off
setFrequency(frequency);
printLine2ClearAndUpdate();
menuOn = 0;
}
//Append by KD8CEC
void menuSetupCWCarrier(int btn){
int knob = 0;
unsigned long prevCarrier;
if (!btn){
printLineF2(F("Set CW RX BFO"));
return;
}
prevCarrier = cwmCarrier;
printLineF1(F("PTT to confirm. "));
delay_background(1000, 0);
si5351bx_setfreq(0, cwmCarrier);
printCarrierFreq(cwmCarrier);
//disable all clock 1 and clock 2
while (digitalRead(PTT) == HIGH && !btnDown())
{
knob = enc_read();
if (knob > 0)
cwmCarrier -= 5;
else if (knob < 0)
cwmCarrier += 5;
else
continue; //don't update the frequency or the display
si5351bx_setfreq(0, cwmCarrier);
printCarrierFreq(cwmCarrier);
Check_Cat(0); //To prevent disconnections
delay(100);
}
//save the setting
if (digitalRead(PTT) == LOW){
printLineF2(F("Carrier set!"));
EEPROM.put(CW_CAL, cwmCarrier);
delay_background(1000, 0);
}
else
cwmCarrier = prevCarrier;
if (cwMode == 0)
si5351bx_setfreq(0, usbCarrier); //set back the carrier oscillator anyway, cw tx switches it off
else
si5351bx_setfreq(0, cwmCarrier); //set back the carrier oscillator anyway, cw tx switches it off
setFrequency(frequency);
printLine2ClearAndUpdate();
menuOn = 0;
}
//Modified by KD8CEC
void menuSetupCwTone(int btn){
int knob = 0;
@ -1051,7 +1243,7 @@ void doMenu(){
btnState = btnDown();
if (i > 0){
if (modeCalibrate && select + i < 180)
if (modeCalibrate && select + i < 190)
select += i;
if (!modeCalibrate && select + i < 80)
select += i;
@ -1069,7 +1261,7 @@ void doMenu(){
else if (select < 30)
menuVfoToggle(btnState, 1);
else if (select < 40)
menuSidebandToggle(btnState);
menuSelectMode(btnState);
else if (select < 50)
menuCWSpeed(btnState);
else if (select < 60)
@ -1083,20 +1275,22 @@ void doMenu(){
else if (select < 100 && modeCalibrate)
menuSetupCarrier(btnState); //lsb
else if (select < 110 && modeCalibrate)
menuSetupCwTone(btnState);
menuSetupCWCarrier(btnState); //lsb
else if (select < 120 && modeCalibrate)
menuSetupCwDelay(btnState);
menuSetupCwTone(btnState);
else if (select < 130 && modeCalibrate)
menuSetupTXCWInterval(btnState);
menuSetupCwDelay(btnState);
else if (select < 140 && modeCalibrate)
menuSetupKeyType(btnState);
menuSetupTXCWInterval(btnState);
else if (select < 150 && modeCalibrate)
menuADCMonitor(btnState);
menuSetupKeyType(btnState);
else if (select < 160 && modeCalibrate)
menuSplitOnOff(btnState); //TX OFF / ON
menuADCMonitor(btnState);
else if (select < 170 && modeCalibrate)
menuTxOnOff(btnState, 0x01); //TX OFF / ON
menuSplitOnOff(btnState); //SplitOn / off
else if (select < 180 && modeCalibrate)
menuTxOnOff(btnState, 0x01); //TX OFF / ON
else if (select < 190 && modeCalibrate)
menuExit(btnState);
Check_Cat(0); //To prevent disconnections

View File

@ -109,7 +109,11 @@ void initOscillators(){
//initialize the SI5351
si5351bx_init();
si5351bx_vcoa = (SI5351BX_XTAL * SI5351BX_MSA) + calibration; // apply the calibration correction factor
if (cwMode == 0)
si5351bx_setfreq(0, usbCarrier);
else
si5351bx_setfreq(0, cwmCarrier);
}

View File

@ -234,11 +234,22 @@ void updateDisplay() {
if (ritOn)
strcpy(c, "RIT ");
else {
if (cwMode == 0)
{
if (isUSB)
strcpy(c, "USB ");
else
strcpy(c, "LSB ");
}
else if (cwMode == 1)
{
strcpy(c, "CWL ");
}
else
{
strcpy(c, "CWU ");
}
}
if (vfoActive == VFO_A) // VFO A is active
strcat(c, "A:");
else