Rev 52 | Rev 54 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 52 | Rev 53 | ||
|---|---|---|---|
| Line 63... | Line 63... | ||
| 63 | ADC_HandleTypeDef hadc1; |
63 | ADC_HandleTypeDef hadc1; |
| 64 | DMA_HandleTypeDef hdma_adc1; |
64 | DMA_HandleTypeDef hdma_adc1; |
| 65 | 65 | ||
| 66 | CAN_HandleTypeDef hcan; |
66 | CAN_HandleTypeDef hcan; |
| 67 | 67 | ||
| - | 68 | IWDG_HandleTypeDef hiwdg; |
|
| - | 69 | ||
| 68 | SPI_HandleTypeDef hspi1; |
70 | SPI_HandleTypeDef hspi1; |
| 69 | 71 | ||
| 70 | TIM_HandleTypeDef htim2; |
72 | TIM_HandleTypeDef htim2; |
| 71 | TIM_HandleTypeDef htim3; |
73 | TIM_HandleTypeDef htim3; |
| 72 | TIM_HandleTypeDef htim4; |
74 | TIM_HandleTypeDef htim4; |
| 73 | 75 | ||
| 74 | UART_HandleTypeDef huart1; |
76 | UART_HandleTypeDef huart1; |
| 75 | 77 | ||
| 76 | /* USER CODE BEGIN PV */ |
78 | /* USER CODE BEGIN PV */ |
| 77 | 79 | ||
| - | 80 | // Storage for USART |
|
| - | 81 | #define USART_TX_BUFF_SIZE 256 |
|
| - | 82 | #define USART_RX_BUFF_SIZE 256 |
|
| - | 83 | uint8_t usartTxBuff[USART_TX_BUFF_SIZE]; |
|
| - | 84 | uint8_t usartRxBuff[USART_RX_BUFF_SIZE]; |
|
| - | 85 | ||
| 78 | // storage for ADC |
86 | // storage for ADC |
| 79 | uint16_t ADC_Samples[ADC_CHANNELS] = {[0 ... ADC_CHANNELS - 1] = 0}; |
87 | uint16_t ADC_Samples[ADC_CHANNELS] = {[0 ... ADC_CHANNELS - 1] = 0}; |
| 80 | 88 | ||
| 81 | uint32_t FILT_Samples[ADC_CHANNELS] = {[0 ... ADC_CHANNELS - 1] = 0}; // filtered ADC samples * Scale |
89 | uint32_t FILT_Samples[ADC_CHANNELS] = {[0 ... ADC_CHANNELS - 1] = 0}; // filtered ADC samples * Scale |
| 82 | 90 | ||
| Line 108... | Line 116... | ||
| 108 | static void MX_SPI1_Init(void); |
116 | static void MX_SPI1_Init(void); |
| 109 | static void MX_TIM2_Init(void); |
117 | static void MX_TIM2_Init(void); |
| 110 | static void MX_TIM3_Init(void); |
118 | static void MX_TIM3_Init(void); |
| 111 | static void MX_TIM4_Init(void); |
119 | static void MX_TIM4_Init(void); |
| 112 | static void MX_USART1_UART_Init(void); |
120 | static void MX_USART1_UART_Init(void); |
| - | 121 | static void MX_IWDG_Init(void); |
|
| 113 | /* USER CODE BEGIN PFP */ |
122 | /* USER CODE BEGIN PFP */ |
| 114 | 123 | ||
| 115 | /* USER CODE END PFP */ |
124 | /* USER CODE END PFP */ |
| 116 | 125 | ||
| 117 | /* Private user code ---------------------------------------------------------*/ |
126 | /* Private user code ---------------------------------------------------------*/ |
| 118 | /* USER CODE BEGIN 0 */ |
127 | /* USER CODE BEGIN 0 */ |
| 119 | - | ||
| 120 | void plx_sendword(int x) |
128 | void libPLXcallbackRecievedData(PLX_SensorInfo * data) |
| 121 | { |
129 | { |
| 122 | PutCharSerial(&uc1, ((x) >> 6) & 0x3F); |
- | |
| 123 | PutCharSerial(&uc1, (x)&0x3F); |
130 | (void )data; |
| - | 131 | ||
| 124 | } |
132 | } |
| 125 | 133 | ||
| - | 134 | ||
| 126 | void filter_ADC_samples() |
135 | void filter_ADC_samples() |
| 127 | { |
136 | { |
| 128 | int i; |
137 | int i; |
| 129 | for (i = 0; i < ADC_CHANNELS; i++) |
138 | for (i = 0; i < ADC_CHANNELS; i++) |
| 130 | { |
139 | { |
| Line 149... | Line 158... | ||
| 149 | 158 | ||
| 150 | void ProcessRPM(void) |
159 | void ProcessRPM(void) |
| 151 | { |
160 | { |
| 152 | static unsigned int Coded_RPM = 0; |
161 | static unsigned int Coded_RPM = 0; |
| 153 | int32_t rpm = CalculateRPM(); |
162 | int32_t rpm = CalculateRPM(); |
| - | 163 | // suppress the EDIS "heartbeat" 90 RPM |
|
| 154 | if (rpm >= 0) |
164 | if (rpm >= 100) |
| 155 | Coded_RPM = rpm / 19.55; |
165 | Coded_RPM = rpm / 19.55; |
| 156 | 166 | ||
| 157 | // send the current RPM *calculation |
167 | // send the current RPM *calculation |
| 158 | plx_sendword(PLX_RPM); |
- | |
| 159 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_RPM)); |
- | |
| - | 168 | ||
| 160 | plx_sendword(Coded_RPM / Scale); |
169 | sendPlxInfo(& uc1, PLX_RPM, Coded_RPM/ Scale); |
| - | 170 | ||
| - | 171 | ||
| 161 | } |
172 | } |
| 162 | 173 | ||
| 163 | // this uses a MAX6675 which is a simple 16 bit read |
174 | // this uses a MAX6675 which is a simple 16 bit read |
| 164 | // SPI is configured for 8 bits so I can use an OLED display if I need it |
175 | // SPI is configured for 8 bits so I can use an OLED display if I need it |
| 165 | // must wait > 0.22 seconds between conversion attempts as this is the measurement time |
176 | // must wait > 0.22 seconds between conversion attempts as this is the measurement time |
| Line 175... | Line 186... | ||
| 175 | /// \param type the code to use for this observation |
186 | /// \param type the code to use for this observation |
| 176 | void ProcessTemp(char item, enum PLX_Observations type) |
187 | void ProcessTemp(char item, enum PLX_Observations type) |
| 177 | { |
188 | { |
| 178 | if (item > NUM_SPI_TEMP_SENS) |
189 | if (item > NUM_SPI_TEMP_SENS) |
| 179 | return; |
190 | return; |
| 180 | plx_sendword(type); |
- | |
| 181 | PutCharSerial(&uc1, libPLXgetNextInstance(type)); |
- | |
| - | 191 | ||
| 182 | plx_sendword(Temp_Observations[(int)item]); |
192 | sendPlxInfo(& uc1, type , Temp_Observations[(int)item]); |
| - | 193 | ||
| 183 | } |
194 | } |
| 184 | 195 | ||
| 185 | /// \brief Reset the temperature chip select system |
196 | /// \brief Reset the temperature chip select system |
| 186 | void resetTempCS(void) |
197 | void resetTempCS(void) |
| 187 | { |
198 | { |
| Line 255... | Line 266... | ||
| 255 | { |
266 | { |
| 256 | float reading = FILT_Samples[item] * ADC_Scale; |
267 | float reading = FILT_Samples[item] * ADC_Scale; |
| 257 | reading = reading * 7.8125; // real voltage |
268 | reading = reading * 7.8125; // real voltage |
| 258 | reading = reading * 51.15; // PLC scaling = 1023/20 |
269 | reading = reading * 51.15; // PLC scaling = 1023/20 |
| 259 | 270 | ||
| 260 | plx_sendword(PLX_Volts); |
- | |
| 261 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_Volts)); |
- | |
| 262 | plx_sendword((uint16_t)reading); |
271 | sendPlxInfo(& uc1, PLX_Volts, reading); |
| - | 272 | ||
| 263 | } |
273 | } |
| 264 | 274 | ||
| 265 | void ProcessCPUTemperature(void) |
275 | void ProcessCPUTemperature(void) |
| 266 | { |
276 | { |
| 267 | // this is defined in the STM32F103 reference manual . # |
277 | // this is defined in the STM32F103 reference manual . # |
| Line 275... | Line 285... | ||
| 275 | /* renormalise temperature value to account for different ADC Vref : normalise to that which we would get for a 3000mV reference */ |
285 | /* renormalise temperature value to account for different ADC Vref : normalise to that which we would get for a 3000mV reference */ |
| 276 | temp_val = (1.43 - temp_val) / 4.3e-3 + 25; |
286 | temp_val = (1.43 - temp_val) / 4.3e-3 + 25; |
| 277 | 287 | ||
| 278 | int32_t result = temp_val; |
288 | int32_t result = temp_val; |
| 279 | 289 | ||
| 280 | // int32_t result = 800 * ((int32_t) temp_val - TS_CAL30); |
- | |
| 281 | // result = result / (TS_CAL110 - TS_CAL30) + 300; |
290 | sendPlxInfo(& uc1, PLX_FluidTemp, result); |
| 282 | 291 | ||
| 283 | plx_sendword(PLX_FluidTemp); |
- | |
| 284 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_FluidTemp)); |
- | |
| 285 | plx_sendword(result); |
- | |
| 286 | } |
292 | } |
| 287 | 293 | ||
| 288 | // the MAP sensor is giving us a reading of |
294 | // the MAP sensor is giving us a reading of |
| 289 | // 4.6 volts for 1019mB or 2.27 volts at the ADC input (resistive divider by 2.016) |
295 | // 4.6 volts for 1019mB or 2.27 volts at the ADC input (resistive divider by 2.016) |
| 290 | // I believe the sensor reads 4.5V at 1000kPa and 0.5V at 0kPa |
296 | // I believe the sensor reads 4.5V at 1000kPa and 0.5V at 0kPa |
| Line 300... | Line 306... | ||
| 300 | float reading = FILT_Samples[ADC_MAP_CHAN] * ADC_Scale; |
306 | float reading = FILT_Samples[ADC_MAP_CHAN] * ADC_Scale; |
| 301 | reading = reading * 2.016; // real voltage |
307 | reading = reading * 2.016; // real voltage |
| 302 | // values computed from slope / intercept of map.ods |
308 | // values computed from slope / intercept of map.ods |
| 303 | // 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 |
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 |
| 304 | // using a pressure gauge. |
310 | // using a pressure gauge. |
| 305 | reading = (reading)*150 + 326; |
311 | reading = (reading) * 150 + 326; |
| - | 312 | ||
| - | 313 | sendPlxInfo(& uc1, PLX_MAP, reading); |
|
| 306 | 314 | ||
| 307 | plx_sendword(PLX_MAP); |
- | |
| 308 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_MAP)); |
- | |
| 309 | plx_sendword((uint16_t)reading); |
- | |
| 310 | } |
315 | } |
| 311 | 316 | ||
| 312 | // the Oil pressi sensor is giving us a reading of |
317 | // the Oil pressi sensor is giving us a reading of |
| 313 | // 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) |
| 314 | // I believe the sensor reads 4.5V at 100PSI and 0.5V at 0PSI |
319 | // I believe the sensor reads 4.5V at 100PSI and 0.5V at 0PSI |
| Line 319... | Line 324... | ||
| 319 | // Using ADC_Samples[2] as the MAP input |
324 | // Using ADC_Samples[2] as the MAP input |
| 320 | float reading = FILT_Samples[ADC_PRESSURE_CHAN] * ADC_Scale; |
325 | float reading = FILT_Samples[ADC_PRESSURE_CHAN] * ADC_Scale; |
| 321 | reading = reading * 2.00; // real voltage |
326 | reading = reading * 2.00; // real voltage |
| 322 | reading = (reading - 0.5) * 512 / 4; // this is 1023 * 100/200 |
327 | reading = (reading - 0.5) * 512 / 4; // this is 1023 * 100/200 |
| 323 | 328 | ||
| 324 | plx_sendword(PLX_FluidPressure); |
329 | sendPlxInfo(& uc1, PLX_FluidPressure, reading); |
| 325 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_FluidPressure)); |
- | |
| 326 | plx_sendword((uint16_t)reading); |
- | |
| 327 | } |
- | |
| 328 | 330 | ||
| 329 | void ProcessTiming(void) |
- | |
| 330 | { |
- | |
| 331 | plx_sendword(PLX_Timing); |
- | |
| 332 | PutCharSerial(&uc1, libPLXgetNextInstance(PLX_Timing)); |
- | |
| 333 | plx_sendword(64 - 15); // make it negative |
- | |
| 334 | } |
331 | } |
| 335 | 332 | ||
| 336 | 333 | ||
| 337 | void libPLXcallbackSendUserData() |
334 | void libPLXcallbackSendUserData() |
| 338 | { |
335 | { |
| Line 387... | Line 384... | ||
| 387 | MX_SPI1_Init(); |
384 | MX_SPI1_Init(); |
| 388 | MX_TIM2_Init(); |
385 | MX_TIM2_Init(); |
| 389 | MX_TIM3_Init(); |
386 | MX_TIM3_Init(); |
| 390 | MX_TIM4_Init(); |
387 | MX_TIM4_Init(); |
| 391 | MX_USART1_UART_Init(); |
388 | MX_USART1_UART_Init(); |
| - | 389 | MX_IWDG_Init(); |
|
| 392 | /* USER CODE BEGIN 2 */ |
390 | /* USER CODE BEGIN 2 */ |
| 393 | HAL_MspInit(); |
391 | HAL_MspInit(); |
| 394 | 392 | ||
| 395 | // Not using HAL USART code |
393 | // Not using HAL USART code |
| 396 | __HAL_RCC_USART1_CLK_ENABLE(); // PLX comms port |
394 | __HAL_RCC_USART1_CLK_ENABLE(); // PLX comms port |
| 397 | /* setup the USART control blocks */ |
395 | /* setup the USART control blocks */ |
| 398 | init_usart_ctl(&uc1, &huart1); |
396 | init_usart_ctl(&uc1, &huart1, |
| - | 397 | usartTxBuff, |
|
| - | 398 | usartRxBuff, |
|
| - | 399 | USART_TX_BUFF_SIZE, |
|
| - | 400 | USART_RX_BUFF_SIZE); |
|
| 399 | 401 | ||
| 400 | EnableSerialRxInterrupt(&uc1); |
402 | EnableSerialRxInterrupt(&uc1); |
| 401 | 403 | ||
| 402 | HAL_SPI_MspInit(&hspi1); |
404 | HAL_SPI_MspInit(&hspi1); |
| 403 | 405 | ||
| Line 488... | Line 490... | ||
| 488 | 490 | ||
| 489 | // check to see if we have any incoming data, copy and append if so, if no data then create our own frames. |
491 | // check to see if we have any incoming data, copy and append if so, if no data then create our own frames. |
| 490 | 492 | ||
| 491 | // poll the input data and produce automatic output if the timer expires and no serial input data |
493 | // poll the input data and produce automatic output if the timer expires and no serial input data |
| 492 | libPLXpollData(&uc1); |
494 | libPLXpollData(&uc1); |
| - | 495 | ||
| - | 496 | HAL_IWDG_Refresh(&hiwdg); |
|
| 493 | } |
497 | } |
| 494 | 498 | ||
| 495 | /* USER CODE END 3 */ |
499 | /* USER CODE END 3 */ |
| 496 | } |
500 | } |
| 497 | 501 | ||
| Line 506... | Line 510... | ||
| 506 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
510 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
| 507 | 511 | ||
| 508 | /** Initializes the RCC Oscillators according to the specified parameters |
512 | /** Initializes the RCC Oscillators according to the specified parameters |
| 509 | * in the RCC_OscInitTypeDef structure. |
513 | * in the RCC_OscInitTypeDef structure. |
| 510 | */ |
514 | */ |
| 511 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
515 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSE; |
| 512 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
516 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
| 513 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
517 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
| 514 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
518 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
| - | 519 | RCC_OscInitStruct.LSIState = RCC_LSI_ON; |
|
| 515 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
520 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| 516 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
521 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
| 517 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
522 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
| 518 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
523 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
| 519 | { |
524 | { |
| Line 675... | Line 680... | ||
| 675 | 680 | ||
| 676 | /* USER CODE END CAN_Init 2 */ |
681 | /* USER CODE END CAN_Init 2 */ |
| 677 | } |
682 | } |
| 678 | 683 | ||
| 679 | /** |
684 | /** |
| - | 685 | * @brief IWDG Initialization Function |
|
| - | 686 | * @param None |
|
| - | 687 | * @retval None |
|
| - | 688 | */ |
|
| - | 689 | static void MX_IWDG_Init(void) |
|
| - | 690 | { |
|
| - | 691 | ||
| - | 692 | /* USER CODE BEGIN IWDG_Init 0 */ |
|
| - | 693 | ||
| - | 694 | /* USER CODE END IWDG_Init 0 */ |
|
| - | 695 | ||
| - | 696 | /* USER CODE BEGIN IWDG_Init 1 */ |
|
| - | 697 | ||
| - | 698 | /* USER CODE END IWDG_Init 1 */ |
|
| - | 699 | hiwdg.Instance = IWDG; |
|
| - | 700 | hiwdg.Init.Prescaler = IWDG_PRESCALER_64; |
|
| - | 701 | hiwdg.Init.Reload = 4095; |
|
| - | 702 | if (HAL_IWDG_Init(&hiwdg) != HAL_OK) |
|
| - | 703 | { |
|
| - | 704 | Error_Handler(); |
|
| - | 705 | } |
|
| - | 706 | /* USER CODE BEGIN IWDG_Init 2 */ |
|
| - | 707 | ||
| - | 708 | /* USER CODE END IWDG_Init 2 */ |
|
| - | 709 | } |
|
| - | 710 | ||
| - | 711 | /** |
|
| 680 | * @brief SPI1 Initialization Function |
712 | * @brief SPI1 Initialization Function |
| 681 | * @param None |
713 | * @param None |
| 682 | * @retval None |
714 | * @retval None |
| 683 | */ |
715 | */ |
| 684 | static void MX_SPI1_Init(void) |
716 | static void MX_SPI1_Init(void) |
| Line 935... | Line 967... | ||
| 935 | * @retval None |
967 | * @retval None |
| 936 | */ |
968 | */ |
| 937 | static void MX_GPIO_Init(void) |
969 | static void MX_GPIO_Init(void) |
| 938 | { |
970 | { |
| 939 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
971 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| - | 972 | /* USER CODE BEGIN MX_GPIO_Init_1 */ |
|
| - | 973 | /* USER CODE END MX_GPIO_Init_1 */ |
|
| 940 | 974 | ||
| 941 | /* GPIO Ports Clock Enable */ |
975 | /* GPIO Ports Clock Enable */ |
| 942 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
976 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
| 943 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
977 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
| 944 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
978 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| Line 967... | Line 1001... | ||
| 967 | /*Configure GPIO pin : STARTER_ON_Pin */ |
1001 | /*Configure GPIO pin : STARTER_ON_Pin */ |
| 968 | GPIO_InitStruct.Pin = STARTER_ON_Pin; |
1002 | GPIO_InitStruct.Pin = STARTER_ON_Pin; |
| 969 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
1003 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
| 970 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1004 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 971 | HAL_GPIO_Init(STARTER_ON_GPIO_Port, &GPIO_InitStruct); |
1005 | HAL_GPIO_Init(STARTER_ON_GPIO_Port, &GPIO_InitStruct); |
| - | 1006 | ||
| - | 1007 | /* USER CODE BEGIN MX_GPIO_Init_2 */ |
|
| - | 1008 | /* USER CODE END MX_GPIO_Init_2 */ |
|
| 972 | } |
1009 | } |
| 973 | 1010 | ||
| 974 | /* USER CODE BEGIN 4 */ |
1011 | /* USER CODE BEGIN 4 */ |
| 975 | 1012 | ||
| 976 | /* USER CODE END 4 */ |
1013 | /* USER CODE END 4 */ |