This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于电机控制中GPIO口连续操作的问题



我在电机控制的程序中使能普通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;
 }

  • 你好,

    请问你用的是哪款芯片?

    有的芯片对IO口的操作有些需要注意的地方,例如对TMS320x2833x, 2823x的某一个GPIO进行置1清零操作,不建议直接对其DAT数据寄存器进行赋值,而是建议使用SET、CLEAR或TOGGLE来完成。

    这在其相关文档中有说明:

    When using the GPxDAT register to change the level of an output pin, you should be cautious not to
    accidentally change the level of another pin. For example, if you mean to change the output latch level
    of GPIOA0 by writing to the GPADAT register bit 0, using a read-modify-write instruction. The problem
    can occur if another I/O port A signal changes level between the read and the write stage of the
    instruction. You can also change the state of that output latch. You can avoid this scenario by using
    the GPxSET, GPxCLEAR, and GPxTOGGLE registers to load the output latch instead.