Limit main loop to 10 Hz
This commit is contained in:
		@ -41,12 +41,11 @@ extern "C" {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* Exported constants --------------------------------------------------------*/
 | 
					/* Exported constants --------------------------------------------------------*/
 | 
				
			||||||
/* USER CODE BEGIN EC */
 | 
					/* USER CODE BEGIN EC */
 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END EC */
 | 
					/* USER CODE END EC */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Exported macro ------------------------------------------------------------*/
 | 
					/* Exported macro ------------------------------------------------------------*/
 | 
				
			||||||
/* USER CODE BEGIN EM */
 | 
					/* USER CODE BEGIN EM */
 | 
				
			||||||
 | 
					#define MAIN_LOOP_PERIOD 100 /* ms */
 | 
				
			||||||
/* USER CODE END EM */
 | 
					/* USER CODE END EM */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Exported functions prototypes ---------------------------------------------*/
 | 
					/* Exported functions prototypes ---------------------------------------------*/
 | 
				
			||||||
@ -54,6 +53,7 @@ void Error_Handler(void);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* USER CODE BEGIN EFP */
 | 
					/* USER CODE BEGIN EFP */
 | 
				
			||||||
void update_status_leds();
 | 
					void update_status_leds();
 | 
				
			||||||
 | 
					void delay_period();
 | 
				
			||||||
/* USER CODE END EFP */
 | 
					/* USER CODE END EFP */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Private defines -----------------------------------------------------------*/
 | 
					/* Private defines -----------------------------------------------------------*/
 | 
				
			||||||
 | 
				
			|||||||
@ -85,6 +85,19 @@ void update_status_leds() {
 | 
				
			|||||||
    HAL_GPIO_WritePin(STAT_LED2_GPIO_Port, STAT_LED2_Pin, GPIO_PIN_SET);
 | 
					    HAL_GPIO_WritePin(STAT_LED2_GPIO_Port, STAT_LED2_Pin, GPIO_PIN_SET);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void delay_period() {
 | 
				
			||||||
 | 
					  static uint32_t last_it = 0;
 | 
				
			||||||
 | 
					  uint32_t now = HAL_GetTick();
 | 
				
			||||||
 | 
					  int32_t diff = now - last_it;
 | 
				
			||||||
 | 
					  if (diff > 100) {
 | 
				
			||||||
 | 
					    HAL_GPIO_WritePin(STAT_LED3_GPIO_Port, STAT_LED3_Pin, GPIO_PIN_SET);
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    HAL_GPIO_WritePin(STAT_LED3_GPIO_Port, STAT_LED3_Pin, GPIO_PIN_RESET);
 | 
				
			||||||
 | 
					    HAL_Delay(100 - diff);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  last_it = now;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
/* USER CODE END 0 */
 | 
					/* USER CODE END 0 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -136,6 +149,7 @@ int main(void) {
 | 
				
			|||||||
    /* USER CODE BEGIN 3 */
 | 
					    /* USER CODE BEGIN 3 */
 | 
				
			||||||
    update_status_leds();
 | 
					    update_status_leds();
 | 
				
			||||||
    afe_measure();
 | 
					    afe_measure();
 | 
				
			||||||
 | 
					    delay_period();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  /* USER CODE END 3 */
 | 
					  /* USER CODE END 3 */
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user