轻型步进,DcStep,水平垂直,初测版本
This commit is contained in:
parent
f38c744f13
commit
a345b34dd0
|
@ -8,8 +8,8 @@
|
|||
#ifdef PTZ_STEP_MOTOR
|
||||
#define DCSTEP_SPEED_LIMIT_HORI 3.3//19.8°以下不使用DCSTEP
|
||||
#define DCSTEP_SPEED_LIMIT_VERT 3.3//俯仰
|
||||
#define DCSTEP_HORI_EN 0
|
||||
#define DCSTEP_VERT_EN 0
|
||||
#define DCSTEP_HORI_EN 1
|
||||
#define DCSTEP_VERT_EN 1
|
||||
|
||||
static BSP_OS_SEM ptz_ftm_mutex;//共享资源锁
|
||||
|
||||
|
@ -81,8 +81,8 @@ static void ptz_hori_step_speed_task()
|
|||
|
||||
while(1)
|
||||
{
|
||||
// if ( GetHoriDcoStatus() )//DC0输出高电平
|
||||
// {
|
||||
if ( GetHoriDcoStatus() )//DC0输出高电平
|
||||
{
|
||||
if(g_ptz.hori_start_stop_set == PTZ_HORI_START)
|
||||
{
|
||||
g_ptz.hori_tmc2160.set_f = ptz_hori_step_v_to_f((g_ptz.hori_speed_set * PTZ_HORI_RATIO), g_ptz.hori_tmc2160.microstep_vlue);//g_ptz.hori_speed_set
|
||||
|
@ -152,7 +152,7 @@ static void ptz_hori_step_speed_task()
|
|||
g_ptz.hori_speed_actual = 0;
|
||||
g_ptz.hori_tmc2160.f = 0;
|
||||
}
|
||||
// }
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// if(GetDcstepPulseFlag())
|
||||
|
|
|
@ -11,12 +11,16 @@
|
|||
|
||||
#if DCSTEP_FUN_EN
|
||||
uint8_t g_dcStepVert = 1;
|
||||
|
||||
uint8_t g_dcStepHori = 1;
|
||||
uint8_t GetVertDcoStatus(void)
|
||||
{
|
||||
return g_dcStepVert;
|
||||
}
|
||||
|
||||
uint8_t GetHoriDcoStatus(void)
|
||||
{
|
||||
return g_dcStepVert;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// @brief 外部中断初始化
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#if DCSTEP_FUN_EN
|
||||
uint8_t GetVertDcoStatus(void);
|
||||
uint8_t GetHoriDcoStatus(void);
|
||||
#endif
|
||||
|
||||
#ifdef PTZ_LIGHT_GEAR_L6235D_AS5047D
|
||||
|
|
|
@ -206,6 +206,34 @@ void tmc2160_init()
|
|||
|
||||
/* TIMER7 enable */
|
||||
// timer_enable(TIMER7);//使能定时器
|
||||
|
||||
/*水平DCO触发外部中断*/
|
||||
nvic_irq_enable(EXTI5_9_IRQn, 2U, 3U);
|
||||
syscfg_exti_line_config(EXTI_SOURCE_GPIOE, EXTI_SOURCE_PIN9);
|
||||
exti_init(EXTI_9, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
|
||||
exti_interrupt_flag_clear(EXTI_9);
|
||||
/*水平DCO定时器更新中断配置*/
|
||||
rcu_periph_clock_enable(RCU_TIMER4);//开启定时器时钟
|
||||
|
||||
timer_struct_para_init(&timer_initpara);//将定时器结构体内参数配置成默认参数
|
||||
timer_deinit(TIMER4); //复位定时器
|
||||
|
||||
/* TIMER1 configuration */
|
||||
//200M/20/1000 = 10K
|
||||
timer_initpara.prescaler = 20-1;//预分频
|
||||
timer_initpara.alignedmode = TIMER_COUNTER_EDGE; //边缘对齐
|
||||
timer_initpara.counterdirection = TIMER_COUNTER_UP; //向上计数方式
|
||||
timer_initpara.period = 1000-1; //计数值
|
||||
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
|
||||
timer_initpara.repetitioncounter = 0; //每次溢出都产生更新是件
|
||||
timer_init(TIMER4,&timer_initpara);
|
||||
|
||||
timer_interrupt_enable(TIMER4,TIMER_INT_UP);//使能溢出中断
|
||||
|
||||
nvic_irq_enable(TIMER4_IRQn, 2u, 3u);//配置中断优先级
|
||||
|
||||
/* TIMER7 enable */
|
||||
// timer_enable(TIMER4);//使能定时器
|
||||
#endif
|
||||
|
||||
/* //为了不让驱动器的两个电容同时上电,驱动器初始化分别进行
|
||||
|
@ -575,7 +603,7 @@ char tmc2160_write_register(char choice, unsigned char mode, unsigned char data)
|
|||
buff[0] = TMC2160_CHOPCONF +0x80;
|
||||
buff[1] = tmc2160_chopconf_data(data);
|
||||
#ifdef PTZ_SUPER_LIGHT_WORM_STEP_TMC2160_AS5047D_24V
|
||||
buff[2] = 0xec;//ed,,高4为被动快速衰减时间,可降低中程共振
|
||||
buff[2] = 0xed;//ed,,高4为被动快速衰减时间,可降低中程共振
|
||||
buff[3] = 0x43;//03
|
||||
buff[4] = 0x38;//C3
|
||||
#endif
|
||||
|
@ -612,7 +640,7 @@ char tmc2160_write_register(char choice, unsigned char mode, unsigned char data)
|
|||
buff[1] = 0x00;
|
||||
buff[2] = 0x00;
|
||||
buff[3] = 0x00;
|
||||
buff[4] = 0x11;
|
||||
buff[4] = 0x25;
|
||||
if(choice == TMC2160_HORI)
|
||||
{
|
||||
hori_regis.chop_conf = tmc2160_write_hori_data(choice, buff[0],buff[1],buff[2],buff[3],buff[4]);
|
||||
|
|
|
@ -37,10 +37,13 @@ OF SUCH DAMAGE.
|
|||
#include "bsp_os.h"
|
||||
#include "Usart.h"
|
||||
#include "device_interrupt.h"
|
||||
#include "Timer.h"
|
||||
//#include "Timer.h"
|
||||
//#include "speed_to_step.h"
|
||||
//#include "ptz_struct.h"
|
||||
|
||||
#if DCSTEP_FUN_EN
|
||||
extern uint8_t g_dcStepVert;
|
||||
extern uint8_t g_dcStepHori;
|
||||
#endif
|
||||
|
||||
extern BSP_OS_SEM sem_enet_isr_recv;
|
||||
|
@ -239,22 +242,23 @@ void EXTI5_9_IRQHandler(void)
|
|||
}
|
||||
if(RESET != exti_interrupt_flag_get(EXTI_9))
|
||||
{
|
||||
// /*function start*/
|
||||
// if (g_dcStepHori)
|
||||
// {
|
||||
// exti_init(EXTI_9, EXTI_INTERRUPT, EXTI_TRIG_RISING);//上升沿中断
|
||||
// timer_enable(TIMER7);//使能定时器
|
||||
// timer_counter_value_config(TIMER7, 0u);
|
||||
// g_dcStepHori = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// exti_init(EXTI_9, EXTI_INTERRUPT, EXTI_TRIG_FALLING);//下降沿中断
|
||||
// timer_disable(TIMER7);//失能定时器
|
||||
// timer_counter_value_config(TIMER7, 0u);
|
||||
// g_dcStepHori = 1;
|
||||
// }
|
||||
// /*function end*/
|
||||
/*function start*/
|
||||
if ( !gpio_input_bit_get(GPIOE, GPIO_PIN_9) )
|
||||
{
|
||||
exti_init(EXTI_9, EXTI_INTERRUPT, EXTI_TRIG_RISING);//上升沿中断
|
||||
timer_enable(TIMER12);//使能定时器
|
||||
timer_counter_value_config(TIMER12, 0u);
|
||||
// ptz_hori_timer_stop();
|
||||
g_dcStepHori = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
exti_init(EXTI_9, EXTI_INTERRUPT, EXTI_TRIG_FALLING);//下降沿中断
|
||||
timer_disable(TIMER12);//失能定时器
|
||||
timer_counter_value_config(TIMER12, 0u);
|
||||
g_dcStepHori = 1;
|
||||
}
|
||||
/*function end*/
|
||||
exti_interrupt_flag_clear(EXTI_9);
|
||||
}
|
||||
}
|
||||
|
@ -286,12 +290,12 @@ void EXTI10_15_IRQHandler(void)
|
|||
if(RESET != exti_interrupt_flag_get(EXTI_12))
|
||||
{
|
||||
/*function start*/
|
||||
if (g_dcStepVert)
|
||||
if ( !gpio_input_bit_get(GPIOE, GPIO_PIN_12) )
|
||||
{
|
||||
exti_init(EXTI_12, EXTI_INTERRUPT, EXTI_TRIG_RISING);//上升沿中断
|
||||
timer_enable(TIMER7);//使能定时器
|
||||
timer_counter_value_config(TIMER7, 0u);
|
||||
ptz_vert_timer_stop();
|
||||
// ptz_vert_timer_stop();
|
||||
g_dcStepVert = 0;
|
||||
}
|
||||
else
|
||||
|
@ -299,7 +303,6 @@ void EXTI10_15_IRQHandler(void)
|
|||
exti_init(EXTI_12, EXTI_INTERRUPT, EXTI_TRIG_FALLING);//下降沿中断
|
||||
timer_disable(TIMER7);//失能定时器
|
||||
timer_counter_value_config(TIMER7, 0u);
|
||||
ptz_vert_timer_start(4000);
|
||||
g_dcStepVert = 1;
|
||||
}
|
||||
/*function end*/
|
||||
|
@ -366,7 +369,7 @@ void EXTI2_IRQHandler(void)
|
|||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
\note LH @2025.08.12
|
||||
\note LH @2025.08.12!
|
||||
*/
|
||||
void TIMER7_UP_TIMER12_IRQHandler(void)
|
||||
{
|
||||
|
@ -389,3 +392,32 @@ void TIMER7_UP_TIMER12_IRQHandler(void)
|
|||
/* clear TIMER interrupt flag */
|
||||
timer_interrupt_flag_clear(TIMER7,TIMER_INT_UP);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief TIM4 中断处理函数
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
\note LH @2025.08.20!
|
||||
*/
|
||||
void TIMER4_IRQHandler(void)
|
||||
{
|
||||
static uint16_t count2 = 0;
|
||||
if(SET == timer_interrupt_flag_get(TIMER4,TIMER_INT_UP))
|
||||
{
|
||||
count2 ++;
|
||||
if ( count2 >= 10 )
|
||||
{
|
||||
gpio_bit_set(GPIOC, GPIO_PIN_6);
|
||||
}
|
||||
else if( count2 >= 12 )
|
||||
{
|
||||
count2 = 0;
|
||||
timer_disable(TIMER4);//失能定时器
|
||||
timer_counter_value_config(TIMER4, 0u);
|
||||
gpio_bit_reset(GPIOC, GPIO_PIN_6);
|
||||
}
|
||||
}
|
||||
/* clear TIMER interrupt flag */
|
||||
timer_interrupt_flag_clear(TIMER4,TIMER_INT_UP);
|
||||
}
|
Loading…
Reference in New Issue