Rev 53 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 53 | Rev 54 | ||
|---|---|---|---|
| Line 154... | Line 154... | ||
| 154 | float adc_vref = STM32REF * (4096.0 * Scale) / adc_val; // the estimate for checking |
154 | float adc_vref = STM32REF * (4096.0 * Scale) / adc_val; // the estimate for checking |
| 155 | 155 | ||
| 156 | ADC_Scale = 1 / (Scale * 4096) * adc_vref; |
156 | ADC_Scale = 1 / (Scale * 4096) * adc_vref; |
| 157 | } |
157 | } |
| 158 | 158 | ||
| 159 | void ProcessRPM(void) |
159 | void ProcessRPM(struct usart_ctl * handle) |
| 160 | { |
160 | { |
| 161 | static unsigned int Coded_RPM = 0; |
161 | static unsigned int Coded_RPM = 0; |
| 162 | int32_t rpm = CalculateRPM(); |
162 | int32_t rpm = CalculateRPM(); |
| 163 | // suppress the EDIS "heartbeat" 90 RPM |
163 | // suppress the EDIS "heartbeat" 90 RPM |
| 164 | if (rpm >= 100) |
164 | if (rpm >= 100) |
| 165 | Coded_RPM = rpm / 19.55; |
165 | Coded_RPM = rpm / 19.55; |
| 166 | 166 | ||
| 167 | // send the current RPM *calculation |
167 | // send the current RPM *calculation |
| 168 | - | ||
| 169 | sendPlxInfo(& uc1, PLX_RPM, Coded_RPM/ Scale); |
168 | sendPlxInfo(handle, PLX_RPM, Coded_RPM/ Scale); |
| 170 | - | ||
| 171 | - | ||
| 172 | } |
169 | } |
| 173 | 170 | ||
| 174 | // this uses a MAX6675 which is a simple 16 bit read |
171 | // this uses a MAX6675 which is a simple 16 bit read |
| 175 | // SPI is configured for 8 bits so I can use an OLED display if I need it |
172 | // SPI is configured for 8 bits so I can use an OLED display if I need it |
| 176 | // must wait > 0.22 seconds between conversion attempts as this is the measurement time |
173 | // must wait > 0.22 seconds between conversion attempts as this is the measurement time |
| Line 182... | Line 179... | ||
| 182 | 179 | ||
| 183 | uint16_t Temp_Observations[NUM_SPI_TEMP_SENS] = {[0 ... NUM_SPI_TEMP_SENS - 1] = 0}; |
180 | uint16_t Temp_Observations[NUM_SPI_TEMP_SENS] = {[0 ... NUM_SPI_TEMP_SENS - 1] = 0}; |
| 184 | 181 | ||
| 185 | /// \param item The array index to send |
182 | /// \param item The array index to send |
| 186 | /// \param type the code to use for this observation |
183 | /// \param type the code to use for this observation |
| 187 | void ProcessTemp(char item, enum PLX_Observations type) |
184 | void ProcessTemp(struct usart_ctl * handle,char item, enum PLX_Observations type) |
| 188 | { |
185 | { |
| 189 | if (item > NUM_SPI_TEMP_SENS) |
186 | if (item > NUM_SPI_TEMP_SENS) |
| 190 | return; |
187 | return; |
| 191 | 188 | ||
| 192 | sendPlxInfo(& uc1, type , Temp_Observations[(int)item]); |
189 | sendPlxInfo(handle, type , Temp_Observations[(int)item]); |
| 193 | 190 | ||
| 194 | } |
191 | } |
| 195 | 192 | ||
| 196 | /// \brief Reset the temperature chip select system |
193 | /// \brief Reset the temperature chip select system |
| 197 | void resetTempCS(void) |
194 | void resetTempCS(void) |
| Line 260... | Line 257... | ||
| 260 | } |
257 | } |
| 261 | } |
258 | } |
| 262 | 259 | ||
| 263 | // 1023 is 20.00 volts. |
260 | // 1023 is 20.00 volts. |
| 264 | /// \param item - used to lookup the index of the local reading |
261 | /// \param item - used to lookup the index of the local reading |
| 265 | void ProcessBatteryVoltage(int item) |
262 | void ProcessBatteryVoltage(struct usart_ctl * handle, int item) |
| 266 | { |
263 | { |
| 267 | float reading = FILT_Samples[item] * ADC_Scale; |
264 | float reading = FILT_Samples[item] * ADC_Scale; |
| 268 | reading = reading * 7.8125; // real voltage |
265 | reading = reading * 7.8125; // real voltage |
| 269 | reading = reading * 51.15; // PLC scaling = 1023/20 |
266 | reading = reading * 51.15; // PLC scaling = 1023/20 |
| 270 | 267 | ||
| 271 | sendPlxInfo(& uc1, PLX_Volts, reading); |
268 | sendPlxInfo(handle, PLX_Volts, reading); |
| 272 | 269 | ||
| 273 | } |
270 | } |
| 274 | 271 | ||
| 275 | void ProcessCPUTemperature(void) |
272 | void ProcessCPUTemperature(struct usart_ctl * handle) |
| 276 | { |
273 | { |
| 277 | // this is defined in the STM32F103 reference manual . # |
274 | // this is defined in the STM32F103 reference manual . # |
| 278 | // V25 = 1.43 volts |
275 | // V25 = 1.43 volts |
| 279 | // Avg_slope = 4.3mV /degree C |
276 | // Avg_slope = 4.3mV /degree C |
| 280 | // temperature = {(V25 - VSENSE) / Avg_Slope} + 25 |
277 | // temperature = {(V25 - VSENSE) / Avg_Slope} + 25 |
| Line 285... | Line 282... | ||
| 285 | /* renormalise temperature value to account for different ADC Vref : normalise to that which we would get for a 3000mV reference */ |
282 | /* renormalise temperature value to account for different ADC Vref : normalise to that which we would get for a 3000mV reference */ |
| 286 | temp_val = (1.43 - temp_val) / 4.3e-3 + 25; |
283 | temp_val = (1.43 - temp_val) / 4.3e-3 + 25; |
| 287 | 284 | ||
| 288 | int32_t result = temp_val; |
285 | int32_t result = temp_val; |
| 289 | 286 | ||
| 290 | sendPlxInfo(& uc1, PLX_FluidTemp, result); |
287 | sendPlxInfo(handle, PLX_FluidTemp, result); |
| 291 | 288 | ||
| 292 | } |
289 | } |
| 293 | 290 | ||
| 294 | // the MAP sensor is giving us a reading of |
291 | // the MAP sensor is giving us a reading of |
| 295 | // 4.6 volts for 1019mB or 2.27 volts at the ADC input (resistive divider by 2.016) |
292 | // 4.6 volts for 1019mB or 2.27 volts at the ADC input (resistive divider by 2.016) |
| Line 298... | Line 295... | ||
| 298 | // Real Displayed |
295 | // Real Displayed |
| 299 | // 989 968 |
296 | // 989 968 |
| 300 | // 994.1 986 |
297 | // 994.1 986 |
| 301 | // 992.3 984 |
298 | // 992.3 984 |
| 302 | 299 | ||
| 303 | void ProcessMAP(void) |
300 | void ProcessMAP(struct usart_ctl * handle) |
| 304 | { |
301 | { |
| 305 | // Using ADC_Samples[3] as the MAP input |
302 | // Using ADC_Samples[3] as the MAP input |
| 306 | float reading = FILT_Samples[ADC_MAP_CHAN] * ADC_Scale; |
303 | float reading = FILT_Samples[ADC_MAP_CHAN] * ADC_Scale; |
| 307 | reading = reading * 2.016; // real voltage |
304 | reading = reading * 2.016; // real voltage |
| 308 | // values computed from slope / intercept of map.ods |
305 | // values computed from slope / intercept of map.ods |
| 309 | // reading = (reading) * 56.23 + 743.2; // do not assume 0.5 volt offset : reading from 0 to 4.5 instead of 0.5 to 4.5 |
306 | // reading = (reading) * 56.23 + 743.2; // do not assume 0.5 volt offset : reading from 0 to 4.5 instead of 0.5 to 4.5 |
| 310 | // using a pressure gauge. |
307 | // using a pressure gauge. |
| 311 | reading = (reading) * 150 + 326; |
308 | reading = (reading) * 150 + 326; |
| 312 | 309 | ||
| 313 | sendPlxInfo(& uc1, PLX_MAP, reading); |
310 | sendPlxInfo(handle, PLX_MAP, reading); |
| 314 | 311 | ||
| 315 | } |
312 | } |
| 316 | 313 | ||
| 317 | // the Oil pressi sensor is giving us a reading of |
314 | // the Oil pressi sensor is giving us a reading of |
| 318 | // 4.5 volts for 100 PSI or 2.25 volts at the ADC input (resistive divider by 2.016) |
315 | // 4.5 volts for 100 PSI or 2.25 volts at the ADC input (resistive divider by 2.016) |
| 319 | // I believe the sensor reads 4.5V at 100PSI and 0.5V at 0PSI |
316 | // I believe the sensor reads 4.5V at 100PSI and 0.5V at 0PSI |
| 320 | // an observation of 1024 is 200PSI, so observation of 512 is 100 PSI. |
317 | // an observation of 1024 is 200PSI, so observation of 512 is 100 PSI. |
| 321 | 318 | ||
| 322 | void ProcessOilPress(void) |
319 | void ProcessOilPress(struct usart_ctl * handle) |
| 323 | { |
320 | { |
| 324 | // Using ADC_Samples[2] as the MAP input |
321 | // Using ADC_Samples[2] as the MAP input |
| 325 | float reading = FILT_Samples[ADC_PRESSURE_CHAN] * ADC_Scale; |
322 | float reading = FILT_Samples[ADC_PRESSURE_CHAN] * ADC_Scale; |
| 326 | reading = reading * 2.00; // real voltage |
323 | reading = reading * 2.00; // real voltage |
| 327 | reading = (reading - 0.5) * 512 / 4; // this is 1023 * 100/200 |
324 | reading = (reading - 0.5) * 512 / 4; // this is 1023 * 100/200 |
| 328 | 325 | ||
| 329 | sendPlxInfo(& uc1, PLX_FluidPressure, reading); |
326 | sendPlxInfo(handle, PLX_FluidPressure, reading); |
| 330 | 327 | ||
| 331 | } |
328 | } |
| 332 | 329 | ||
| 333 | 330 | ||
| 334 | void libPLXcallbackSendUserData() |
331 | void libPLXcallbackSendUserData(struct usart_ctl * handle) |
| 335 | { |
332 | { |
| 336 | // send the observations |
333 | // send the observations |
| 337 | ProcessRPM(); |
334 | ProcessRPM(handle); |
| 338 | ProcessTemp(0, PLX_X_CHT); |
335 | ProcessTemp(handle,0, PLX_X_CHT); |
| 339 | ProcessTemp(1, PLX_X_CHT); |
336 | ProcessTemp(handle,1, PLX_X_CHT); |
| 340 | ProcessTemp(2, PLX_AIT); |
337 | ProcessTemp(handle,2, PLX_AIT); |
| 341 | ProcessTemp(3, PLX_AIT); |
338 | ProcessTemp(handle,3, PLX_AIT); |
| 342 | ProcessBatteryVoltage(0); // Batt 1 |
339 | ProcessBatteryVoltage(handle,0); // Batt 1 |
| 343 | ProcessBatteryVoltage(1); // Batt 2 |
340 | ProcessBatteryVoltage(handle,1); // Batt 2 |
| 344 | ProcessCPUTemperature(); // built in temperature sensor |
341 | ProcessCPUTemperature(handle); // built in temperature sensor |
| 345 | - | ||
| 346 | ProcessMAP(); |
- | |
| 347 | ProcessOilPress(); |
- | |
| 348 | 342 | ||
| - | 343 | ProcessMAP(handle); |
|
| 349 | PutCharSerial(&uc1, PLX_Stop); |
344 | ProcessOilPress(handle); |
| 350 | } |
345 | } |
| 351 | /* USER CODE END 0 */ |
346 | /* USER CODE END 0 */ |
| 352 | 347 | ||
| 353 | /** |
348 | /** |
| 354 | * @brief The application entry point. |
349 | * @brief The application entry point. |