专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
TI
28335控制28BYJ48步进电机转速的c语言程序
2019-08-03 17:12
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
TI MCU
5260
10
1069
跪求一个用cpu_timer控制步进电机转速的程序,看各种资料还是无法编译成功,谢谢了!
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
10条回答
你一笑,粉直掉
2019-08-04 20:39
我又对这个程序作了修改,但是步进电机不会转动,原因是我没有把步进电机的操作部分写进定时器中断里面,但我又想不出来,求版主指点@zhangmangui
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#define PHA_ON GpioDataRegs.GPASET.bit.GPIO8 = 1 //A相输出高电平
#define PHA_OFF GpioDataRegs.GPACLEAR.bit.GPIO8 = 1 //A相输出低电平
#define PHB_ON GpioDataRegs.GPASET.bit.GPIO9 = 1 //B相输出高电平
#define PHB_OFF GpioDataRegs.GPACLEAR.bit.GPIO9 = 1 //B相输出低电平
#define PHC_ON GpioDataRegs.GPASET.bit.GPIO10 = 1 //C相输出高电平
#define PHC_OFF GpioDataRegs.GPACLEAR.bit.GPIO10 = 1 //C相输出低电平
#define PHD_ON GpioDataRegs.GPASET.bit.GPIO11 = 1 //D相输出高电平
#define PHD_OFF GpioDataRegs.GPACLEAR.bit.GPIO11 = 1 //D相输出低电平
const Uint16 StepMode1[8] = {0x0D0A,0x0D0A,0x0A0B,0x0A0B,0x0B0C,0x0B0C,0x0C0D,0x0C0D}; //单四拍时序A-B-C-D-A
void MotionControl1(void);
void delay(Uint32 t);
void PhaseOff(Uint16 i);
void PhaseOn(Uint16 i);
interrupt void cpu_timer0_isr(void);
void Init_StepMotorGpio(void)
{
EALLOW;
//Phase A
GpioCtrlRegs.GPAPUD.bit.GPIO8 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO8 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO8 = 1; // GPIO11 = output
//Phase B
GpioCtrlRegs.GPAPUD.bit.GPIO9 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO9 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // GPIO11 = output
//Phase C
GpioCtrlRegs.GPAPUD.bit.GPIO10 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO10 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO10 = 1; // GPIO11 = output
//Phase D
GpioCtrlRegs.GPAPUD.bit.GPIO11= 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO11 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO11= 1; // GPIO11 = output
EDIS;
PHA_OFF;
PHB_OFF;
PHC_OFF;
PHD_OFF;
}
void delay(Uint32 t)
{
Uint32 i = 0;
for (i = 0; i < t; i++);
}
void PhaseOn(Uint16 i)
{
switch(i)
{
case 0xA:
PHA_ON;
break;
case 0xB:
PHB_ON;
break;
case 0xC:
PHC_ON;
break;
case 0xD:
PHD_ON;
break;
case 0x0:
break;
default:
break;
}
}
void PhaseOff(Uint16 i)
{
switch(i)
{
case 0xA:
PHA_OFF;
break;
case 0xB:
PHB_OFF;
break;
case 0xC:
PHC_OFF;
break;
case 0xD:
PHD_OFF;
break;
case 0x0:
break;
default:
break;
}
}
void MotionControl1(void)
{Uint16 loop = 0;
while(1)
{
if(loop==8)
{
loop=0;
}
else
{
PhaseOn (StepMode1[loop] & 0x000F); //第一位:控制信号高电平判断
PhaseOn ((StepMode1[loop] & 0x00F0)>>4); //第二位:控制信号高电平判断
PhaseOff((StepMode1[loop] & 0x0F00)>>8); //第三位:控制信号低电平判断
PhaseOff((StepMode1[loop] & 0xF000)>>12); //第四位:控制信号低电平判断
loop++;
}
}
}
void main(void)
{
InitSysCtrl();
Init_StepMotorGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0,0,0);
IER |= M_INT1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
EINT;
ERTM;
StartCpuTimer0();
while(1)
{
MotionControl1();
}
}
interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
加载中...
查看其它10个回答
一周热门
更多
>
相关问题
CPLD的方波输出
4 个回答
11个版本Quartus II 软件下载,安装包网盘合集,附教程,47G!
20 个回答
请大家帮忙到21IC发展大家谈支持我申请新版面
20 个回答
【通知】21ic中国电子网服务条款 (所有人员必读)
1 个回答
满载而归乙亥年,大展鸿途庚子年---集签赢好礼
20 个回答
相关文章
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
TI
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#define PHA_ON GpioDataRegs.GPASET.bit.GPIO8 = 1 //A相输出高电平
#define PHA_OFF GpioDataRegs.GPACLEAR.bit.GPIO8 = 1 //A相输出低电平
#define PHB_ON GpioDataRegs.GPASET.bit.GPIO9 = 1 //B相输出高电平
#define PHB_OFF GpioDataRegs.GPACLEAR.bit.GPIO9 = 1 //B相输出低电平
#define PHC_ON GpioDataRegs.GPASET.bit.GPIO10 = 1 //C相输出高电平
#define PHC_OFF GpioDataRegs.GPACLEAR.bit.GPIO10 = 1 //C相输出低电平
#define PHD_ON GpioDataRegs.GPASET.bit.GPIO11 = 1 //D相输出高电平
#define PHD_OFF GpioDataRegs.GPACLEAR.bit.GPIO11 = 1 //D相输出低电平
const Uint16 StepMode1[8] = {0x0D0A,0x0D0A,0x0A0B,0x0A0B,0x0B0C,0x0B0C,0x0C0D,0x0C0D}; //单四拍时序A-B-C-D-A
void MotionControl1(void);
void delay(Uint32 t);
void PhaseOff(Uint16 i);
void PhaseOn(Uint16 i);
interrupt void cpu_timer0_isr(void);
void Init_StepMotorGpio(void)
{
EALLOW;
//Phase A
GpioCtrlRegs.GPAPUD.bit.GPIO8 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO8 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO8 = 1; // GPIO11 = output
//Phase B
GpioCtrlRegs.GPAPUD.bit.GPIO9 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO9 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // GPIO11 = output
//Phase C
GpioCtrlRegs.GPAPUD.bit.GPIO10 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO10 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO10 = 1; // GPIO11 = output
//Phase D
GpioCtrlRegs.GPAPUD.bit.GPIO11= 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO11 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO11= 1; // GPIO11 = output
EDIS;
PHA_OFF;
PHB_OFF;
PHC_OFF;
PHD_OFF;
}
void delay(Uint32 t)
{
Uint32 i = 0;
for (i = 0; i < t; i++);
}
void PhaseOn(Uint16 i)
{
switch(i)
{
case 0xA:
PHA_ON;
break;
case 0xB:
PHB_ON;
break;
case 0xC:
PHC_ON;
break;
case 0xD:
PHD_ON;
break;
case 0x0:
break;
default:
break;
}
}
void PhaseOff(Uint16 i)
{
switch(i)
{
case 0xA:
PHA_OFF;
break;
case 0xB:
PHB_OFF;
break;
case 0xC:
PHC_OFF;
break;
case 0xD:
PHD_OFF;
break;
case 0x0:
break;
default:
break;
}
}
void MotionControl1(void)
{Uint16 loop = 0;
while(1)
{
if(loop==8)
{
loop=0;
}
else
{
PhaseOn (StepMode1[loop] & 0x000F); //第一位:控制信号高电平判断
PhaseOn ((StepMode1[loop] & 0x00F0)>>4); //第二位:控制信号高电平判断
PhaseOff((StepMode1[loop] & 0x0F00)>>8); //第三位:控制信号低电平判断
PhaseOff((StepMode1[loop] & 0xF000)>>12); //第四位:控制信号低电平判断
loop++;
}
}
}
void main(void)
{
InitSysCtrl();
Init_StepMotorGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0,0,0);
IER |= M_INT1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
EINT;
ERTM;
StartCpuTimer0();
while(1)
{
MotionControl1();
}
}
interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
一周热门 更多>