LW21-01B/BSP/Driver/speed/speed_to_hall.c

62 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "speed_to_hall.h"
speed_hall g_speed_to_hall = {0};
/**
* @brief 初始化定时器+霍尔计算速度
* @param
* @retval
*
*/
void init_hall_speed_module(void)
{
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER6);
timer_struct_para_init(&timer_initpara);
timer_deinit(TIMER6);
// TIMER1 configuration
timer_initpara.prescaler = 99;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;//计数模式,边缘对齐
timer_initpara.counterdirection = TIMER_COUNTER_UP;//计数方向
timer_initpara.period = SPEED_TIMER_PERIOD;//计数重装载值确定周期该值可在任意时刻进行修改以改变周期TIMER_CAR(timer_periph) = (uint32_t)initpara->period;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;//时钟分频
timer_initpara.repetitioncounter = 0;//计数重复值
timer_init(TIMER6, &timer_initpara);
timer_auto_reload_shadow_enable(TIMER6);
timer_enable(TIMER6);
timer_interrupt_enable(TIMER6, TIMER_INT_UP);//定时器更新中断使能
nvic_irq_enable(TIMER6_IRQn, 2U, 2U);
g_speed_to_hall.hori_speed_t.flag = calculation_disable;
g_speed_to_hall.vert_speed_t.flag = calculation_disable;
}
/**
* @brief 定时器1中断服务函数
* @param
* @retval
*
*/
void TIMER6_IRQHandler(void)
{
if(RESET != timer_interrupt_flag_get(TIMER6, TIMER_INT_FLAG_UP)) {
g_speed_to_hall.time_60ms++;
if (g_speed_to_hall.time_60ms >= TIME_60MS_MAX) {
g_speed_to_hall.time_60ms = 0;
}
timer_interrupt_flag_clear(TIMER6, TIMER_INT_FLAG_UP);
}
}