轻型步进电机使用DcStep,DCO,DCEN,DCIN三个引脚均用上

备注:作为一个基础修改版,非可用版
This commit is contained in:
REASEARCHER\18383 2025-08-20 10:38:41 +08:00
parent 93071dc6b4
commit 1430888d67
7 changed files with 51 additions and 70 deletions

View File

@ -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 1
#define DCSTEP_VERT_EN 1
#define DCSTEP_HORI_EN 0
#define DCSTEP_VERT_EN 0
static BSP_OS_SEM ptz_ftm_mutex;//共享资源锁
@ -177,8 +177,8 @@ static void ptz_vert_step_speed_task()
while(1)
{
// if ( GetVertDcoStatus() )
// {
if ( GetVertDcoStatus() )
{
if(g_ptz.vert_start_stop_set == PTZ_VERT_START)
{
g_ptz.vert_tmc2160.set_f = ptz_vert_step_v_to_f((g_ptz.vert_speed_set * PTZ_VERT_RATIO), g_ptz.vert_tmc2160.microstep_vlue);
@ -250,23 +250,7 @@ static void ptz_vert_step_speed_task()
g_ptz.vert_speed_actual = 0;
g_ptz.vert_tmc2160.f = 0;
}
// }
// else
// {
// if ( GetDcstepPulseFlag() )
// {
//// gpio_bit_set(GPIOD, GPIO_PIN_12);
//// OSTimeDlyHMSM(0u, 0u, 0u, 1u);
//// gpio_bit_reset(GPIOD, GPIO_PIN_12);
//// ptz_vert_timer_start((unsigned int)(g_ptz.vert_tmc2160.f + 0.5));
//// OSTimeDlyHMSM(0u, 0u, 0u, 1u);
// ResetDcstepPulseFlag();
// }
// else
// {
//// ptz_vert_timer_stop();
// }
// }
}
OSTimeDlyHMSM(0u, 0u, 0u, PTZ_VERT_ACC_DEC_INC_T);
}

View File

@ -11,22 +11,12 @@
#if DCSTEP_FUN_EN
uint8_t g_dcStepVert = 1;
uint8_t g_dcStepVertPulseFlag = 0;
uint8_t GetVertDcoStatus(void)
{
return g_dcStepVert;
}
uint8_t GetDcstepPulseFlag(void)
{
return g_dcStepVertPulseFlag;
}
void ResetDcstepPulseFlag(void)
{
g_dcStepVertPulseFlag = 0;
}
#endif
/// @brief 外部中断初始化

View File

@ -3,13 +3,11 @@
#include "ptz_type_select.h"
#include "gd32f4xx.h"
#define DCSTEP_FUN_EN 0
#define DCSTEP_FUN_EN 1
//#if DCSTEP_FUN_EN
//uint8_t GetVertDcoStatus(void);
//uint8_t GetDcstepPulseFlag(void);
//void ResetDcstepPulseFlag(void);
//#endif
#if DCSTEP_FUN_EN
uint8_t GetVertDcoStatus(void);
#endif
#ifdef PTZ_LIGHT_GEAR_L6235D_AS5047D
//使用L6235D驱动电机并打开霍尔反馈

View File

@ -180,7 +180,7 @@ void tmc2160_init()
/*垂直DCO触发外部中断*/
nvic_irq_enable(EXTI10_15_IRQn, 2U, 2U);
syscfg_exti_line_config(EXTI_SOURCE_GPIOE, EXTI_SOURCE_PIN12);
exti_init(EXTI_12, EXTI_INTERRUPT, EXTI_TRIG_BOTH);
exti_init(EXTI_12, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
exti_interrupt_flag_clear(EXTI_12);
/*垂直DCO定时器更新中断配置*/
timer_parameter_struct timer_initpara;//定时器结构体
@ -191,8 +191,8 @@ void tmc2160_init()
timer_deinit(TIMER7); //复位定时器
/* TIMER1 configuration */
//200M/200/1000 = 1k
timer_initpara.prescaler = 200-1;//预分频
//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; //计数值

View File

@ -37,10 +37,10 @@ OF SUCH DAMAGE.
#include "bsp_os.h"
#include "Usart.h"
#include "device_interrupt.h"
#include "Timer.h"
#if DCSTEP_FUN_EN
extern uint8_t g_dcStepVert;
extern uint8_t g_dcStepVertPulseFlag;
#endif
extern BSP_OS_SEM sem_enet_isr_recv;
@ -286,20 +286,22 @@ void EXTI10_15_IRQHandler(void)
if(RESET != exti_interrupt_flag_get(EXTI_12))
{
/*function start*/
// if (g_dcStepVert)
// {
//// exti_init(EXTI_12, EXTI_INTERRUPT, EXTI_TRIG_RISING);//上升沿中断
// timer_enable(TIMER7);//使能定时器
// timer_counter_value_config(TIMER7, 0u);
// g_dcStepVert = 0;
// }
// else
// {
//// exti_init(EXTI_12, EXTI_INTERRUPT, EXTI_TRIG_FALLING);//下降沿中断
// timer_disable(TIMER7);//失能定时器
// timer_counter_value_config(TIMER7, 0u);
// g_dcStepVert = 1;
// }
if (g_dcStepVert)
{
exti_init(EXTI_12, EXTI_INTERRUPT, EXTI_TRIG_RISING);//上升沿中断
timer_enable(TIMER7);//使能定时器
timer_counter_value_config(TIMER7, 0u);
ptz_vert_timer_stop();
g_dcStepVert = 0;
}
else
{
exti_init(EXTI_12, EXTI_INTERRUPT, EXTI_TRIG_FALLING);//下降沿中断
timer_disable(TIMER7);//失能定时器
timer_counter_value_config(TIMER7, 0u);
ptz_vert_timer_start(20000);
g_dcStepVert = 1;
}
/*function end*/
exti_interrupt_flag_clear(EXTI_12);
}
@ -368,20 +370,22 @@ void EXTI2_IRQHandler(void)
*/
void TIMER7_UP_TIMER12_IRQHandler(void)
{
// static uint32_t count = 0;
// if(SET == timer_interrupt_flag_get(TIMER7,TIMER_INT_UP))
// {
// count++;
// if ( count >= 2 )
// {
// count = 0;
// g_dcStepVertPulseFlag = 1;
// timer_disable(TIMER7);//失能定时器
// timer_counter_value_config(TIMER7, 0u);
//// g_dcStepVert = 1;
// }
//
// }
static uint16_t count = 0;
if(SET == timer_interrupt_flag_get(TIMER7,TIMER_INT_UP))
{
count ++;
if ( count >= 10 )
{
gpio_bit_set(GPIOD, GPIO_PIN_12);
}
else if( count >= 12 )
{
count = 0;
timer_disable(TIMER7);//失能定时器
timer_counter_value_config(TIMER7, 0u);
gpio_bit_reset(GPIOD, GPIO_PIN_12);
}
}
/* clear TIMER interrupt flag */
timer_interrupt_flag_clear(TIMER7,TIMER_INT_UP);
}

View File

@ -738,7 +738,7 @@
<data>
<extensions></extensions>
<cmdline></cmdline>
<hasPrio>184</hasPrio>
<hasPrio>1</hasPrio>
<buildSequence>inputOutputBased</buildSequence>
</data>
</settings>

5
ReadMe.txt Normal file
View File

@ -0,0 +1,5 @@
V1.0(sourcetree内相较前一版本优化一些参数)
1水平和垂直在25°/S噪声明显
2水平和垂直在40°/S效果较好
3水平和垂直在高转速下水平60以上垂直60接近目标位置5°内会自动将速度降到1.8°/S
4俯仰转动在低转速下-45°位置会有轻微异响