392 lines
13 KiB
C
392 lines
13 KiB
C
|
#include "gd32f4xx_timer.h"
|
|||
|
#include "Timer.h"
|
|||
|
#include "gd32f4xx_rcu.h"
|
|||
|
#include "ptz_type_select.h"
|
|||
|
#include "ptz_struct.h"
|
|||
|
#include <includes.h>
|
|||
|
#include "gd32f4xx_it.h"
|
|||
|
|
|||
|
#ifdef TMC2160
|
|||
|
|
|||
|
#define timer_frequence 2000000 //<2F><>ʱ<EFBFBD><CAB1>Ƶ<EFBFBD><C6B5>1MHZ
|
|||
|
|
|||
|
|
|||
|
/*!
|
|||
|
\brief none ˮƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>
|
|||
|
\param[in] none
|
|||
|
\param[out] none
|
|||
|
\retval none
|
|||
|
\note LH @2022.07.11
|
|||
|
*/
|
|||
|
void ptz_hori_timer_start(unsigned int f)
|
|||
|
{
|
|||
|
unsigned int counter,chcv;
|
|||
|
counter = (unsigned int)(timer_frequence / f + 0.5);
|
|||
|
chcv = (unsigned int)(counter / 2.0 +0.5);
|
|||
|
TIMER_CAR(TIMER3) = counter;
|
|||
|
TIMER_CH0CV(TIMER3) = chcv;
|
|||
|
timer_enable(TIMER3);
|
|||
|
}
|
|||
|
|
|||
|
/*!
|
|||
|
\brief none ˮƽֹͣ
|
|||
|
\param[in] none
|
|||
|
\param[out] none
|
|||
|
\retval none
|
|||
|
\note LH @2022.07.11
|
|||
|
*/
|
|||
|
void ptz_hori_timer_stop()
|
|||
|
{
|
|||
|
TIMER_CH0CV(TIMER3) = 0;
|
|||
|
timer_disable(TIMER3);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*!
|
|||
|
\brief none <EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>
|
|||
|
\param[in] none
|
|||
|
\param[out] none
|
|||
|
\retval none
|
|||
|
\note LH @2022.07.11
|
|||
|
*/
|
|||
|
void ptz_vert_timer_start(unsigned int f)
|
|||
|
{
|
|||
|
unsigned int counter,chcv;
|
|||
|
counter = (unsigned int)(timer_frequence / f + 0.5);
|
|||
|
chcv = (unsigned int)(counter / 2.0 +0.5);
|
|||
|
TIMER_CAR(TIMER2) = counter;
|
|||
|
TIMER_CH0CV(TIMER2) = chcv;
|
|||
|
timer_enable(TIMER2);
|
|||
|
}
|
|||
|
|
|||
|
/*!
|
|||
|
\brief none <EFBFBD><EFBFBD>ֱֹͣ
|
|||
|
\param[in] none
|
|||
|
\param[out] none
|
|||
|
\retval none
|
|||
|
\note LH @2022.07.11
|
|||
|
*/
|
|||
|
void ptz_vert_timer_stop()
|
|||
|
{
|
|||
|
TIMER_CH0CV(TIMER2) = 0;
|
|||
|
timer_disable(TIMER2);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*!
|
|||
|
\brief none <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
\param[in] none
|
|||
|
\param[out] none
|
|||
|
\retval none
|
|||
|
\note LH @2022.07.11
|
|||
|
*/
|
|||
|
static void Step_timer_cfg(void)
|
|||
|
{//APB1<42><31><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ƶ<EFBFBD><C6B5>50MHz
|
|||
|
timer_parameter_struct timer_initpara;
|
|||
|
timer_oc_parameter_struct timer_ocintpara;
|
|||
|
|
|||
|
rcu_periph_clock_enable(RCU_TIMER2);
|
|||
|
rcu_periph_clock_enable(RCU_TIMER3);
|
|||
|
// rcu_timer_clock_prescaler_config(RCU_TIMER_PSC_MUL4);
|
|||
|
timer_struct_para_init(&timer_initpara);
|
|||
|
timer_deinit(TIMER2);
|
|||
|
timer_deinit(TIMER3);
|
|||
|
|
|||
|
// TIMER1 configuration
|
|||
|
timer_initpara.prescaler = 49;//<2F><>Ƶϵ<C6B5><CFB5><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>Ƶ<EFBFBD><C6B5>Ϊ1MHZ
|
|||
|
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD>
|
|||
|
timer_initpara.counterdirection = TIMER_COUNTER_UP;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
timer_initpara.period = 999;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><D7B0>ֵ<EFBFBD><D6B5>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><DEB8>Ըı<D4B8><C4B1><EFBFBD><EFBFBD>ڣ<EFBFBD>TIMER_CAR(timer_periph) = (uint32_t)initpara->period;
|
|||
|
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;//ʱ<>ӷ<EFBFBD>Ƶ
|
|||
|
timer_initpara.repetitioncounter = 0;//<2F><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>ֵ
|
|||
|
timer_init(TIMER2,&timer_initpara);
|
|||
|
timer_init(TIMER3,&timer_initpara);
|
|||
|
|
|||
|
// CH0 configuration in PWM mode 0
|
|||
|
timer_channel_output_struct_para_init(&timer_ocintpara);
|
|||
|
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
|
|||
|
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
|
|||
|
timer_ocintpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH;
|
|||
|
timer_ocintpara.outputnstate = TIMER_CCXN_DISABLE;
|
|||
|
timer_ocintpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
|
|||
|
timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
|
|||
|
|
|||
|
timer_channel_output_config(TIMER2,TIMER_CH_0,&timer_ocintpara);
|
|||
|
timer_channel_output_config(TIMER3,TIMER_CH_0,&timer_ocintpara);
|
|||
|
|
|||
|
// CH0 configuration in PWM mode 0,duty cycle
|
|||
|
timer_channel_output_pulse_value_config(TIMER2,TIMER_CH_0,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
|
|||
|
timer_channel_output_mode_config(TIMER2,TIMER_CH_0,TIMER_OC_MODE_PWM0);
|
|||
|
timer_channel_output_shadow_config(TIMER2,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
|
|||
|
// CH0 configuration in PWM mode 0,duty cycle
|
|||
|
timer_channel_output_pulse_value_config(TIMER3,TIMER_CH_0,0);
|
|||
|
timer_channel_output_mode_config(TIMER3,TIMER_CH_0,TIMER_OC_MODE_PWM0);
|
|||
|
timer_channel_output_shadow_config(TIMER3,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
|
|||
|
|
|||
|
// auto-reload preload enable
|
|||
|
timer_auto_reload_shadow_enable(TIMER2);
|
|||
|
timer_enable(TIMER2);
|
|||
|
timer_auto_reload_shadow_enable(TIMER3);
|
|||
|
timer_enable(TIMER3);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*!
|
|||
|
\brief none <EFBFBD><EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
\param[in] none
|
|||
|
\param[out] none
|
|||
|
\retval none
|
|||
|
\note LH @2022.07.11
|
|||
|
*/
|
|||
|
static void timer_gpio_init(void)
|
|||
|
{
|
|||
|
rcu_periph_clock_enable(RCU_GPIOC);
|
|||
|
rcu_periph_clock_enable(RCU_GPIOD);
|
|||
|
//H-STEP<45><50>timer3-ch0
|
|||
|
gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_12);
|
|||
|
gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_12);
|
|||
|
//V-STEP<45><50>timer2-ch0
|
|||
|
gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_6);
|
|||
|
gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_6);
|
|||
|
|
|||
|
//<2F><><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD>
|
|||
|
gpio_af_set(GPIOD, GPIO_AF_2, GPIO_PIN_12);
|
|||
|
gpio_af_set(GPIOC, GPIO_AF_2, GPIO_PIN_6);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
void step_time_init()
|
|||
|
{
|
|||
|
Step_timer_cfg();
|
|||
|
timer_gpio_init();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#endif
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#ifdef Full_bridge
|
|||
|
|
|||
|
void PWM_timer4_cfg();
|
|||
|
|
|||
|
/*!
|
|||
|
\brief none <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
\param[in] none
|
|||
|
\param[out] none
|
|||
|
\retval none
|
|||
|
\note LH @2022.07.20
|
|||
|
*/
|
|||
|
static void PWM_gpio_init(void)
|
|||
|
{
|
|||
|
rcu_periph_clock_enable(RCU_GPIOC);
|
|||
|
// rcu_periph_clock_enable(RCU_GPIOD);
|
|||
|
//ˮƽPC6-TIM2_CH0,ˮƽPC7-TIM2_CH1,ˮƽPC8-TIM2_CH2
|
|||
|
gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_6);
|
|||
|
gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_6);
|
|||
|
|
|||
|
gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_7);
|
|||
|
gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_7);
|
|||
|
|
|||
|
gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_8);
|
|||
|
gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_8);
|
|||
|
|
|||
|
//<2F><><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD>
|
|||
|
gpio_af_set(GPIOC, GPIO_AF_2, GPIO_PIN_6);
|
|||
|
gpio_af_set(GPIOC, GPIO_AF_2, GPIO_PIN_7);
|
|||
|
gpio_af_set(GPIOC, GPIO_AF_2, GPIO_PIN_8);
|
|||
|
|
|||
|
//<2F><>ֱPD12-TIM3_CH0,<2C><>ֱPD13-TIM3_CH1,<2C><>ֱPD14-TIM3_CH2
|
|||
|
gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_12);
|
|||
|
gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_12);
|
|||
|
|
|||
|
gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_13);
|
|||
|
gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_13);
|
|||
|
|
|||
|
gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_14);
|
|||
|
gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_14);
|
|||
|
|
|||
|
//<2F><><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD>
|
|||
|
gpio_af_set(GPIOD, GPIO_AF_2, GPIO_PIN_12);
|
|||
|
gpio_af_set(GPIOD, GPIO_AF_2, GPIO_PIN_13);
|
|||
|
gpio_af_set(GPIOD, GPIO_AF_2, GPIO_PIN_14);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*!
|
|||
|
\brief PWM<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
\param[in] none
|
|||
|
\param[out] none
|
|||
|
\retval none
|
|||
|
\note LH @2022.07.20
|
|||
|
*/
|
|||
|
static void PWM_timer_cfg(void)
|
|||
|
{//APB1<42><31><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ƶ<EFBFBD><C6B5>50MHz,APB2<42><32><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ƶ<EFBFBD><C6B5>100MHz----timer0,7
|
|||
|
timer_parameter_struct timer_initpara;
|
|||
|
timer_oc_parameter_struct timer_ocintpara;
|
|||
|
|
|||
|
rcu_periph_clock_enable(RCU_TIMER2);
|
|||
|
rcu_periph_clock_enable(RCU_TIMER3);
|
|||
|
// rcu_timer_clock_prescaler_config(RCU_TIMER_PSC_MUL4);
|
|||
|
timer_struct_para_init(&timer_initpara);
|
|||
|
timer_deinit(TIMER2);
|
|||
|
timer_deinit(TIMER3);
|
|||
|
|
|||
|
// TIMER1 configuration
|
|||
|
timer_initpara.prescaler = 2;//<2F><>Ƶϵ<C6B5><CFB5><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>Ƶ<EFBFBD><C6B5>Ϊ25MHZ
|
|||
|
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD>
|
|||
|
timer_initpara.counterdirection = TIMER_COUNTER_UP;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
timer_initpara.period = 1999;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><D7B0>ֵ<EFBFBD><D6B5>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><DEB8>Ըı<D4B8><C4B1><EFBFBD><EFBFBD>ڣ<EFBFBD>TIMER_CAR(timer_periph) = (uint32_t)initpara->period;
|
|||
|
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;//ʱ<>ӷ<EFBFBD>Ƶ
|
|||
|
timer_initpara.repetitioncounter = 0;//<2F><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>ֵ
|
|||
|
timer_init(TIMER2,&timer_initpara);
|
|||
|
timer_init(TIMER3,&timer_initpara);
|
|||
|
|
|||
|
// CH0 configuration in PWM mode 0
|
|||
|
timer_channel_output_struct_para_init(&timer_ocintpara);
|
|||
|
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
|
|||
|
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
|
|||
|
timer_ocintpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH;
|
|||
|
timer_ocintpara.outputnstate = TIMER_CCXN_DISABLE;
|
|||
|
timer_ocintpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
|
|||
|
timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
|
|||
|
|
|||
|
timer_channel_output_config(TIMER2,TIMER_CH_0,&timer_ocintpara);
|
|||
|
timer_channel_output_config(TIMER2,TIMER_CH_1,&timer_ocintpara);
|
|||
|
timer_channel_output_config(TIMER2,TIMER_CH_2,&timer_ocintpara);
|
|||
|
|
|||
|
timer_channel_output_config(TIMER3,TIMER_CH_0,&timer_ocintpara);
|
|||
|
timer_channel_output_config(TIMER3,TIMER_CH_1,&timer_ocintpara);
|
|||
|
timer_channel_output_config(TIMER3,TIMER_CH_2,&timer_ocintpara);
|
|||
|
|
|||
|
// CH0 configuration in PWM mode 0,duty cycle
|
|||
|
timer_channel_output_pulse_value_config(TIMER2,TIMER_CH_0,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
|
|||
|
timer_channel_output_mode_config(TIMER2,TIMER_CH_0,TIMER_OC_MODE_PWM0);
|
|||
|
timer_channel_output_shadow_config(TIMER2,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
|
|||
|
|
|||
|
// CH0 configuration in PWM mode 0,duty cycle
|
|||
|
timer_channel_output_pulse_value_config(TIMER2,TIMER_CH_1,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
|
|||
|
timer_channel_output_mode_config(TIMER2,TIMER_CH_1,TIMER_OC_MODE_PWM0);
|
|||
|
timer_channel_output_shadow_config(TIMER2,TIMER_CH_1,TIMER_OC_SHADOW_DISABLE);
|
|||
|
|
|||
|
// CH0 configuration in PWM mode 0,duty cycle
|
|||
|
timer_channel_output_pulse_value_config(TIMER2,TIMER_CH_2,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
|
|||
|
timer_channel_output_mode_config(TIMER2,TIMER_CH_2,TIMER_OC_MODE_PWM0);
|
|||
|
timer_channel_output_shadow_config(TIMER2,TIMER_CH_2,TIMER_OC_SHADOW_DISABLE);
|
|||
|
|
|||
|
// CH0 configuration in PWM mode 0,duty cycle
|
|||
|
timer_channel_output_pulse_value_config(TIMER3,TIMER_CH_0,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
|
|||
|
timer_channel_output_mode_config(TIMER3,TIMER_CH_0,TIMER_OC_MODE_PWM0);
|
|||
|
timer_channel_output_shadow_config(TIMER3,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
|
|||
|
|
|||
|
// CH0 configuration in PWM mode 0,duty cycle
|
|||
|
timer_channel_output_pulse_value_config(TIMER3,TIMER_CH_1,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
|
|||
|
timer_channel_output_mode_config(TIMER3,TIMER_CH_1,TIMER_OC_MODE_PWM0);
|
|||
|
timer_channel_output_shadow_config(TIMER3,TIMER_CH_1,TIMER_OC_SHADOW_DISABLE);
|
|||
|
|
|||
|
// CH0 configuration in PWM mode 0,duty cycle
|
|||
|
timer_channel_output_pulse_value_config(TIMER3,TIMER_CH_2,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
|
|||
|
timer_channel_output_mode_config(TIMER3,TIMER_CH_2,TIMER_OC_MODE_PWM0);
|
|||
|
timer_channel_output_shadow_config(TIMER3,TIMER_CH_2,TIMER_OC_SHADOW_DISABLE);
|
|||
|
|
|||
|
// auto-reload preload enable
|
|||
|
timer_auto_reload_shadow_enable(TIMER2);
|
|||
|
timer_enable(TIMER2);
|
|||
|
|
|||
|
timer_auto_reload_shadow_enable(TIMER3);
|
|||
|
timer_enable(TIMER3);
|
|||
|
|
|||
|
// timer_interrupt_enable(TIMER2,TIMER_INT_UP);//<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
// nvic_irq_enable(TIMER2_IRQn, 3U, 0U);
|
|||
|
|
|||
|
// timer_interrupt_enable(TIMER3,TIMER_INT_UP);//<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
// nvic_irq_enable(TIMER3_IRQn, 3U, 1U);
|
|||
|
}
|
|||
|
|
|||
|
/*!
|
|||
|
\brief <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>,,<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>ģ<EFBFBD><EFBFBD>
|
|||
|
\param[in] none
|
|||
|
\param[out] none
|
|||
|
\retval none
|
|||
|
\note LH @2022.07.20
|
|||
|
*/
|
|||
|
void bldc_pwm_init(void)
|
|||
|
{
|
|||
|
PWM_gpio_init();
|
|||
|
|
|||
|
PWM_timer_cfg();
|
|||
|
|
|||
|
OSTimeDlyHMSM(0u, 0u, 0u, 1u);
|
|||
|
|
|||
|
// //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȳ<EFBFBD>ʹ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>ֹCPU<50><55><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>
|
|||
|
// timer_disable(TIMER3);
|
|||
|
// timer_disable(TIMER2);
|
|||
|
// timer_interrupt_disable(TIMER3,TIMER_INT_UP);//<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
// timer_interrupt_disable(TIMER2,TIMER_INT_UP);//<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
PWM_timer4_cfg();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//<2F><><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|||
|
/*!
|
|||
|
\brief <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮƽ<EFBFBD>ʹ<EFBFBD>ֱ
|
|||
|
\param[in] none
|
|||
|
\param[out] none
|
|||
|
\retval none
|
|||
|
\note LH @2022.07.20
|
|||
|
*/
|
|||
|
void PWM_timer4_cfg()
|
|||
|
{//APB1<42><31><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ƶ<EFBFBD><C6B5>50MHz,APB2<42><32><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ƶ<EFBFBD><C6B5>100MHz----timer0,7
|
|||
|
timer_parameter_struct timer_initpara;
|
|||
|
// timer_oc_parameter_struct timer_ocintpara;
|
|||
|
|
|||
|
rcu_periph_clock_enable(RCU_TIMER4);
|
|||
|
timer_struct_para_init(&timer_initpara);
|
|||
|
timer_deinit(TIMER4);
|
|||
|
|
|||
|
// TIMER1 configuration
|
|||
|
timer_initpara.prescaler = 9;//<2F><>Ƶϵ<C6B5><CFB5><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>Ƶ<EFBFBD><C6B5>Ϊ25MHZ
|
|||
|
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD>
|
|||
|
timer_initpara.counterdirection = TIMER_COUNTER_UP;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
timer_initpara.period = 999;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><D7B0>ֵ<EFBFBD><D6B5>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><DEB8>Ըı<D4B8><C4B1><EFBFBD><EFBFBD>ڣ<EFBFBD>TIMER_CAR(timer_periph) = (uint32_t)initpara->period;
|
|||
|
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;//ʱ<>ӷ<EFBFBD>Ƶ
|
|||
|
timer_initpara.repetitioncounter = 0;//<2F><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>ֵ
|
|||
|
timer_init(TIMER4,&timer_initpara);
|
|||
|
|
|||
|
timer_auto_reload_shadow_enable(TIMER4);
|
|||
|
timer_enable(TIMER4);
|
|||
|
|
|||
|
|
|||
|
timer_interrupt_enable(TIMER4,TIMER_INT_UP);//<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
nvic_irq_enable(TIMER4_IRQn, 2U, 1U);
|
|||
|
// BSP_IntVectSet(66,TIMER4_IRQHandler);
|
|||
|
// BSP_IntEn(66);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//int hall_count,hall_count_last;//=0,counter_diff;
|
|||
|
//float motor_speed;//<2F><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
|
|||
|
//
|
|||
|
//void hall_irq_process()
|
|||
|
//{
|
|||
|
// if(abs(hall_count_last-g_ptz.vert_l6235d.l6235d_hall_h1_count) >= 1)
|
|||
|
// {
|
|||
|
// motor_speed = (144.0 / hall_count * 8000.0) / 6.0;//<2F><>λתÿ<D7AA><C3BF>
|
|||
|
//
|
|||
|
//// g_ptz.vert_motor_speed_hall_actual = motor_speed;
|
|||
|
// hall_count_last=g_ptz.vert_l6235d.l6235d_hall_h1_count;
|
|||
|
// hall_count=0;
|
|||
|
//}}
|
|||
|
|
|||
|
|
|||
|
#endif
|
|||
|
|