chargeController/APP/functionalModule/Src/FM_TIM.c

92 lines
1.9 KiB
C
Raw Normal View History

2024-12-06 13:23:28 +00:00
#include "FM_TIM.h"
#include "timeSliceOffset.h"
#include "capture.h"
2024-12-06 13:23:28 +00:00
static int PWM_RESOLUTION;
/**
* @brief
* @param None
* @retval None
*/
void tim_Init(void)
2024-12-06 13:23:28 +00:00
{
HD_PWM_Init();
/* 得到pwm的分辨率 */
2024-12-06 13:23:28 +00:00
PWM_RESOLUTION = HAL_RCC_GetHCLKFreq() / 100000;
HD_controlTim_Init();
HD_taskBaseTim_Init();
HD_checkAbnormalTim_Init();
2024-12-06 13:23:28 +00:00
}
void pwm_Stop(void)
{
set_pwmPulse(0);
// HAL_TIM_OC_MspDeInit(&htim3);
HAL_TIM_PWM_MspDeInit(&htim3);
2024-12-06 13:23:28 +00:00
}
/**
* @brief
* @param Pulse
* @retval None
*/
void set_pwmPulse(uint32_t Pulse)
{
if (Pulse > PWM_RESOLUTION) {
return;
}
__HAL_TIM_SetCompare(&htim3, TIM_CHANNEL_4, Pulse);
}
/**
* @brief
* @param DutyRatio
* @retval None
*/
void set_pwmDutyRatio(float DutyRatio)
{
uint32_t Pulse = (int)(DutyRatio * PWM_RESOLUTION);
set_pwmPulse(Pulse);
}
/**
* @brief Period elapsed callback in non blocking mode
* @note This function is called when TIM1 interrupt took place, inside
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
* a global variable "uwTick" used as application time base.
* @param htim : TIM handle
* @retval None
*/
/**
* @brief
* @param htim
* @retval None
*/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* USER CODE BEGIN Callback 0 */
/* USER CODE END Callback 0 */
if (htim->Instance == TIM1) {
HAL_IncTick();
}
/* USER CODE BEGIN Callback 1 */
if (htim->Instance == TIM7) {
chargControl();
}
if (htim->Instance == TIM16) {
TimeSliceOffset_Produce();
}
if (htim->Instance == TIM17) {
checkAbnormal();
}
2024-12-06 13:23:28 +00:00
/* USER CODE END Callback 1 */
}