diff --git a/openrtx/src/rtx.c b/openrtx/src/rtx.c index eaabff48..c759a016 100644 --- a/openrtx/src/rtx.c +++ b/openrtx/src/rtx.c @@ -34,6 +34,8 @@ rtxStatus_t rtxStatus; /* RTX driver status */ bool sqlOpen; /* Flag for squelch open/close */ bool enterRx; /* Flag for RX mode activation */ +float rssi; /* Current RSSI in dBm */ + /* * These functions below provide a basic API for audio path management. They * will be removed once the audio driver is set up. @@ -134,6 +136,11 @@ void rtx_init(OS_MUTEX *m) */ radio_init(); + /* + * Initial value for RSSI filter + */ + rssi = radio_getRssi(rtxStatus.rxFrequency); + _afCtrlInit(); } @@ -236,9 +243,12 @@ void rtx_taskFunc() if(rtxStatus.opStatus == RX) { /* - * RSSI-based squelch mechanism, with 15 levels from -140dBm to -70dBm + * RSSI-based squelch mechanism, with 15 levels from -140dBm to -70dBm. + * + * RSSI value is passed through a filter with a time constant of 60ms + * (cut-off frequency of 15Hz) at an update rate of 33.3Hz */ - float rssi = rtx_getRssi(); + rssi = 0.74*radio_getRssi(rtxStatus.rxFrequency) + 0.26*rssi; float squelch = -127.0f + rtxStatus.sqlLevel * 66.0f / 15.0f; if((sqlOpen == false) && (rssi > (squelch + 0.1f))) @@ -261,6 +271,9 @@ void rtx_taskFunc() radio_enableRx(); rtxStatus.opStatus = RX; enterRx = false; + + /* Reinitialise RSSI filter state */ + rssi = radio_getRssi(rtxStatus.rxFrequency); } /* TX logic */ @@ -309,5 +322,5 @@ void rtx_taskFunc() float rtx_getRssi() { - return radio_getRssi(rtxStatus.rxFrequency); + return rssi; } diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index cc8e5287..f8101a1d 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -251,6 +251,11 @@ static void dev_task(void *arg) (void) arg; OS_ERR os_err; + // Initialise battery voltage, to avoid filter settling transient + OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err); + state.v_bat = platform_getVbat(); + OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err); + while(1) { // Lock mutex and update internal state @@ -260,7 +265,11 @@ static void dev_task(void *arg) state.time = rtc_getTime(); state_applyTimezone(); #endif - state.v_bat = platform_getVbat(); + + // Low-pass filtering with a time constant of 10s when updated at 1Hz + float vbat = platform_getVbat(); + state.v_bat = 0.02*vbat + 0.98*state.v_bat; + state.charge = battery_getCharge(state.v_bat); state.rssi = rtx_getRssi(); diff --git a/platform/drivers/ADC/ADC1_MDx.c b/platform/drivers/ADC/ADC1_MDx.c index 4c3b7763..c5d4f4b2 100644 --- a/platform/drivers/ADC/ADC1_MDx.c +++ b/platform/drivers/ADC/ADC1_MDx.c @@ -20,18 +20,12 @@ #include "ADC1_MDx.h" /* - * Ringbuffer of samples to allow for value smoothing through averaging. This - * buffer is structured as follows: + * The sample buffer is structured as follows: * - * | vbat | rssi | vox | vol | vbat | rssi | vox | vol | ... + * | vbat | rssi | vox | vol | * - * thus it contains four samples of the four channels. Then, DMA is configured - * in circular mode with a rollover after 16 transfers, effectively managing - * this buffer as a ringbuffer for the measurements of the four channels. - * Then, in adc1_getMeasurement(), the average over the values contained in the - * ring buffer is performed and returned as the current channel value. */ -uint16_t sampleRingBuf[16]; +uint16_t sampleBuf[4]; void adc1_init() { @@ -98,8 +92,8 @@ void adc1_init() * - no interrupts */ DMA2_Stream0->PAR = ((uint32_t) &(ADC1->DR)); - DMA2_Stream0->M0AR = ((uint32_t) &sampleRingBuf); - DMA2_Stream0->NDTR = 16; + DMA2_Stream0->M0AR = ((uint32_t) &sampleBuf); + DMA2_Stream0->NDTR = 4; DMA2_Stream0->CR = DMA_SxCR_MSIZE_0 /* Memory size: 16 bit */ | DMA_SxCR_PSIZE_0 /* Peripheral size: 16 bit */ | DMA_SxCR_PL_0 /* Medium priority */ @@ -123,14 +117,6 @@ float adc1_getMeasurement(uint8_t ch) { if(ch > 3) return 0.0f; - /* Return the average over the ring buffer */ - float value = 0.0f; - for(uint8_t i = 0; i < 16; i += 4) - { - value += ((float) sampleRingBuf[i + ch]); - } - value /= 4.0f; - - /* Return average value converted to mV */ + float value = ((float) sampleBuf[ch]); return (value * 3300.0f)/4096.0f; } diff --git a/platform/drivers/baseband/radio_UV3x0.c b/platform/drivers/baseband/radio_UV3x0.c index 09e7f262..42d190c3 100644 --- a/platform/drivers/baseband/radio_UV3x0.c +++ b/platform/drivers/baseband/radio_UV3x0.c @@ -54,7 +54,7 @@ void radio_setCSS(const tone_t rxCss, const tone_t txCss) bool radio_checkRxDigitalSquelch() { - + return false; } void radio_enableRx()