Detect DAC overflows.

48kHz
Jonathan Naylor 2016-06-09 19:50:34 +01:00
parent 961d1000f5
commit 0d07dd78eb
3 changed files with 29 additions and 19 deletions

33
IO.cpp
View File

@ -121,8 +121,8 @@ m_ledCount(0U),
m_ledValue(true),
m_dcd(false),
m_detect(false),
m_overflow(0U),
m_overcount(0U),
m_adcOverflow(0U),
m_dacOverflow(0U),
m_count(0U),
m_watchdog(0U),
m_lockout(false)
@ -301,8 +301,7 @@ void CIO::process()
// Detect ADC overflow
if (m_detect && (sample == 0U || sample == 4095U))
m_overflow++;
m_overcount++;
m_adcOverflow++;
q15_t res1 = q15_t(sample) - DC_OFFSET;
q31_t res2 = res1 * m_rxLevel;
@ -405,11 +404,16 @@ void CIO::write(q15_t* samples, uint16_t length, const uint8_t* control)
for (uint16_t i = 0U; i < length; i++) {
q31_t res1 = samples[i] * m_txLevel;
q15_t res2 = q15_t(__SSAT((res1 >> 15), 16));
uint16_t res3 = uint16_t(res2 + DC_OFFSET);
// Detect DAC overflow
if (res3 == 0U || res3 >= 4095U)
m_dacOverflow++;
if (control == NULL)
m_txBuffer.put(uint16_t(res2 + DC_OFFSET), MARK_NONE);
m_txBuffer.put(res3, MARK_NONE);
else
m_txBuffer.put(uint16_t(res2 + DC_OFFSET), control[i]);
m_txBuffer.put(res3, control[i]);
}
}
@ -499,19 +503,18 @@ void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rx
m_txLevel = -m_txLevel;
}
bool CIO::hasADCOverflow()
void CIO::getOverflow(bool& adcOverflow, bool& dacOverflow)
{
bool overflow = m_overflow > 0U;
adcOverflow = m_adcOverflow > 0U;
dacOverflow = m_dacOverflow > 0U;
#if defined(WANT_DEBUG)
if (m_overflow > 0U)
DEBUG3("IO: Overflow, n/count", m_overflow, m_overcount);
if (m_adcOverflow > 0U || m_dacOverflow > 0U)
DEBUG3("IO: adc/dac", m_adcOverflow, m_dacOverflow);
#endif
m_overflow = 0U;
m_overcount = 0U;
return overflow;
m_adcOverflow = 0U;
m_dacOverflow = 0U;
}
bool CIO::hasTXOverflow()

6
IO.h
View File

@ -43,7 +43,7 @@ public:
void setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t txLevel);
bool hasADCOverflow();
void getOverflow(bool& adcOverflow, bool& dacOverflow);
bool hasTXOverflow();
bool hasRXOverflow();
@ -85,8 +85,8 @@ private:
bool m_dcd;
bool m_detect;
uint16_t m_overflow;
uint16_t m_overcount;
uint16_t m_adcOverflow;
uint16_t m_dacOverflow;
uint32_t m_count;

View File

@ -123,7 +123,11 @@ void CSerialPort::getStatus()
reply[5U] = m_tx ? 0x01U : 0x00U;
if (io.hasADCOverflow())
bool adcOverflow;
bool dacOverflow;
io.getOverflow(adcOverflow, dacOverflow);
if (adcOverflow)
reply[5U] |= 0x02U;
if (io.hasRXOverflow())
@ -135,6 +139,9 @@ void CSerialPort::getStatus()
if (io.hasLockout())
reply[5U] |= 0x10U;
if (dacOverflow)
reply[5U] |= 0x20U;
if (m_dstarEnable)
reply[6U] = dstarTX.getSpace();
else