Mercurial > public > ostc4
changeset 921:eb4109d7d1e9 Evo_2_23
Improved mix mode ADC conversion:
Activity of UART sensors may have an impact to ADC measurement. To avoid the ADC trigger was moved into a time window ~300ms after last UART command request => After UART sensor performed measurement but before next measurement is requested. In addition the general ADC measurement cycle has been changed to one second to avoid jitter in the value updates on the display.
author | Ideenmodellierer |
---|---|
date | Sun, 03 Nov 2024 18:19:51 +0100 |
parents | c4c9850a2039 |
children | 7c996354b8ac |
files | Small_CPU/Src/externalInterface.c Small_CPU/Src/uart.c Small_CPU/Src/uartProtocol_O2.c |
diffstat | 3 files changed, 63 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/Small_CPU/Src/externalInterface.c Sun Nov 03 15:44:54 2024 +0100 +++ b/Small_CPU/Src/externalInterface.c Sun Nov 03 18:19:51 2024 +0100 @@ -40,9 +40,10 @@ extern SGlobal global; extern UART_HandleTypeDef huart1; -#define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */ -#define ADC_TIMEOUT (10u) /* conversion stuck for unknown reason => restart */ -#define ADC_REF_VOLTAGE_MV (2048.0f) /* reference voltage of MPC3424*/ +#define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */ +#define ADC_TIMEOUT (10u) /* conversion stuck for unknown reason => restart */ +#define ADC_REF_VOLTAGE_MV (2048.0f) /* reference voltage of MPC3424*/ +#define ADC_CYCLE_INTERVAL_MS (1000u) /* start adc read out once per second*/ #define ADC_START_CONVERSION (0x80) #define ADC_GAIN_4 (0x02) @@ -70,6 +71,7 @@ static uint8_t timeoutCnt = 0; static uint8_t externalInterfacePresent = 0; static uint8_t delayAdcConversion = 0; +static uint32_t startTickADC = 0; float externalChannel_mV[MAX_ADC_CHANNEL]; static uint8_t externalV33_On = 0; @@ -171,55 +173,67 @@ if(externalADC_On) { - if(delayAdcConversion) - { - if(UART_isComActive(activeUartChannel) == 0) - { - externalInterface_StartConversion(activeChannel); - delayAdcConversion = 0; - } - } - else if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK) + if(time_elapsed_ms(startTickADC, HAL_GetTick()) > ADC_CYCLE_INTERVAL_MS) { - if((recBuf[ANSWER_CONFBYTE_INDEX] & ADC_START_CONVERSION) == 0) /* !ready set => received data contains new value */ + if(delayAdcConversion) { - retval = activeChannel; /* return channel number providing new data */ - nextChannel = activeChannel + 1; - if(nextChannel == MAX_ADC_CHANNEL) + if(UART_isComActive(activeUartChannel) == 0) { - nextChannel = 0; + externalInterface_StartConversion(activeChannel); + delayAdcConversion = 0; } - - while((psensorMap[nextChannel] != SENSOR_ANALOG) && (nextChannel != activeChannel)) + } + else if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK) + { + if((recBuf[ANSWER_CONFBYTE_INDEX] & ADC_START_CONVERSION) == 0) /* !ready set => received data contains new value */ { + retval = activeChannel; /* return channel number providing new data */ + nextChannel = activeChannel + 1; if(nextChannel == MAX_ADC_CHANNEL) { nextChannel = 0; } + + while((psensorMap[nextChannel] != SENSOR_ANALOG) && (nextChannel != activeChannel)) + { + if(nextChannel == MAX_ADC_CHANNEL) + { + nextChannel = 0; + startTickADC = HAL_GetTick(); + } + else + { + nextChannel++; + } + } + + activeChannel = nextChannel; + if(activeChannel == 0) + { + delayAdcConversion = 1; /* wait for next cycle interval */ + } else { - nextChannel++; + if(UART_isComActive(activeUartChannel) == 0) + { + externalInterface_StartConversion(activeChannel); + } + else + { + delayAdcConversion = 1; + } } + timeoutCnt = 0; } + } - activeChannel = nextChannel; - if(UART_isComActive(activeUartChannel) == 0) - { - externalInterface_StartConversion(activeChannel); - } - else - { - delayAdcConversion = 1; - } - timeoutCnt = 0; - } - } if(timeoutCnt++ >= ADC_TIMEOUT) { externalInterface_StartConversion(activeChannel); delayAdcConversion = 0; timeoutCnt = 0; } + } } return retval; } @@ -352,6 +366,7 @@ { if(externalADC_On == 0) { + startTickADC = HAL_GetTick(); activeChannel = 0; externalInterface_StartConversion(activeChannel); externalADC_On = 1; @@ -1227,10 +1242,18 @@ break; } } +#if 0 + else + { + if(((time_elapsed_ms(lastRequestTick,tick) > (externalInterfaceMuxReqIntervall - 100)) + && externalInterface_SensorState[activeSensorId] = UART_COMMON_IDLE)) + { + externalInterface_ReadAndSwitch(); + } + } +#endif } - - #if 0 #ifdef ENABLE_SENTINEL_MODE if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_SENTINEL)) @@ -1239,6 +1262,4 @@ } #endif #endif - - }
--- a/Small_CPU/Src/uart.c Sun Nov 03 15:44:54 2024 +0100 +++ b/Small_CPU/Src/uart.c Sun Nov 03 18:19:51 2024 +0100 @@ -54,6 +54,7 @@ static uint8_t dmaRxActive; /* Indicator if DMA reception needs to be started */ static uint8_t dmaTxActive; /* Indicator if DMA reception needs to be started */ +static uint32_t LastCmdRequestTick = 0; /* Used by ADC handler to avoid interferance with UART communication */ static uint8_t isEndIndication(uint8_t index); @@ -297,6 +298,7 @@ if(HAL_OK == HAL_UART_Transmit_DMA(&huart1,txBuffer,cmdLength)) { dmaTxActive = 1; + LastCmdRequestTick = HAL_GetTick(); } } } @@ -319,6 +321,7 @@ if(HAL_OK == HAL_UART_Transmit_DMA(&huart1,txBuffer,len)) { dmaTxActive = 1; + LastCmdRequestTick = HAL_GetTick(); } } } @@ -544,11 +547,12 @@ uint8_t ComState = externalInterface_GetSensorState(sensorId + EXT_INTERFACE_MUX_OFFSET); - if((ComState == UART_COMMON_INIT) || (ComState == UART_COMMON_IDLE) || (ComState == UART_COMMON_ERROR) || (ComState == COMMON_SENSOR_STATE_INVALID)) + if(time_elapsed_ms(LastCmdRequestTick, HAL_GetTick()) > 300) /* UART activity should be inactive 300ms after last command */ { active = 0; } return active; } + /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/
--- a/Small_CPU/Src/uartProtocol_O2.c Sun Nov 03 15:44:54 2024 +0100 +++ b/Small_CPU/Src/uartProtocol_O2.c Sun Nov 03 18:19:51 2024 +0100 @@ -106,6 +106,7 @@ localComState = UART_O2_CHECK; lastComState = UART_O2_CHECK; + UART_clearRxBuffer(); uartO2_SetupCmd(localComState,cmdString,&cmdLength); UART_SendCmdString(cmdString); rxState = O2RX_CONFIRM;