Rev 11 | Rev 13 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 11 | Rev 12 | ||
|---|---|---|---|
| Line 66... | Line 66... | ||
| 66 | 66 | ||
| 67 | volatile char NoSerialInCTR = 0; // Missing characters coming in on USART1 |
67 | volatile char NoSerialInCTR = 0; // Missing characters coming in on USART1 |
| 68 | volatile char NoSerialIn = 0; |
68 | volatile char NoSerialIn = 0; |
| 69 | 69 | ||
| 70 | // storage for ADC |
70 | // storage for ADC |
| 71 | long ADC_samples[6]; |
71 | long ADC_Samples[6]; |
| 72 | 72 | ||
| 73 | // Rev counter processing from original RevCounter Project |
73 | // Rev counter processing from original RevCounter Project |
| 74 | unsigned int RPM_Diff = 0; |
74 | unsigned int RPM_Diff = 0; |
| 75 | unsigned int RPM_Count_Latch = 0; |
75 | unsigned int RPM_Count_Latch = 0; |
| 76 | // accumulators |
76 | // accumulators |
| Line 223... | Line 223... | ||
| 223 | } |
223 | } |
| 224 | 224 | ||
| 225 | plx_sendword(PLX_EGT); |
225 | plx_sendword(PLX_EGT); |
| 226 | PutCharSerial(&uc1, instance); |
226 | PutCharSerial(&uc1, instance); |
| 227 | plx_sendword(Coded_CHT); |
227 | plx_sendword(Coded_CHT); |
| 228 | PutCharSerial(&uc2,Coded_CHT + 32); |
- | |
| 229 | HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET); |
228 | HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET); |
| 230 | 229 | ||
| 231 | } |
230 | } |
| 232 | 231 | ||
| - | 232 | void ProcessBatteryVoltage(int instance) |
|
| - | 233 | { |
|
| - | 234 | plx_sendword(PLX_Volts); |
|
| - | 235 | PutCharSerial(&uc1, instance); |
|
| - | 236 | plx_sendword(ADC_Samples[instance]); |
|
| - | 237 | ||
| - | 238 | ||
| - | 239 | ||
| - | 240 | } |
|
| - | 241 | ||
| - | 242 | ||
| 233 | /* USER CODE END 0 */ |
243 | /* USER CODE END 0 */ |
| 234 | 244 | ||
| 235 | int main(void) |
245 | int main(void) |
| 236 | { |
246 | { |
| 237 | 247 | ||
| Line 269... | Line 279... | ||
| 269 | __HAL_RCC_ADC1_CLK_ENABLE() |
279 | __HAL_RCC_ADC1_CLK_ENABLE() |
| 270 | ; // enable the ADC |
280 | ; // enable the ADC |
| 271 | 281 | ||
| 272 | __HAL_RCC_TIM6_CLK_ENABLE() |
282 | __HAL_RCC_TIM6_CLK_ENABLE() |
| 273 | ; |
283 | ; |
| - | 284 | __HAL_RCC_TIM2_CLK_ENABLE(); |
|
| 274 | 285 | ||
| 275 | ConfigureDMA(); |
286 | ConfigureDMA(); |
| 276 | // HAL_ADC_Start_DMA(&g_AdcHandle, g_ADCBuffer, ADC_BUFFER_LENGTH); |
287 | HAL_ADC_Start_DMA(&hadc, ADC_Samples, 6); |
| 277 | 288 | ||
| 278 | /* setup the USART control blocks */ |
289 | /* setup the USART control blocks */ |
| 279 | init_usart_ctl(&uc1, huart1.Instance); |
290 | init_usart_ctl(&uc1, huart1.Instance); |
| 280 | init_usart_ctl(&uc2, huart2.Instance); |
291 | init_usart_ctl(&uc2, huart2.Instance); |
| 281 | 292 | ||
| 282 | EnableSerialRxInterrupt(&uc1); |
293 | EnableSerialRxInterrupt(&uc1); |
| 283 | EnableSerialRxInterrupt(&uc2); |
294 | EnableSerialRxInterrupt(&uc2); |
| 284 | 295 | ||
| 285 | HAL_TIM_Base_Start_IT(&htim6); |
296 | HAL_TIM_Base_Start_IT(&htim6); |
| - | 297 | HAL_TIM_Base_Start(&htim2); |
|
| - | 298 | ||
| - | 299 | __HAL_TIM_ENABLE_IT(&htim2, TIM_IT_CC1); |
|
| 286 | 300 | ||
| 287 | PutCharSerial(&uc2, 'A'); |
- | |
| 288 | 301 | ||
| 289 | /* USER CODE END 2 */ |
302 | /* USER CODE END 2 */ |
| 290 | 303 | ||
| 291 | /* Infinite loop */ |
304 | /* Infinite loop */ |
| 292 | /* USER CODE BEGIN WHILE */ |
305 | /* USER CODE BEGIN WHILE */ |
| Line 322... | Line 335... | ||
| 322 | } |
335 | } |
| 323 | if (send) |
336 | if (send) |
| 324 | { |
337 | { |
| 325 | send = 0; |
338 | send = 0; |
| 326 | 339 | ||
| - | 340 | uint16_t val; |
|
| - | 341 | val = __HAL_TIM_GET_COUNTER(&htim2); |
|
| - | 342 | PutCharSerial(&uc2,(val&31) + 32); |
|
| - | 343 | ||
| - | 344 | // send the observations |
|
| 327 | ProcessRPM(0); |
345 | ProcessRPM(0); |
| 328 | ProcessCHT(0); |
346 | ProcessCHT(0); |
| - | 347 | ProcessBatteryVoltage(0); |
|
| - | 348 | ProcessBatteryVoltage(1); |
|
| 329 | 349 | ||
| 330 | PutCharSerial(&uc1,PLX_Stop); |
350 | PutCharSerial(&uc1,PLX_Stop); |
| 331 | } |
351 | } |
| 332 | 352 | ||
| 333 | } |
353 | } |
| Line 488... | Line 508... | ||
| 488 | 508 | ||
| 489 | /* TIM2 init function */ |
509 | /* TIM2 init function */ |
| 490 | static void MX_TIM2_Init(void) |
510 | static void MX_TIM2_Init(void) |
| 491 | { |
511 | { |
| 492 | 512 | ||
| - | 513 | TIM_ClockConfigTypeDef sClockSourceConfig; |
|
| 493 | TIM_MasterConfigTypeDef sMasterConfig; |
514 | TIM_MasterConfigTypeDef sMasterConfig; |
| 494 | TIM_IC_InitTypeDef sConfigIC; |
515 | TIM_IC_InitTypeDef sConfigIC; |
| 495 | TIM_OC_InitTypeDef sConfigOC; |
516 | TIM_OC_InitTypeDef sConfigOC; |
| 496 | 517 | ||
| 497 | htim2.Instance = TIM2; |
518 | htim2.Instance = TIM2; |
| 498 | htim2.Init.Prescaler = 320; |
519 | htim2.Init.Prescaler = 320; |
| 499 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
520 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
| 500 | htim2.Init.Period = 0; |
521 | htim2.Init.Period = 0xFFFF; |
| 501 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
522 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
| - | 523 | if (HAL_TIM_Base_Init(&htim2) != HAL_OK) |
|
| - | 524 | { |
|
| - | 525 | Error_Handler(); |
|
| - | 526 | } |
|
| - | 527 | ||
| - | 528 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
|
| - | 529 | if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) |
|
| - | 530 | { |
|
| - | 531 | Error_Handler(); |
|
| - | 532 | } |
|
| - | 533 | ||
| 502 | if (HAL_TIM_IC_Init(&htim2) != HAL_OK) |
534 | if (HAL_TIM_IC_Init(&htim2) != HAL_OK) |
| 503 | { |
535 | { |
| 504 | Error_Handler(); |
536 | Error_Handler(); |
| 505 | } |
537 | } |
| 506 | 538 | ||