Rev 41 | Rev 43 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 41 | Rev 42 | ||
|---|---|---|---|
| Line 89... | Line 89... | ||
| 89 | 89 | ||
| 90 | // scale for filtered samples |
90 | // scale for filtered samples |
| 91 | #define Scale 1024.0 |
91 | #define Scale 1024.0 |
| 92 | 92 | ||
| 93 | // storage for ADC |
93 | // storage for ADC |
| 94 | uint16_t ADC_Samples[ADC_CHANNELS]; |
94 | uint16_t ADC_Samples[ADC_CHANNELS] = { [0 ... ADC_CHANNELS-1] = 0 }; |
| 95 | 95 | ||
| 96 | uint32_t FILT_Samples[ADC_CHANNELS]; // filtered ADC samples * Scale |
96 | uint32_t FILT_Samples[ADC_CHANNELS] = { [0 ... ADC_CHANNELS-1] = 0 }; // filtered ADC samples * Scale |
| 97 | 97 | ||
| 98 | 98 | ||
| 99 | #define NOM_VREF 3.3 |
99 | #define NOM_VREF 3.3 |
| 100 | // initial ADC vref |
100 | // initial ADC vref |
| 101 | float adc_vref = NOM_VREF; |
101 | float adc_vref = NOM_VREF; |
| Line 119... | Line 119... | ||
| 119 | unsigned int RPM_Period_Ptr = 0; |
119 | unsigned int RPM_Period_Ptr = 0; |
| 120 | 120 | ||
| 121 | unsigned int Coded_RPM = 0; |
121 | unsigned int Coded_RPM = 0; |
| 122 | unsigned int Coded_CHT = 0; |
122 | unsigned int Coded_CHT = 0; |
| 123 | 123 | ||
| 124 | uint32_t Power_CHT_Timer; |
124 | uint32_t PowerTempTimer; |
| 125 | 125 | ||
| 126 | uint16_t Starter_Debounce = 0; |
126 | uint16_t Starter_Debounce = 0; |
| 127 | 127 | ||
| 128 | /* USER CODE END PV */ |
128 | /* USER CODE END PV */ |
| 129 | 129 | ||
| Line 151... | Line 151... | ||
| 151 | PutCharSerial (&uc1, ((x) >> 6) & 0x3F); |
151 | PutCharSerial (&uc1, ((x) >> 6) & 0x3F); |
| 152 | PutCharSerial (&uc1, (x) & 0x3F); |
152 | PutCharSerial (&uc1, (x) & 0x3F); |
| 153 | } |
153 | } |
| 154 | 154 | ||
| 155 | void |
155 | void |
| 156 | init_ADC_filter () |
- | |
| 157 | { |
- | |
| 158 | int i; |
- | |
| 159 | for (i = 0; i < ADC_CHANNELS; i++) |
- | |
| 160 | { |
- | |
| 161 | FILT_Samples[i] = 0; |
- | |
| 162 | } |
- | |
| 163 | } |
- | |
| 164 | - | ||
| 165 | void |
- | |
| 166 | filter_ADC_samples () |
156 | filter_ADC_samples () |
| 167 | { |
157 | { |
| 168 | int i; |
158 | int i; |
| 169 | for (i = 0; i < ADC_CHANNELS; i++) |
159 | for (i = 0; i < ADC_CHANNELS; i++) |
| 170 | { |
160 | { |
| Line 276... | Line 266... | ||
| 276 | 266 | ||
| 277 | FunctionalState CHT_Enable = ENABLE; |
267 | FunctionalState CHT_Enable = ENABLE; |
| 278 | 268 | ||
| 279 | #define CORR 3 |
269 | #define CORR 3 |
| 280 | 270 | ||
| 281 | uint16_t CHT_Observations[2] = |
271 | uint16_t Temp_Observations[NUM_SPI_TEMP_SENS] = { [0 ... NUM_SPI_TEMP_SENS-1] = 0 }; |
| 282 | { 0, 0 }; |
- | |
| 283 | 272 | ||
| 284 | // look for the trigger pin being high then low - the points |
- | |
| 285 | // are opening, and skip the reading |
- | |
| 286 | 273 | ||
| - | 274 | /// \param item The array index to send |
|
| - | 275 | /// \param instance The instance to send over the bus |
|
| - | 276 | /// \param type the code to use for this observation |
|
| 287 | void |
277 | void |
| 288 | ProcessCHT (int instance) |
278 | ProcessTemp (char item, int instance, enum PLX_Observations type) |
| 289 | { |
279 | { |
| - | 280 | if (item > NUM_SPI_TEMP_SENS) |
|
| - | 281 | return; |
|
| 290 | plx_sendword (PLX_X_CHT); |
282 | plx_sendword (type); |
| 291 | PutCharSerial (&uc1, instance); |
283 | PutCharSerial (&uc1, instance); |
| 292 | plx_sendword (CHT_Observations[instance]); |
284 | plx_sendword (Temp_Observations[item]); |
| 293 | 285 | ||
| 294 | } |
286 | } |
| 295 | 287 | ||
| - | 288 | ||
| - | 289 | /// \brief Reset the temperature chip select system |
|
| - | 290 | void resetTempCS(void) |
|
| - | 291 | { |
|
| - | 292 | HAL_GPIO_WritePin (SPI_CS_D_GPIO_Port, SPI_CS_D_Pin, GPIO_PIN_SET); |
|
| - | 293 | HAL_GPIO_WritePin (SPI_CS_Clk_GPIO_Port, SPI_CS_Clk_Pin, |
|
| - | 294 | GPIO_PIN_SET); |
|
| - | 295 | ||
| - | 296 | for (int i = 0 ; i < 4; i++) |
|
| - | 297 | { |
|
| - | 298 | HAL_GPIO_WritePin (SPI_CS_Clk_GPIO_Port, SPI_CS_Clk_Pin, |
|
| - | 299 | GPIO_PIN_RESET); |
|
| - | 300 | HAL_GPIO_WritePin (SPI_CS_Clk_GPIO_Port, SPI_CS_Clk_Pin, |
|
| - | 301 | GPIO_PIN_SET); |
|
| - | 302 | } |
|
| - | 303 | ||
| - | 304 | // prepare for selecting next pin |
|
| - | 305 | HAL_GPIO_WritePin (SPI_CS_D_GPIO_Port, SPI_CS_D_Pin, GPIO_PIN_RESET); |
|
| - | 306 | ||
| - | 307 | } |
|
| - | 308 | ||
| - | 309 | void nextTempCS(void) |
|
| - | 310 | { |
|
| - | 311 | HAL_GPIO_WritePin (SPI_CS_Clk_GPIO_Port, SPI_CS_Clk_Pin, |
|
| - | 312 | GPIO_PIN_RESET); |
|
| - | 313 | HAL_GPIO_WritePin (SPI_CS_Clk_GPIO_Port, SPI_CS_Clk_Pin, |
|
| - | 314 | GPIO_PIN_SET); |
|
| - | 315 | HAL_GPIO_WritePin (SPI_CS_D_GPIO_Port, SPI_CS_D_Pin, GPIO_PIN_SET); |
|
| - | 316 | } |
|
| - | 317 | ||
| 296 | void |
318 | void |
| 297 | EnableCHT (FunctionalState state) |
319 | EnableTempSensors (FunctionalState state) |
| 298 | 320 | ||
| 299 | { |
321 | { |
| 300 | GPIO_InitTypeDef GPIO_InitStruct; |
322 | GPIO_InitTypeDef GPIO_InitStruct; |
| 301 | 323 | ||
| 302 | CHT_Enable = state; |
324 | CHT_Enable = state; |
| 303 | 325 | ||
| 304 | /* enable SPI in live mode : assume it and its GPIOs are already initialised in SPI mode */ |
326 | /* enable SPI in live mode : assume it and its GPIOs are already initialised in SPI mode */ |
| 305 | if (state == ENABLE) |
327 | if (state == ENABLE) |
| 306 | { |
328 | { |
| 307 | HAL_GPIO_WritePin (ENA_AUX_5V_GPIO_Port, ENA_AUX_5V_Pin, GPIO_PIN_SET); |
329 | HAL_GPIO_WritePin (ENA_AUX_5V_GPIO_Port, ENA_AUX_5V_Pin, GPIO_PIN_SET); |
| 308 | HAL_GPIO_WritePin (SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET); |
- | |
| 309 | HAL_GPIO_WritePin (SPI_NS_Temp2_GPIO_Port, SPI_NS_Temp2_Pin, |
- | |
| - | 330 | ||
| 310 | GPIO_PIN_SET); |
331 | resetTempCS(); |
| 311 | 332 | ||
| 312 | /* put the SPI pins back into SPI AF mode */ |
333 | /* put the SPI pins back into SPI AF mode */ |
| 313 | GPIO_InitStruct.Pin = SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin; |
334 | GPIO_InitStruct.Pin = SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin; |
| 314 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
335 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 315 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
336 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| Line 319... | Line 340... | ||
| 319 | } |
340 | } |
| 320 | else |
341 | else |
| 321 | { |
342 | { |
| 322 | /* Power down the SPI interface taking signals all low */ |
343 | /* Power down the SPI interface taking signals all low */ |
| 323 | HAL_GPIO_WritePin (ENA_AUX_5V_GPIO_Port, ENA_AUX_5V_Pin, GPIO_PIN_RESET); |
344 | HAL_GPIO_WritePin (ENA_AUX_5V_GPIO_Port, ENA_AUX_5V_Pin, GPIO_PIN_RESET); |
| 324 | HAL_GPIO_WritePin (SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, |
- | |
| 325 | GPIO_PIN_RESET); |
- | |
| 326 | HAL_GPIO_WritePin (SPI_NS_Temp2_GPIO_Port, SPI_NS_Temp2_Pin, |
- | |
| 327 | GPIO_PIN_RESET); |
- | |
| 328 | 345 | ||
| 329 | HAL_GPIO_WritePin (SPI1_SCK_GPIO_Port, |
346 | HAL_GPIO_WritePin (SPI1_SCK_GPIO_Port, |
| 330 | SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin, |
347 | SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin, |
| 331 | GPIO_PIN_RESET); |
348 | GPIO_PIN_RESET); |
| 332 | 349 | ||
| Line 507... | Line 524... | ||
| 507 | HAL_TIM_Base_MspInit (&htim3); |
524 | HAL_TIM_Base_MspInit (&htim3); |
| 508 | __HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE); |
525 | __HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE); |
| 509 | uint32_t Ticks = HAL_GetTick () + 100; |
526 | uint32_t Ticks = HAL_GetTick () + 100; |
| 510 | int CalCounter = 0; |
527 | int CalCounter = 0; |
| 511 | 528 | ||
| 512 | Power_CHT_Timer = HAL_GetTick () + 1000; /* wait 10 seconds before powering up the CHT sensor */ |
529 | PowerTempTimer = HAL_GetTick () + 1000; /* wait 10 seconds before powering up the CHT sensor */ |
| 513 | 530 | ||
| 514 | /* USER CODE END 2 */ |
531 | /* USER CODE END 2 */ |
| 515 | 532 | ||
| 516 | /* Infinite loop */ |
533 | /* Infinite loop */ |
| 517 | /* USER CODE BEGIN WHILE */ |
534 | /* USER CODE BEGIN WHILE */ |
| Line 554... | Line 571... | ||
| 554 | } |
571 | } |
| 555 | } |
572 | } |
| 556 | 573 | ||
| 557 | if (Starter_Debounce == STARTER_LIMIT) |
574 | if (Starter_Debounce == STARTER_LIMIT) |
| 558 | { |
575 | { |
| 559 | EnableCHT (DISABLE); |
576 | EnableTempSensors (DISABLE); |
| 560 | Power_CHT_Timer = HAL_GetTick () + 1000; |
577 | PowerTempTimer = HAL_GetTick () + 1000; |
| 561 | } |
578 | } |
| 562 | else |
579 | else |
| 563 | /* if the Power_CHT_Timer is set then wait for it to timeout, then power up CHT */ |
580 | /* if the PowerTempTimer is set then wait for it to timeout, then power up CHT */ |
| 564 | { |
581 | { |
| 565 | if ((Power_CHT_Timer > 0) && (HAL_GetTick () > Power_CHT_Timer)) |
582 | if ((PowerTempTimer > 0) && (HAL_GetTick () > PowerTempTimer)) |
| 566 | { |
583 | { |
| 567 | EnableCHT (ENABLE); |
584 | EnableTempSensors (ENABLE); |
| 568 | Power_CHT_Timer = 0; |
585 | PowerTempTimer = 0; |
| 569 | } |
586 | } |
| 570 | } |
587 | } |
| 571 | 588 | ||
| 572 | // check to see if we have any incoming data, copy and append if so, if no data then create our own frames. |
589 | // check to see if we have any incoming data, copy and append if so, if no data then create our own frames. |
| 573 | int c; |
590 | int c; |
| Line 602... | Line 619... | ||
| 602 | { |
619 | { |
| 603 | send = 0; |
620 | send = 0; |
| 604 | 621 | ||
| 605 | // send the observations |
622 | // send the observations |
| 606 | ProcessRPM (0); |
623 | ProcessRPM (0); |
| - | 624 | ProcessTemp (0,0,PLX_X_CHT); |
|
| - | 625 | ProcessTemp (1,1,PLX_X_CHT); |
|
| 607 | ProcessCHT (0); |
626 | ProcessTemp (2,0,PLX_AIT); |
| 608 | ProcessCHT (1); |
627 | ProcessTemp (3,1,PLX_AIT); |
| 609 | ProcessBatteryVoltage (0); // Batt 1 |
628 | ProcessBatteryVoltage (0); // Batt 1 |
| 610 | ProcessBatteryVoltage (1); // Batt 2 |
629 | ProcessBatteryVoltage (1); // Batt 2 |
| 611 | ProcessCPUTemperature (0); // built in temperature sensor |
630 | ProcessCPUTemperature (0); // built in temperature sensor |
| 612 | 631 | ||
| 613 | ProcessMAP (0); |
632 | ProcessMAP (0); |
| Line 1072... | Line 1091... | ||
| 1072 | 1091 | ||
| 1073 | /*Configure GPIO pin Output Level */ |
1092 | /*Configure GPIO pin Output Level */ |
| 1074 | HAL_GPIO_WritePin(LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET); |
1093 | HAL_GPIO_WritePin(LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET); |
| 1075 | 1094 | ||
| 1076 | /*Configure GPIO pin Output Level */ |
1095 | /*Configure GPIO pin Output Level */ |
| 1077 | HAL_GPIO_WritePin(GPIOB, SPI_NS_Temp_Pin|SPI_NS_Temp2_Pin|ENA_AUX_5V_Pin, GPIO_PIN_RESET); |
1096 | HAL_GPIO_WritePin(GPIOB, SPI_CS_D_Pin|SPI_CS_Clk_Pin|ENA_AUX_5V_Pin, GPIO_PIN_RESET); |
| 1078 | 1097 | ||
| 1079 | /*Configure GPIO pin : LED_Blink_Pin */ |
1098 | /*Configure GPIO pin : LED_Blink_Pin */ |
| 1080 | GPIO_InitStruct.Pin = LED_Blink_Pin; |
1099 | GPIO_InitStruct.Pin = LED_Blink_Pin; |
| 1081 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1100 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 1082 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1101 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 1083 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
1102 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| 1084 | HAL_GPIO_Init(LED_Blink_GPIO_Port, &GPIO_InitStruct); |
1103 | HAL_GPIO_Init(LED_Blink_GPIO_Port, &GPIO_InitStruct); |
| 1085 | 1104 | ||
| 1086 | /*Configure GPIO pins : SPI_NS_Temp_Pin SPI_NS_Temp2_Pin ENA_AUX_5V_Pin */ |
1105 | /*Configure GPIO pins : SPI_CS_D_Pin SPI_CS_Clk_Pin ENA_AUX_5V_Pin */ |
| 1087 | GPIO_InitStruct.Pin = SPI_NS_Temp_Pin|SPI_NS_Temp2_Pin|ENA_AUX_5V_Pin; |
1106 | GPIO_InitStruct.Pin = SPI_CS_D_Pin|SPI_CS_Clk_Pin|ENA_AUX_5V_Pin; |
| 1088 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1107 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 1089 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1108 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 1090 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
1109 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| 1091 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
1110 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| 1092 | 1111 | ||