More reorg changes in the DSP code. Working towards creating a separate ADC 'process' that will continually update the applicable variables, and then they'll be reported upon request via I2C or Serial as applicable.

This commit is contained in:
Rob French 2021-01-21 22:00:35 -06:00
parent bb31ccfbe4
commit 16b350cb0f
2 changed files with 50 additions and 53 deletions

View File

@ -232,7 +232,7 @@ void sendCommand1Num(char varIndex, char sendValue)
//======================================================= //=======================================================
int i2cCommand = 0; int i2cCommand = 0;
void CalculateCoeff(uint8_t freqIndex); void calculateCoeff(uint8_t freqIndex);
char forwardBuff[MAX_FORWARD_BUFF_LENGTH + 1]; char forwardBuff[MAX_FORWARD_BUFF_LENGTH + 1];
static int nowBuffIndex = 0; static int nowBuffIndex = 0;
@ -249,7 +249,7 @@ char FFTToUartIdleCount = 0;
elapsedMillis sinceForward = 0; elapsedMillis sinceForward = 0;
uint8_t responseCommand = 0; // uint8_t responseCommand = 0; //
uint8_t TXStatus = 0; //0:RX, 1:TX bool isTX = false;
void responseConfig() void responseConfig()
{ {
if (responseCommand == 2) if (responseCommand == 2)
@ -357,7 +357,7 @@ char commandParser(int lastIndex)
else if (cmd1 >= 100 && cmd1 <= 145) else if (cmd1 >= 100 && cmd1 <= 145)
{ {
cwDecodeHz = cmd1 - 100; cwDecodeHz = cmd1 - 100;
CalculateCoeff(cwDecodeHz); calculateCoeff(cwDecodeHz);
DSPType = 2; DSPType = 2;
EEPROM.put(EEPROM_DSPTYPE, DSPType); EEPROM.put(EEPROM_DSPTYPE, DSPType);
EEPROM.put(EEPROM_CW_FREQ, cwDecodeHz); EEPROM.put(EEPROM_CW_FREQ, cwDecodeHz);
@ -383,12 +383,12 @@ char commandParser(int lastIndex)
{ {
if (commandVal == 0) //RX if (commandVal == 0) //RX
{ {
TXStatus = 0; isTX = false;
SMeterToUartIdleCount = 0; SMeterToUartIdleCount = 0;
} }
else if (commandVal == 1) //TX else if (commandVal == 1) //TX
{ {
TXStatus = 1; isTX = true;
SMeterToUartIdleCount = 0; SMeterToUartIdleCount = 0;
} }
} }
@ -462,7 +462,7 @@ void forwardData(void)
} }
} }
void SendMeterData(uint8_t isSend) void sendMeterData(uint8_t isSend)
{ {
//basic : 1.5Khz //basic : 1.5Khz
int newScaledSMeter = 0; int newScaledSMeter = 0;
@ -638,10 +638,16 @@ void setup()
Serial1.flush(); Serial1.flush();
SAMPLE_INTERVAL = round(1000000 * (1.0 / SAMPLE_FREQUENCY)); SAMPLE_INTERVAL = round(1000000 * (1.0 / SAMPLE_FREQUENCY));
//CalculateCoeff(cwDecodeHz); //Set 750Hz //9 * 50 + 300 = 750Hz //calculateCoeff(cwDecodeHz); //Set 750Hz //9 * 50 + 300 = 750Hz
//Serial1.println("Start..."); //Serial1.println("Start...");
} }
/*!
@brief Receive a command via I2C. The most recent command will be received, which will
indicate which data the DSP should be preparing to return.
@param numBytes
Number of bytes received--not used in this procedure.
*/
void i2cReceiveEvent(size_t numBytes) void i2cReceiveEvent(size_t numBytes)
{ {
int readCommand = 0; int readCommand = 0;
@ -649,6 +655,8 @@ void i2cReceiveEvent(size_t numBytes)
while (Wire1.available() > 0) // for Last command while (Wire1.available() > 0) // for Last command
{ {
readCommand = Wire1.read(); readCommand = Wire1.read();
// KC4UPR: Note that this looks to be only reading the last command, i.e.
// if multiple commands have been queued up, only the last will get executed.
} }
if (0x50 <= readCommand && readCommand <= 0x59) if (0x50 <= readCommand && readCommand <= 0x59)
@ -657,6 +665,10 @@ void i2cReceiveEvent(size_t numBytes)
} }
} }
/*!
@brief Respond to a request from the I2C Master (Raduino). Returns the appropriate data
based on whatever command was previously issued.
*/
void i2cRequestEvent(void) void i2cRequestEvent(void)
{ {
int maxValue = 0; int maxValue = 0;
@ -664,20 +676,16 @@ void i2cRequestEvent(void)
int readValue = 0; int readValue = 0;
unsigned long curr = 0; unsigned long curr = 0;
//if (nowADCSampling == 1) //Now Sampling ADC's switch (i2cCommand) {
//{ case I2CMETER_CALCS:
// nowADCSampling = 2; //when finished ADC Sampling, response I2CRequest Event // Returns an already-calculated S-meter value.
// return;
//} //end of if
if (i2cCommand == I2CMETER_CALCS)
{
Wire1.write(scaledSMeter); Wire1.write(scaledSMeter);
} break;
else if (i2cCommand == I2CMETER_UNCALCS)
{ case I2CMETER_UNCALCS:
//Wire1.write(ADC_DIFF); // Returns a raw signal strength value.
//8292Hz // KC4UPR: I'm going to replace this with a "process" that continually updates the ADC values.
// So then this would just grab the current value, and return it.
for(int i=0; i < 7; i++) for(int i=0; i < 7; i++)
{ {
curr = micros(); curr = micros();
@ -707,23 +715,32 @@ void i2cRequestEvent(void)
readValue = 255; readValue = 255;
} }
Wire1.write(readValue); Wire1.write(readValue);
} break;
else if (i2cCommand == I2CMETER_CALCP)
{ case I2CMETER_CALCP:
// Returns a raw forward power value.
// KC4UPR: I'm going to replace this with a "process" that continually updates the ADC values.
// So then this would just grab the current value, and return it.
readValue = analogRead(POWER_METER_ADC); //POWER readValue = analogRead(POWER_METER_ADC); //POWER
Wire1.write(readValue); Wire1.write(readValue);
} break;
else if (i2cCommand == I2CMETER_CALCR) //SWR
{ case I2CMETER_CALCR:
// Returns a raw reverse power value.
// KC4UPR: I'm going to replace this with a "process" that continually updates the ADC values.
// So then this would just grab the current value, and return it.
readValue = analogRead(SWR_METER_ADC); readValue = analogRead(SWR_METER_ADC);
Wire1.write(readValue); Wire1.write(readValue);
break;
default:
break;
} }
} }
extern void Decode_Morse(float magnitude); extern void Decode_Morse(float magnitude);
extern double coeff; extern double coeff;
#define LAST_TIME_INTERVAL 159 #define LAST_TIME_INTERVAL 159
//int SWRAdcValue = 0; //int SWRAdcValue = 0;
@ -759,30 +776,10 @@ void loop()
} }
//=========================================== //===========================================
//TRANSCEIVER STATUS : RX // TRANSCEIVER STATUS : TX
//=========================================== //===========================================
if (TXStatus == 1) //TX Mode if (isTX) //TX Mode
{ {
/*
int readValue = 0;
SMeterToUartIdleCount++;
if (SMeterToUartIdleCount > 130) //SWR
{
//SWR Send
sendCommandL('m', SWRAdcValue);
sendCommand1Num('m', 3);
SMeterToUartIdleCount = 0;
}
else if (SMeterToUartIdleCount == 100) //POWER 500msec interval
{
readValue = analogRead(POWER_METER_ADC );
SWRAdcValue = analogRead(SWR_METER_ADC);
sendCommandL('m', readValue);
sendCommand1Num('m',2);
//PWR Send
}
*/
//************************************************ //************************************************
//Read FWD and RWD //Read FWD and RWD
adcFWD = adcFWD * 0.8 + analogRead(A2) * 0.2; adcFWD = adcFWD * 0.8 + analogRead(A2) * 0.2;
@ -852,7 +849,7 @@ void loop()
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
forwardData(); forwardData();
if (TXStatus != 1) //if TX -> RX break if (!isTX) //if TX -> RX break
{ {
break; break;
} }
@ -911,14 +908,14 @@ void loop()
//nowSendingProtocol -> not finished data forward, (not found 0xff, 0xff, 0xff yet) //nowSendingProtocol -> not finished data forward, (not found 0xff, 0xff, 0xff yet)
if (nowSendingProtocol == 0 && isProcess == 1) //Complete ADC Sampling and Idle status if (nowSendingProtocol == 0 && isProcess == 1) //Complete ADC Sampling and Idle status
{ {
SendMeterData(1); sendMeterData(1);
SMeterToUartIdleCount = 0; SMeterToUartIdleCount = 0;
} }
} }
} //end of if } //end of if
else else
{ {
SendMeterData(0); //only calculate Signal Level sendMeterData(0); //only calculate Signal Level
} }
forwardData(); forwardData();

View File

@ -88,7 +88,7 @@ void FFT(double *x,double *y, int n, long m)
double coeff; double coeff;
void CalculateCoeff(uint8_t freqIndex) void calculateCoeff(uint8_t freqIndex)
{ {
float omega; float omega;
int targetFrequency = freqIndex * 50 + 300; int targetFrequency = freqIndex * 50 + 300;