During motor/sensor setup, the controller rotates the motor and finds the angles that the hall sensors are located in the electrical cycle. This angle table is useful for the sinusoidal commutation of the motor. Ideally, Hall sensors placed with 120 degrees difference should be identified every 60 degrees. In reality, this angle difference will vary from one electrical cycle to the other. Big variation in the angle of the Hall sensor will affect the commutation of the motor and thus its performance. Although the Hall Sensor Angle Table (HSAT) can be obtained from the controller configuration, the values stored there are an average of the transitions over total number of electrical cycles, so a single variation between an hall transition will not be visible. The below script will print the whole Hall angle table, helping determining  any manufacturing issues that will be reflected in a single Hall state. 


Script parametrization


In the script one must define the number of pole pairs, the channel that the test will run and the reference power, that is the current that will be supplied to the motor during the test. For the test to give good results, the reference power should be set to the nominal current of the motor.



Test execution


To run the test, just send the script to device, go at the console tab and click run. The motor will rotate in both directions and print the Hall data. Of course the motor should be without load and able to rotate in both directions for the test to be performed. 


Results


The values that the script prints will be in electrical degrees. 360 degrees correspond to 512 electrical degrees, so the desired angle of 60 will be (60/360)*512 = 85 electrical degrees. The script will first print the electrical angles that each Hall transition is identified in every electrical cycle, in both forward and reverse directions, and then it will print the angle difference between each transitions. Some sample data by using a 5 pole pairs motor follow:



The Hall sensors have been detected in the following electrical angles:

 

forward direction:

 

1      2      3      4      5     

_      _      _      _      _     

9    95    179    266    349    435    

7    93    181    264    350    435    

10    96    178    265    351    435    

8    94    180    265    350    438    

9    96    181    264    352    435    

 

 

reverse direction:

 

1      2      3      4      5     

_      _      _      _      _     

75    159    243    331    413    499    

73    159    244    329    416    501    

74    157    244    329    413    498    

72    160    242    329    413    500    

74    158    245    328    415    501    

 

Angle differences in forward direction: 

 

1      2      3      4      5     

_      _      _      _      _     

86    84    87    83    86    86    

86    88    83    86    85    84    

86    82    87    86    84    87    

86    86    85    85    88    82    

87    85    83    88    83    86    

 


Angle differences in reverse direction: 

 

1      2      3      4      5     

_      _      _      _      _     

84    84    88    82    86    88    

86    85    85    87    85    84    

83    87    85    84    85    88    

88    82    87    84    87    84    

84    87    83    87    86    85    

 

 

Program execution finished.



Script


Copy and paste the below lines at the script tab:


 

'Purpose:

'--------

'This script can be used to report the angle difference between 

'each Hall transition and thus help determining any misalignments in 

'the Hall sensors. The controller stores the angle difference values in 

'the HSAT array, but these values are averaged and cannot report any 

'variances that concern a signle pole pair.

 

'Use:

'----

'The user has to configure the number of pole pairs, reference seek power and 

'the channel to be tested. This configuration happens AT THE SCRIPT parametrization

'filed and not on the controller itself. The script overrides the controller

'configurations and once its execution finishes, the user must restore

'his previous configuraitons

 

'Disclaimer:

'----------

'The script is tested and validated by Roboteq and is believed to be fault-free. 

'The possibility always exists, however, that the particular configuration and/or use 

'condition uncovers a fault that escaped our validation test coverage. Always 

'extensively test the script under your use conditions prior to deploying it in the field. 

 

option explicit

 

'**********************************************

'     SCRIPT PARAMETRIZATION

'  

'        modify below to conifugre the script

'**********************************************

 

#define POLE_PAIRS 'number of motor pole pairs

#define CHANNEL 1' The channel to perform the Sensor test

#define REFERENCE_POWER 10 'current used during calibration. Value in Amps

 

'**********************************************

'       PROGRAN STARTS HERE

 

'          Do not change for correct operation

'**********************************************

 

dim HALL[2as integer 'Previous and current HALL state

dim transitions as integer 'Number of expected transitions

dim transition as integer 'current Hall transition

dim FORWARD[300as integer 'Table with all the angles in forward direction

dim REVERSE[300as integer 'Table with all the angles in reverse direction

dim as integer 'auxiliary counter var

dim as integer 'auxiliary counter var

dim temp as integer 'auxiliary var for sorting algorithm

 

'**********************************************

'                MAIN PROGRAM

'**********************************************

 

gosub config 'make initial conifgurations

gosub forward 'move the motor in forward direction

wait(1000)

gosub reverse 'move the motor in reverse direction

wait(1000)

gosub sort_forward 'sort the forward direction angle table

gosub sort_reverse 'sort the reverse direction angle table

gosub prints 'print the results

 

terminate

 

'**********************************************

'                 SUB ROUTINES

'**********************************************

'---------------------------------------------

'       1. Configurations routine

'---------------------------------------------

'Configures open loop, sets the pole pairs and 

'reference seek power according to the script

'configurations

config:

 

transitions = (POLE_PAIRS+2) * 'We will discard the first and last rotation readings as it doesn't give accurate results

 

setconfig(_MMOD,CHANNEL,0'Set Open Loop

wait(1)

setconfig(_BMOD,CHANNEL,1'Set sinusoidal commutation

wait(1)

setconfig(_BZPW,CHANNEL,REFERENCE_POWER*10'set the reference seek power

wait(1)

setconfig(_BPOL,CHANNEL,POLE_PAIRS'set the number of pole pairs

wait(1)

 

return

'---------------------------------------------

'       2. Forward routine

'---------------------------------------------

'gives a positive motor command and reads the electrical angles

'when the hall transitions occur

forward:

 

transition 0

setcommand(_VPM,CHANNEL,POLE_PAIRS+2)

 

setTimerCount(1,5000'Load the response timer with 5 sec

 

while(getvalue(_ANG,CHANNEL)=0' wait until there is applied electrical field

    

    if getTimerState(1)

        print("Not applied power"'if 5 seconds pass without applied power terminate

        terminate

    end if

 

end while

 

while(transition<transitions-1)

 

    gosub wait_until_transition

    FORWARD[transition]= getvalue(_ANG,CHANNEL)

    transition++

    

end while

 

return

'---------------------------------------------

'       3. Reverse routine

'---------------------------------------------

'gives a reverse motor command and reads the electrical angles

'when the hall transitions occur

reverse:

 

transition 0

setcommand(_VPM,CHANNEL,-POLE_PAIRS-2)

 

setTimerCount(1,5000'Load the response timer with 5 sec

 

while(getvalue(_ANG,CHANNEL)=0' wait until there is applied electrical field

    

    if getTimerState(1)

        print("Not applied power"'if 5 seconds pass without applied power terminate

        terminate

    end if

 

end while

 

while(transition<transitions-1)

 

    gosub wait_until_transition

    REVERSE[transition]= getvalue(_ANG,CHANNEL)

    transition++

    

end while

 

return

'---------------------------------------------

'     4. Wait until Hall transition routine

'---------------------------------------------

'Waits there until there is a Hall transition

'and gets the electrical field angle

 

wait_until_transition:

 

HALL[0] = getvalue(_HS,CHANNEL'read the current HALL status

HALL[1] = HALL[0]

 

setTimerCount(1,5000'Load the resonse timer with 5 sec

 

while(HALL[0]=HALL[1])

    

    HALL[1] = getvalue(_HS,CHANNEL)

    

    if getTimerState(1)

        print("No response from HALL")

        terminate

    end if

    

    

end while

    

return

 

'---------------------------------------------

'       5. Print routine

'---------------------------------------------

'Prints the results and makes the angle difference calculations

 

prints:

 

print("The Hall sensors have been detected in the following electrical angles:\n \n")

 

 

print("forward direction:\n \n")

print("1 \t 2 \t 3 \t 4 \t 5 \t 6 \n")

print("_ \t _ \t _ \t _ \t _ \t _ \n")

 

for transition 1+andwhile transition transitions+1-6 'discard first and last cycle

    print (FORWARD[transition-1],"\t")

    wait(50)

    if ((transition mod 6) = 0)

        print("\n")

        wait(50)

    end if

next

 

print(" \n \n")

 

wait(50)

 

print("reverse direction:\n \n")

print("1 \t 2 \t 3 \t 4 \t 5 \t 6 \n")

print("_ \t _ \t _ \t _ \t _ \t _ \n")

 

for transition 1+andwhile transition transitions+1-6 'discard first and last cycle

    print (REVERSE[transition-1],"\t")

    wait(50)

    if ((transition mod 6) = 0)

        print("\n")

        wait(50)

    end if

next

 

print(" \nAngle differences in forward direction: \n \n")

print("1 \t 2 \t 3 \t 4 \t 5 \t 6 \n")

print("_ \t _ \t _ \t _ \t _ \t _ \n")

 

1+6

 

while transitions+1-6

 

    for transition andwhile transition j+6

        

        if ((transition mod <> 0or (transition ))

            print (abs(FORWARD[transition-1] - FORWARD[transition]),"\t")            

        elseif ((transition mod and (transition <> )) 

            print (abs(FORWARD[transition-1]-512) + FORWARD[transition 6],"\t")

        end if

        

    wait(50)

        

    next

    

    print("\n")

    wait(50)

    

    J+=6

 

end while

 

print(" \n \n")

 

print(" \nAngle differences in reverse direction: \n \n")

print("1 \t 2 \t 3 \t 4 \t 5 \t 6 \n")

print("_ \t _ \t _ \t _ \t _ \t _ \n")

 

1+6

 

while transitions+1-6

 

    for transition andwhile transition j+6

        

        if ((transition mod <> 0or (transition ))

            print (abs(REVERSE[transition-1] - REVERSE[transition]),"\t")            

        elseif ((transition mod and (transition <> )) 

            print (abs(REVERSE[transition-1]-512) + REVERSE[transition 6],"\t")

        end if

        

    wait(50)

        

    next

    

    print("\n")

    wait(50)

    

    J+=6

 

end while

 

print(" \n \n")

 

print("Program execution finished.\n")

return

 

'---------------------------------------------

'    6. Sort positive angle table routine

'---------------------------------------------

'Sort the array from minimum to maximum value, to be easy to calculate the

'angle difference

'bubble sort algorithm 

sort_forward:

 

0

 

while (<transitions)

 

    for andwhile j+5

    

        for transition andwhile transition +5

            if FORWARD[transition] > FORWARD[transition+1]

                temp=FORWARD[transition]

                FORWARD[transition] = FORWARD[transition+1]

                FORWARD[transition+1] = temp

            end if

        next

    next

    

    j+=6

 

end while

        

return

 

'---------------------------------------------

'    6. Sort negative angle table routine

'---------------------------------------------

'Sort the array from minimum to maximum value, to be easy to calculate the

'angle difference

'bubble sort algorithm 

sort_reverse: 

 

0

 

while (<transitions)

 

    for andwhile j+5

    

        for transition andwhile transition +5

            if REVERSE[transition] > REVERSE[transition+1]

                temp=REVERSE[transition]

                REVERSE[transition] = REVERSE[transition+1]

                REVERSE[transition+1] = temp

            end if

        next

    next

    

    j+=6

 

end while

        

return