Fix CTCSS value is different when using RXLevel 50 to 99

This commit is contained in:
Geoffrey Merck 2020-05-01 17:56:45 +02:00
parent 5b32fecc0a
commit 0a5c496a3a
2 changed files with 17 additions and 1 deletions

View File

@ -93,7 +93,7 @@ m_rxLevelInverse(1)
uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, uint8_t level)
{
m_rxLevelInverse = 511 / q15_t(level);
m_rxLevelInverse = q15Division(65535, q15_t(level * 128));
m_coeffDivTwo = 0;
@ -179,3 +179,17 @@ void CFMCTCSSRX::reset()
m_result = CTS_NONE;
m_count = 0U;
}
//Taken from https://en.wikipedia.org/wiki/Q_(number_format)#Division
q15_t CFMCTCSSRX::q15Division(q15_t a, q15_t divisor)
{
q31_t a31 = q31_t(a) << 16;
if (((a >> 31) & 1) == ((divisor >> 15) & 1))
a31 += divisor >> 1;
else
a31 -= divisor >> 1;
return a31 / divisor;
}

View File

@ -62,6 +62,8 @@ public:
void reset();
private:
q15_t q15Division(q15_t a, q15_t divisor);
q63_t m_coeffDivTwo;
q31_t m_threshold;
uint16_t m_count;