Rev 49 | Rev 52 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 49 | Rev 50 | ||
---|---|---|---|
Line 23... | Line 23... | ||
23 | /* Private includes ----------------------------------------------------------*/ |
23 | /* Private includes ----------------------------------------------------------*/ |
24 | /* USER CODE BEGIN Includes */ |
24 | /* USER CODE BEGIN Includes */ |
25 | #include <string.h> |
25 | #include <string.h> |
26 | #include "libSerial/serial.h" |
26 | #include "libSerial/serial.h" |
27 | #include "libPLX/plx.h" |
27 | #include "libPLX/plx.h" |
- | 28 | #include "libPLX/commsLib.h" |
|
28 | #include "misc.h" |
29 | #include "misc.h" |
29 | 30 | ||
30 | #include "libIgnTiming/rpm.h" |
31 | #include "libIgnTiming/rpm.h" |
31 | 32 | ||
32 | /* USER CODE END Includes */ |
33 | /* USER CODE END Includes */ |
Line 77... | Line 78... | ||
77 | volatile char TimerFlag = 0; |
78 | volatile char TimerFlag = 0; |
78 | 79 | ||
79 | volatile char NoSerialInCTR = 0; // Missing characters coming in on USART1 |
80 | volatile char NoSerialInCTR = 0; // Missing characters coming in on USART1 |
80 | volatile char NoSerialIn = 0; |
81 | volatile char NoSerialIn = 0; |
81 | 82 | ||
82 | // an array containing values being one more than incoming index for all observations or zero |
- | |
83 | // if no incoming index |
- | |
84 | char obsIndex[PLX_MAX_OBS]; |
- | |
85 | - | ||
86 | // storage for ADC |
83 | // storage for ADC |
87 | uint16_t ADC_Samples[ADC_CHANNELS] = {[0 ... ADC_CHANNELS - 1] = 0}; |
84 | uint16_t ADC_Samples[ADC_CHANNELS] = {[0 ... ADC_CHANNELS - 1] = 0}; |
88 | 85 | ||
89 | uint32_t FILT_Samples[ADC_CHANNELS] = {[0 ... ADC_CHANNELS - 1] = 0}; // filtered ADC samples * Scale |
86 | uint32_t FILT_Samples[ADC_CHANNELS] = {[0 ... ADC_CHANNELS - 1] = 0}; // filtered ADC samples * Scale |
90 | 87 | ||
Line 162... | Line 159... | ||
162 | if (rpm >= 0) |
159 | if (rpm >= 0) |
163 | Coded_RPM = rpm / 19.55; |
160 | Coded_RPM = rpm / 19.55; |
164 | 161 | ||
165 | // send the current RPM *calculation |
162 | // send the current RPM *calculation |
166 | plx_sendword(PLX_RPM); |
163 | plx_sendword(PLX_RPM); |
167 | PutCharSerial(&uc1, obsIndex[PLX_RPM]++); |
164 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_RPM)); |
168 | plx_sendword(Coded_RPM / Scale); |
165 | plx_sendword(Coded_RPM / Scale); |
169 | } |
166 | } |
170 | 167 | ||
171 | // this uses a MAX6675 which is a simple 16 bit read |
168 | // this uses a MAX6675 which is a simple 16 bit read |
172 | // SPI is configured for 8 bits so I can use an OLED display if I need it |
169 | // SPI is configured for 8 bits so I can use an OLED display if I need it |
Line 184... | Line 181... | ||
184 | void ProcessTemp(char item, enum PLX_Observations type) |
181 | void ProcessTemp(char item, enum PLX_Observations type) |
185 | { |
182 | { |
186 | if (item > NUM_SPI_TEMP_SENS) |
183 | if (item > NUM_SPI_TEMP_SENS) |
187 | return; |
184 | return; |
188 | plx_sendword(type); |
185 | plx_sendword(type); |
189 | PutCharSerial(&uc1, obsIndex[type]++); |
186 | PutCharSerial(&uc1, libPLXgetNextInstance(type)); |
190 | plx_sendword(Temp_Observations[(int)item]); |
187 | plx_sendword(Temp_Observations[(int)item]); |
191 | } |
188 | } |
192 | 189 | ||
193 | /// \brief Reset the temperature chip select system |
190 | /// \brief Reset the temperature chip select system |
194 | void resetTempCS(void) |
191 | void resetTempCS(void) |
Line 264... | Line 261... | ||
264 | float reading = FILT_Samples[item] * ADC_Scale; |
261 | float reading = FILT_Samples[item] * ADC_Scale; |
265 | reading = reading * 7.8125; // real voltage |
262 | reading = reading * 7.8125; // real voltage |
266 | reading = reading * 51.15; // PLC scaling = 1023/20 |
263 | reading = reading * 51.15; // PLC scaling = 1023/20 |
267 | 264 | ||
268 | plx_sendword(PLX_Volts); |
265 | plx_sendword(PLX_Volts); |
269 | PutCharSerial(&uc1, obsIndex[PLX_Volts]++); |
266 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_Volts)); |
270 | plx_sendword((uint16_t)reading); |
267 | plx_sendword((uint16_t)reading); |
271 | } |
268 | } |
272 | 269 | ||
273 | void ProcessCPUTemperature(void) |
270 | void ProcessCPUTemperature(void) |
274 | { |
271 | { |
Line 287... | Line 284... | ||
287 | 284 | ||
288 | // int32_t result = 800 * ((int32_t) temp_val - TS_CAL30); |
285 | // int32_t result = 800 * ((int32_t) temp_val - TS_CAL30); |
289 | // result = result / (TS_CAL110 - TS_CAL30) + 300; |
286 | // result = result / (TS_CAL110 - TS_CAL30) + 300; |
290 | 287 | ||
291 | plx_sendword(PLX_FluidTemp); |
288 | plx_sendword(PLX_FluidTemp); |
292 | PutCharSerial(&uc1, obsIndex[PLX_FluidTemp]++); |
289 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_FluidTemp)); |
293 | plx_sendword(result); |
290 | plx_sendword(result); |
294 | } |
291 | } |
295 | 292 | ||
296 | // the MAP sensor is giving us a reading of |
293 | // the MAP sensor is giving us a reading of |
297 | // 4.6 volts for 1019mB or 2.27 volts at the ADC input (resistive divider by 2.016) |
294 | // 4.6 volts for 1019mB or 2.27 volts at the ADC input (resistive divider by 2.016) |
Line 311... | Line 308... | ||
311 | // 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 |
308 | // 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 |
312 | // using a pressure gauge. |
309 | // using a pressure gauge. |
313 | reading = (reading)*150 + 326; |
310 | reading = (reading)*150 + 326; |
314 | 311 | ||
315 | plx_sendword(PLX_MAP); |
312 | plx_sendword(PLX_MAP); |
316 | PutCharSerial(&uc1, obsIndex[PLX_MAP]++); |
313 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_MAP)); |
317 | plx_sendword((uint16_t)reading); |
314 | plx_sendword((uint16_t)reading); |
318 | } |
315 | } |
319 | 316 | ||
320 | // the Oil pressi sensor is giving us a reading of |
317 | // the Oil pressi sensor is giving us a reading of |
321 | // 4.5 volts for 100 PSI or 2.25 volts at the ADC input (resistive divider by 2.016) |
318 | // 4.5 volts for 100 PSI or 2.25 volts at the ADC input (resistive divider by 2.016) |
Line 328... | Line 325... | ||
328 | float reading = FILT_Samples[ADC_PRESSURE_CHAN] * ADC_Scale; |
325 | float reading = FILT_Samples[ADC_PRESSURE_CHAN] * ADC_Scale; |
329 | reading = reading * 2.00; // real voltage |
326 | reading = reading * 2.00; // real voltage |
330 | reading = (reading - 0.5) * 512 / 4; // this is 1023 * 100/200 |
327 | reading = (reading - 0.5) * 512 / 4; // this is 1023 * 100/200 |
331 | 328 | ||
332 | plx_sendword(PLX_FluidPressure); |
329 | plx_sendword(PLX_FluidPressure); |
333 | PutCharSerial(&uc1, obsIndex[PLX_FluidPressure]++); |
330 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_FluidPressure)); |
334 | plx_sendword((uint16_t)reading); |
331 | plx_sendword((uint16_t)reading); |
335 | } |
332 | } |
336 | 333 | ||
337 | void ProcessTiming(void) |
334 | void ProcessTiming(void) |
338 | { |
335 | { |
339 | plx_sendword(PLX_Timing); |
336 | plx_sendword(PLX_Timing); |
340 | PutCharSerial(&uc1, obsIndex[PLX_Timing]++); |
337 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_Timing)); |
341 | plx_sendword(64 - 15); // make it negative |
338 | plx_sendword(64 - 15); // make it negative |
342 | } |
339 | } |
343 | 340 | ||
- | 341 | void libPLXcallbackResetSerialTimeout() |
|
- | 342 | { |
|
- | 343 | resetSerialTimeout(); |
|
- | 344 | TimerFlag = 0; |
|
- | 345 | } |
|
- | 346 | ||
- | 347 | void libPLXcallbackSendUserData() |
|
- | 348 | { |
|
- | 349 | // send the observations |
|
- | 350 | ProcessRPM(); |
|
- | 351 | ProcessTemp(0, PLX_X_CHT); |
|
- | 352 | ProcessTemp(1, PLX_X_CHT); |
|
- | 353 | ProcessTemp(2, PLX_AIT); |
|
- | 354 | ProcessTemp(3, PLX_AIT); |
|
- | 355 | ProcessBatteryVoltage(0); // Batt 1 |
|
- | 356 | ProcessBatteryVoltage(1); // Batt 2 |
|
- | 357 | ProcessCPUTemperature(); // built in temperature sensor |
|
- | 358 | ||
- | 359 | ProcessMAP(); |
|
- | 360 | ProcessOilPress(); |
|
- | 361 | ||
- | 362 | PutCharSerial(&uc1, PLX_Stop); |
|
- | 363 | } |
|
344 | /* USER CODE END 0 */ |
364 | /* USER CODE END 0 */ |
345 | 365 | ||
346 | /** |
366 | /** |
347 | * @brief The application entry point. |
367 | * @brief The application entry point. |
348 | * @retval int |
368 | * @retval int |
Line 416... | Line 436... | ||
416 | 436 | ||
417 | PowerTempTimer = HAL_GetTick() + 1000; /* wait 10 seconds before powering up the CHT sensor */ |
437 | PowerTempTimer = HAL_GetTick() + 1000; /* wait 10 seconds before powering up the CHT sensor */ |
418 | 438 | ||
419 | ResetRxBuffer(&uc1); |
439 | ResetRxBuffer(&uc1); |
420 | 440 | ||
421 | PLX_SensorInfo info; ///< sensor info structure for getting idents |
- | |
422 | - | ||
423 | memset(obsIndex, 0, PLX_MAX_OBS); // zero incoming obsevation index |
441 | resetPLX(); |
424 | int infoCount = -1; ///< counting bytes when we are copying them across |
- | |
425 | /* USER CODE END 2 */ |
442 | /* USER CODE END 2 */ |
426 | 443 | ||
427 | /* Infinite loop */ |
444 | /* Infinite loop */ |
428 | /* USER CODE BEGIN WHILE */ |
445 | /* USER CODE BEGIN WHILE */ |
429 | while (1) |
446 | while (1) |
Line 478... | Line 495... | ||
478 | PowerTempTimer = 0; |
495 | PowerTempTimer = 0; |
479 | } |
496 | } |
480 | } |
497 | } |
481 | 498 | ||
482 | // check to see if we have any incoming data, copy and append if so, if no data then create our own frames. |
499 | // check to see if we have any incoming data, copy and append if so, if no data then create our own frames. |
483 | char send = 0; |
- | |
484 | - | ||
485 | // poll the input for a stop bit or timeout |
- | |
486 | if (PollSerial(&uc1)) |
- | |
487 | { |
- | |
488 | resetSerialTimeout(); |
- | |
489 | uint8_t c = GetCharSerial(&uc1); |
- | |
490 | // code added to read in all data, extract the observation index maximum for each type of data |
- | |
491 | if (c == PLX_Start) |
- | |
492 | { |
- | |
493 | infoCount = 0; |
- | |
494 | } |
- | |
495 | else |
- | |
496 | { |
- | |
497 | info.bytes[infoCount++] = c; |
- | |
498 | // process the sensor info field : discover maximum observation index |
- | |
499 | if (infoCount == sizeof(PLX_SensorInfo)) |
- | |
500 | { |
- | |
501 | infoCount = 0; |
- | |
502 | int addr = ConvPLXAddr(&info); |
- | |
503 | if (addr < PLX_MAX_OBS && (obsIndex[addr] <= info.Instance)) |
- | |
504 | obsIndex[addr] = info.Instance + 1; |
- | |
505 | } |
- | |
506 | } |
- | |
507 | - | ||
508 | if (c != PLX_Stop) |
- | |
509 | { |
- | |
510 | PutCharSerial(&uc1, c); // echo all but the stop bit |
- | |
511 | } |
- | |
512 | else |
- | |
513 | { // must be a stop character |
- | |
514 | send = 1; // start our sending process. |
- | |
515 | } |
- | |
516 | } |
- | |
517 | - | ||
518 | // sort out auto-sending |
- | |
519 | if (TimerFlag) |
- | |
520 | { |
- | |
521 | TimerFlag = 0; |
- | |
522 | if (NoSerialIn) |
- | |
523 | { |
- | |
524 | PutCharSerial(&uc1, PLX_Start); |
- | |
525 | send = 1; |
- | |
526 | } |
- | |
527 | } |
- | |
528 | if (send) |
- | |
529 | { |
- | |
530 | send = 0; |
- | |
531 | - | ||
532 | // send the observations |
- | |
533 | ProcessRPM(); |
- | |
534 | ProcessTemp(0, PLX_X_CHT); |
- | |
535 | ProcessTemp(1, PLX_X_CHT); |
- | |
536 | ProcessTemp(2, PLX_AIT); |
- | |
537 | ProcessTemp(3, PLX_AIT); |
- | |
538 | ProcessBatteryVoltage(0); // Batt 1 |
- | |
539 | ProcessBatteryVoltage(1); // Batt 2 |
- | |
540 | ProcessCPUTemperature(); // built in temperature sensor |
- | |
541 | - | ||
542 | ProcessMAP(); |
- | |
543 | ProcessOilPress(); |
- | |
544 | memset(obsIndex, 0, PLX_MAX_OBS); // zero incoming obsevation index |
- | |
545 | 500 | ||
- | 501 | // poll the input data and produce automatic output if the timer expires and no serial input data |
|
546 | PutCharSerial(&uc1, PLX_Stop); |
502 | libPLXpollData(&uc1, TimerFlag && NoSerialIn); |
547 | } |
- | |
548 | } |
503 | } |
549 | 504 | ||
550 | /* USER CODE END 3 */ |
505 | /* USER CODE END 3 */ |
551 | } |
506 | } |
552 | 507 |