找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1030|回复: 0
打印 上一主题 下一主题
收起左侧

STM32 驱动ULN2003步进电机驱动板 + 5V步进电机

[复制链接]
跳转到指定楼层
楼主
STM32 驱动ULN2003步进电机驱动板 + 5V步进电机


step.h

#ifndef  __STEP_H__
#define __STEP_H__

#include "stm32f10x.h"

void Step_Motor_GPIO_Init(void);
/*
        功能:转1/64圈
        步距角5.625 360/5.625=64 减速比1/64
        故64*64个脉冲转一圈
        n 圈数
        direction 方向 1正转 非1反转
        delay delay时长 >= 2
*/
void motor_circle(int n, int direction, int delay);

#endif







step.C


#include "sys.h"
#include "delay.h"
#include "step.h"

//IN4: PF4  d
//IN3: PF3  c
//IN2: PF2  b
//IN1: PF1  a

u8 forward[4] = {0x03,0x06,0x0c,0x09}; // 正转
u8 reverse[4]= {0x03,0x09,0x0c,0x06}; // 反转

//引脚初始化
void Step_Motor_GPIO_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_3|GPIO_Pin_2|GPIO_Pin_1;
    GPIO_Init(GPIOF, &GPIO_InitStructure);
}

//引脚映射
void SetMotor(unsigned char InputData)
{
        if(InputData == 0x03)
        {
                GPIO_SetBits(GPIOF,GPIO_Pin_1);
                GPIO_SetBits(GPIOF,GPIO_Pin_2);
                GPIO_ResetBits(GPIOF,GPIO_Pin_3);
                GPIO_ResetBits(GPIOF,GPIO_Pin_4);
        }
        else if(InputData == 0x06)
        {
                GPIO_ResetBits(GPIOF,GPIO_Pin_1);
                GPIO_SetBits(GPIOF,GPIO_Pin_2);
                GPIO_SetBits(GPIOF,GPIO_Pin_3);
                GPIO_ResetBits(GPIOF,GPIO_Pin_4);
        }
        else if(InputData == 0x09)
        {
                GPIO_SetBits(GPIOF,GPIO_Pin_1);
                GPIO_ResetBits(GPIOF,GPIO_Pin_2);
                GPIO_ResetBits(GPIOF,GPIO_Pin_3);
                GPIO_SetBits(GPIOF,GPIO_Pin_4);
        }
        else if(InputData == 0x0c)
        {       
                GPIO_ResetBits(GPIOF,GPIO_Pin_1);
                GPIO_ResetBits(GPIOF,GPIO_Pin_2);
                GPIO_SetBits(GPIOF,GPIO_Pin_3);
                GPIO_SetBits(GPIOF,GPIO_Pin_4);
        }
        else if(InputData == 0x00)
        {
                GPIO_ResetBits(GPIOF,GPIO_Pin_1);
                GPIO_ResetBits(GPIOF,GPIO_Pin_2);
                GPIO_ResetBits(GPIOF,GPIO_Pin_3);
                GPIO_ResetBits(GPIOF,GPIO_Pin_4);
        }
}

/*
        功能:转1/64圈
        步距角5.625 360/5.625=64 减速比1/64
        故64*64个脉冲转一圈
        n 圈数
        direction 方向 1正转 非1反转
        delay delay时长ms >= 2
*/
void motor_circle(int n, int direction, int delay)
{
    int i, j;
    for(i = 0; i < n * 8; i++)
    {
                for(j = 0; j < 4; j++)
                {
                        if(1 == direction)
                        {
                                SetMotor(0x00);
                                SetMotor(forward[j]);
                        }
                        else
                        {
                                SetMotor(0x00);
                                SetMotor(reverse[j]);
                        }
                       
                        delay_ms(delay > 2 ? delay : 2);
                }
    }
}


51hei图片_20230628091311.jpg (261.03 KB, 下载次数: 35)

接线

接线

51hei图片_20230628091346.jpg (160.31 KB, 下载次数: 33)

51hei图片_20230628091346.jpg

51hei图片_20230628091353.jpg (487.63 KB, 下载次数: 29)

MAIN

MAIN

STM32_ULN2003步进电机驱动板 .zip

3.05 MB, 下载次数: 51, 下载积分: 黑币 -5

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表