2019-08-03 17:12发布
zhangmangui 发表于 2014-2-26 09:53 步进电机的速度应该是好测的啊 也就是你多长时间送了一次脉冲 多少个脉冲转了一周 速度就出来了 ...
最多设置5个标签!
这个步进电机一个脉冲转动5.625度的
#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;
}
一周热门 更多>