Run main loop every 50ms
This commit is contained in:
parent
f09665ad28
commit
f5e26aad24
|
@ -70,7 +70,19 @@ static void MX_USART1_UART_Init(void);
|
|||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
#define MAIN_LOOP_PERIOD 50
|
||||
|
||||
static void loop_delay() {
|
||||
static uint32_t last_loop = 0;
|
||||
uint32_t dt = HAL_GetTick() - last_loop;
|
||||
if (dt < MAIN_LOOP_PERIOD) {
|
||||
HAL_Delay(MAIN_LOOP_PERIOD - dt);
|
||||
HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_RESET);
|
||||
} else {
|
||||
HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
last_loop = HAL_GetTick();
|
||||
}
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
|
@ -127,7 +139,7 @@ int main(void) {
|
|||
soc_update();
|
||||
can_send_status();
|
||||
|
||||
HAL_Delay(10);
|
||||
loop_delay();
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue