欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
自己用的步進(jìn)電機(jī)程序STM32 四相八拍 源程序
[打印本頁]
作者:
520899
時間:
2019-11-13 09:14
標(biāo)題:
自己用的步進(jìn)電機(jī)程序STM32 四相八拍 源程序
#include "sys.h"
#include "delay.h"
#include "diver.h"
#include "stdbool.h"
//IN4: PB8 d
//IN3: PB7 c
//IN2: PB6 b
//IN1: PB5 a
//四相八拍
u8 phasecw[8] ={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};// 逆時針
u8 phaseccw[8]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};// 順時針
//引腳初始化
void Step_Motor_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
//引腳映射
void SetMotor(unsigned char InputData)
{
if(InputData&0x01)
{
GPIO_SetBits(GPIOB,GPIO_Pin_5);
}
else
{
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
}
if(InputData&0x02)
{
GPIO_SetBits(GPIOB,GPIO_Pin_6);
}
else
{
GPIO_ResetBits(GPIOB,GPIO_Pin_6);
}
if(InputData&0x04)
{
GPIO_SetBits(GPIOB,GPIO_Pin_7);
}
else
{
GPIO_ResetBits(GPIOB,GPIO_Pin_7);
}
if(InputData&0x08)
{
GPIO_SetBits(GPIOB,GPIO_Pin_8);
}
else
{
GPIO_ResetBits(GPIOB,GPIO_Pin_8);
}
}
//步距角5.625 360/5.625=64 減速比1/64
//故64*64個脈沖轉(zhuǎn)一圈
//n圈數(shù)
//direction 方向
void motorNcircle(int n,bool direction)
{
int i,j,k=0;
for(j=0;j<n;j++)
{
for(i=0;i<64*8;i++)
//for(i=0;i<8;i++)
{
for(k=0;k<8;k++)
{
if(1 == direction)
{
SetMotor(phasecw[k]);
}
else
{
SetMotor(phaseccw[k]);
}
delay_ms(2);
}
}
}
}
//speed 速度
//direction 方向
void motorNspeed(int speed,bool direction)
{
unsigned char k=0;
for(k=0;k<8;k++)
{
if(direction==1)
SetMotor(phasecw[k]); //取數(shù)據(jù)
else
SetMotor(phaseccw[k]);
delay_ms(speed); //調(diào)節(jié)轉(zhuǎn)速
}
}
復(fù)制代碼
全部資料51hei下載地址:
步進(jìn)電機(jī).7z
(179.69 KB, 下載次數(shù): 29)
2019-11-13 14:55 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
電子科123
時間:
2019-12-10 16:05
能測電機(jī)的速度么?
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1