我在电机控制的程序中使能普通I/O口,可是在置高置低的过程中,波形始终不对,不是正常的高低电平的方波信号,不知道为什么,下面是一段程序(六步换向程序)
// 0<=Angle<1/6 to voltage base vector 1 U_BASE_1
if ( (0 <= rg1.Out) && ( rg1.Out < _IQ(0.1666667) ) )
{Num = 1;
GpioDataRegs.GPADAT.bit.GPIO7 = 0; \
GpioDataRegs.GPADAT.bit.GPIO6 = 1; \
GpioDataRegs.GPADAT.bit.GPIO9 = 0; \
GpioDataRegs.GPADAT.bit.GPIO8 = 1; \
GpioDataRegs.GPADAT.bit.GPIO10 = 0; \
GpioDataRegs.GPADAT.bit.GPIO11 = 1;
}
// 1/6<=Angle<1/3 to voltage base vector 2 U_BASE_2
else if ( (_IQ(0.1666667) <= rg1.Out) && ( rg1.Out < _IQ(0.3333333) ) )
{Num = 2;
GpioDataRegs.GPADAT.bit.GPIO6 = 0; \
GpioDataRegs.GPADAT.bit.GPIO7= 1; \
GpioDataRegs.GPADAT.bit.GPIO9 = 0; \
GpioDataRegs.GPADAT.bit.GPIO8 = 1; \
GpioDataRegs.GPADAT.bit.GPIO10 = 0; \
GpioDataRegs.GPADAT.bit.GPIO11 = 1;
}
// 1/3<=Angle<1/2 to voltage base vector 3 U_BASE_3
else if ( (_IQ(0.3333333) <= rg1.Out) && ( rg1.Out < _IQ(0.5) ) )
{Num = 3;
GpioDataRegs.GPADAT.bit.GPIO6 = 0; \
GpioDataRegs.GPADAT.bit.GPIO7= 1; \
GpioDataRegs.GPADAT.bit.GPIO9 = 0; \
GpioDataRegs.GPADAT.bit.GPIO8 = 1; \
GpioDataRegs.GPADAT.bit.GPIO11 = 0; \
GpioDataRegs.GPADAT.bit.GPIO10 = 1;
}
// 0<=Angle<1/6 to voltage base vector 1 U_BASE_1
else if ( (_IQ(0.5) <= rg1.Out) && ( rg1.Out < _IQ(0.6666667) ) )
{Num = 4;
GpioDataRegs.GPADAT.bit.GPIO6 = 0; \
GpioDataRegs.GPADAT.bit.GPIO7= 1; \
GpioDataRegs.GPADAT.bit.GPIO8 = 0; \
GpioDataRegs.GPADAT.bit.GPIO9 = 1; \
GpioDataRegs.GPADAT.bit.GPIO11 = 0; \
GpioDataRegs.GPADAT.bit.GPIO10 = 1;
}
// 0<=Angle<1/6 to voltage base vector 1 U_BASE_1
else if ( (_IQ(0.6666667) <= rg1.Out) && ( rg1.Out < _IQ(0.8333333) ) )
{Num = 5;
GpioDataRegs.GPADAT.bit.GPIO7 = 0; \
GpioDataRegs.GPADAT.bit.GPIO6 = 1; \
GpioDataRegs.GPADAT.bit.GPIO8 = 0; \
GpioDataRegs.GPADAT.bit.GPIO9 = 1; \
GpioDataRegs.GPADAT.bit.GPIO11 = 0; \
GpioDataRegs.GPADAT.bit.GPIO10 = 1;
}
// 0<=Angle<1/6 to voltage base vector 1 U_BASE_1
else if ( (_IQ(0.8333333) <= rg1.Out) && ( rg1.Out < _IQ(1) ) )
{Num = 6;
GpioDataRegs.GPADAT.bit.GPIO7 = 0; \
GpioDataRegs.GPADAT.bit.GPIO6 = 1; \
GpioDataRegs.GPADAT.bit.GPIO8 = 0; \
GpioDataRegs.GPADAT.bit.GPIO9 = 1; \
GpioDataRegs.GPADAT.bit.GPIO10 = 0; \
GpioDataRegs.GPADAT.bit.GPIO11 = 1;
}
else
{Num = 0;
GpioDataRegs.GPADAT.bit.GPIO6 = 0; \
GpioDataRegs.GPADAT.bit.GPIO7= 1; \
GpioDataRegs.GPADAT.bit.GPIO8 = 0; \
GpioDataRegs.GPADAT.bit.GPIO9 = 1; \
GpioDataRegs.GPADAT.bit.GPIO10 = 0; \
GpioDataRegs.GPADAT.bit.GPIO11 = 1;
}
Jay:
你好,
建议你使用SET、CLEAR、TOGGLE寄存器来操作GPIO,不要使用DATA寄存器来赋值。