Skip to content

darwinstudio/MultiStepperMotor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MultiStepperMotor

简介

MultiStepperMotor是一个步进电机驱动模块,可无限量拓展电机。

使用方法

1.先申请一个步进电机结构体

STEPPER_MOTOR stepper_motor;

2.完成CLK引脚翻转接口函数

//e.g. stm32

static void gpio_clk_toggle(void)
{
    HAL_GPIO_TogglePin(CLK_SM1_GPIO_Port, CLK_SM1_Pin);
}

3.完成DIR引脚控制接口函数

static void gpio_dir_control(uint8_t level)
{
    if (level)
    {
        HAL_GPIO_WritePin(DIR_SM1_GPIO_Port, DIR_SM1_Pin, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(DIR_SM1_GPIO_Port, DIR_SM1_Pin, GPIO_PIN_RESET);
    }
}

4.完成电机停止回调函数(可选)

static void stepper_motor_stop_callback(void)
{
    // do something
    //e.g. usart send message to computer
}

5.调用电机初始化函数

stepper_motor_init(&stepper_motor,gpio_clk_toggle,gpio_dir_control,(uint8_t)GPIO_PIN_SET,stepper_motor_stop_callback);

6.调用电机注册函数

stepper_motor_register(&stepper_motor,0);

7.定时器中断调用处理函数

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
    if(htim->Instance == TIM3)
    {
        stepper_motor_group_it_ticks(0);
    }
}

8.线程中调用电机回调处理函数

static void step_motor_entry(void *argument)
{
    while (1)
    {
        stepper_motor_callback_ticks(0);
        osDelay(100);
    }
}

About

Stepper motor driver for embedded system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages