Limit main loop frequency
This commit is contained in:
parent
38590d433b
commit
9fa034f10f
@ -41,7 +41,7 @@ extern "C" {
|
|||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN EC */
|
/* USER CODE BEGIN EC */
|
||||||
|
#define MAIN_LOOP_PERIOD 50 /* ms */
|
||||||
/* USER CODE END EC */
|
/* USER CODE END EC */
|
||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "stm32g4xx_hal.h"
|
#include "stm32g4xx_hal.h"
|
||||||
#include "stm32g4xx_hal_gpio.h"
|
#include "stm32g4xx_hal_gpio.h"
|
||||||
|
#include "stm32g4xx_hal_tim.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -74,7 +75,14 @@ static void MX_TIM2_Init(void);
|
|||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
|
void loop_delay() {
|
||||||
|
static uint32_t last_loop = 0;
|
||||||
|
int32_t diff = MAIN_LOOP_PERIOD - (HAL_GetTick() - last_loop);
|
||||||
|
if (diff > 0) {
|
||||||
|
HAL_Delay(diff);
|
||||||
|
}
|
||||||
|
last_loop = HAL_GetTick();
|
||||||
|
}
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,6 +142,7 @@ int main(void) {
|
|||||||
// vehicle_send_mission_select(MISSION_ACCELERATION);
|
// vehicle_send_mission_select(MISSION_ACCELERATION);
|
||||||
last_can = now;
|
last_can = now;
|
||||||
}
|
}
|
||||||
|
loop_delay();
|
||||||
}
|
}
|
||||||
/* USER CODE END 3 */
|
/* USER CODE END 3 */
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user