h_12345 发表于 2012-11-13 09:30:15

关于(PIC)AN1017关于电机正弦控制的问题

// These Phase values represent the base Phase value of the sinewave for each
// one of the sectors (each sector is a translation of the hall effect sensors
// reading
#define PHASE_ZERO         57344
#define PHASE_ONE        ((PHASE_ZERO + 65536/6) % 65536)
#define PHASE_TWO        ((PHASE_ONE + 65536/6) % 65536)
#define PHASE_THREE        ((PHASE_TWO + 65536/6) % 65536)
#define PHASE_FOUR        ((PHASE_THREE + 65536/6) % 65536)
#define PHASE_FIVE        ((PHASE_FOUR + 65536/6) % 65536)

// Constants used for properly energizing the motor depending on the
// rotor's position
int PhaseValues __attribute__((far,section(".const,r")))=
{PHASE_ZERO, PHASE_ONE, PHASE_TWO, PHASE_THREE, PHASE_FOUR, PHASE_FIVE};

char SectorTable[] = {-1,4,2,3,0,5,1,-1};
void __attribute__((__interrupt__)) _CNInterrupt (void)
{
        IFS0bits.CNIF = 0;        // Clear interrupt flag
        HallValue = (unsigned int)((PORTB >> 3) & 0x0007);        // Read halls
        Sector = SectorTable;        // Get Sector from table

    // This MUST be done for getting around the HW slow rate
        if (Sector != LastSector)       
        {
                // Since a new sector is detected, clear variable that would stop
      // the motor if stalled.
                MotorStalledCounter = 0;

                // Motor current direction is computed based on Sector
                if ((Sector == 5) || (Sector == 2))       
                        Current_Direction = CCW;
                else
                        Current_Direction = CW;

      // Motor commutation is actually based on the required direction, not
      // the current dir. This allows driving the motor in four quadrants
                if (Required_Direction == CW)       
                {
                        Phase = PhaseValues;
                }
                else
                {
                        // For CCW an offset must be added to compensate difference in
            // symmetry of the sine table used for CW and CCW
                        Phase = PhaseValues[(Sector + 3) % 6] + PhaseOffset;
                }
                LastSector = Sector; // Update last sector
        }

        return;
}
按照电机的转动方向,如果是正转,霍尔发生的顺序1,3,2,6,4,5,反转顺序是1,5,4,6,2,3,
char SectorTable[] = {-1,4,2,3,0,5,1,-1};这个是顺序是如何得出来的?
页: [1]
查看完整版本: 关于(PIC)AN1017关于电机正弦控制的问题