comparison Small_CPU/Src/externalInterface.c @ 861:ad96f99ebc78 Evo_2_23 tip

Synchronize ADC and UART activities: depending on the cable configuration the UART sensor operation may have an impact to the ADC measurement (peaks). To avoid this the ADC measurements are now only started in case no UART communication is pending.
author Ideenmodellierer
date Tue, 07 May 2024 21:25:25 +0200
parents c3dd461ca3f9
children
comparison
equal deleted inserted replaced
860:3e499569baf3 861:ad96f99ebc78
66 66
67 static uint8_t activeChannel = 0; /* channel which is in request */ 67 static uint8_t activeChannel = 0; /* channel which is in request */
68 static uint8_t recBuf[ADC_ANSWER_LENGTH]; 68 static uint8_t recBuf[ADC_ANSWER_LENGTH];
69 static uint8_t timeoutCnt = 0; 69 static uint8_t timeoutCnt = 0;
70 static uint8_t externalInterfacePresent = 0; 70 static uint8_t externalInterfacePresent = 0;
71 static uint8_t delayAdcConversion = 0;
71 72
72 float externalChannel_mV[MAX_ADC_CHANNEL]; 73 float externalChannel_mV[MAX_ADC_CHANNEL];
73 static uint8_t externalV33_On = 0; 74 static uint8_t externalV33_On = 0;
74 static uint8_t externalADC_On = 0; 75 static uint8_t externalADC_On = 0;
75 static uint8_t externalUART_Protocol = 0; 76 static uint8_t externalUART_Protocol = 0;
102 uint16_t index; 103 uint16_t index;
103 uint16_t coeff; 104 uint16_t coeff;
104 activeChannel = 0; 105 activeChannel = 0;
105 timeoutCnt = 0; 106 timeoutCnt = 0;
106 externalInterfacePresent = 0; 107 externalInterfacePresent = 0;
108 delayAdcConversion = 0;
107 if(externalInterface_StartConversion(activeChannel) == HAL_OK) 109 if(externalInterface_StartConversion(activeChannel) == HAL_OK)
108 { 110 {
109 externalInterfacePresent = 1; 111 externalInterfacePresent = 1;
110 global.deviceDataSendToMaster.hw_Info.extADC = 1; 112 global.deviceDataSendToMaster.hw_Info.extADC = 1;
111 } 113 }
169 uint8_t nextChannel; 171 uint8_t nextChannel;
170 uint8_t* psensorMap = externalInterface_GetSensorMapPointer(0); 172 uint8_t* psensorMap = externalInterface_GetSensorMapPointer(0);
171 173
172 if(externalADC_On) 174 if(externalADC_On)
173 { 175 {
174 if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK) 176 if(delayAdcConversion)
177 {
178 if(UART_isComActive(activeUartChannel) == 0)
179 {
180 externalInterface_StartConversion(activeChannel);
181 delayAdcConversion = 0;
182 }
183 }
184 else if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK)
175 { 185 {
176 if((recBuf[ANSWER_CONFBYTE_INDEX] & ADC_START_CONVERSION) == 0) /* !ready set => received data contains new value */ 186 if((recBuf[ANSWER_CONFBYTE_INDEX] & ADC_START_CONVERSION) == 0) /* !ready set => received data contains new value */
177 { 187 {
178 retval = activeChannel; /* return channel number providing new data */ 188 retval = activeChannel; /* return channel number providing new data */
179 nextChannel = activeChannel + 1; 189 nextChannel = activeChannel + 1;
193 nextChannel++; 203 nextChannel++;
194 } 204 }
195 } 205 }
196 206
197 activeChannel = nextChannel; 207 activeChannel = nextChannel;
198 externalInterface_StartConversion(activeChannel); 208 if(UART_isComActive(activeUartChannel) == 0)
199 timeoutCnt = 0;
200 }
201 else
202 {
203 if(timeoutCnt++ >= ADC_TIMEOUT)
204 { 209 {
205 externalInterface_StartConversion(activeChannel); 210 externalInterface_StartConversion(activeChannel);
206 timeoutCnt = 0;
207 } 211 }
208 } 212 else
209 } 213 {
210 else /* take also i2c bus disturb into account */ 214 delayAdcConversion = 1;
211 { 215 }
212 if(timeoutCnt++ >= ADC_TIMEOUT)
213 {
214 externalInterface_StartConversion(activeChannel);
215 timeoutCnt = 0; 216 timeoutCnt = 0;
216 } 217 }
218
219 }
220 if(timeoutCnt++ >= ADC_TIMEOUT)
221 {
222 externalInterface_StartConversion(activeChannel);
223 delayAdcConversion = 0;
224 timeoutCnt = 0;
217 } 225 }
218 } 226 }
219 return retval; 227 return retval;
220 } 228 }
221 float externalInterface_CalculateADCValue(uint8_t channel) 229 float externalInterface_CalculateADCValue(uint8_t channel)