The below script can be used to test the functionality of the Hall and Encoder sensors of a motor. To run it, the motor together with its sensors must be connected to the controller.


Steps


1. Copy - paste the below script in the script tab


 

'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

 

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

'                  ADD BELOW THE 

'                   ENCODER PPR

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

#define PPR 4096  '<--- Encoder pulses per revolution

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

'                  ADD BELOW THE 

'               MPOTOR NOMINAL CURRENT

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

#define REFERENCE_POWER 70 '< --- Amps used during calibration. 

'                            Must be equal to nominal current. 

'                            Value in amps*10         

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

'                 ADD BELOW THE 

'               MPOTOR POLE PAIRS

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

#define POLE_PAIRS '< --- Pole pairs of the motor. 

'                           Value is pole number divided by 2 

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

 

' Script starts here. DON'T MODIFY BELOW

 

 

#define CHANNELS 2               'Number of channels to be tested       

#define HALL_UP_LIMIT 90         'Maximum allowed electrical angle between two Hall transitions. Nominal is 85. Value in degrees*512/360

#define HALL_DOWN_LIMIT 80       'Minimum allowed electrical angle between two Hall transitions. Nominal is 85. Value in degrees*512/360

#define HALL_ZERO_MARGIN 14      'The acceptable error for the HALL_ZERO value. Default value is 14 that corresponds to 10 degrees. Value in degrees*512/360

 

 

#define ENCODER_MIN 15768        'Minumum allowed encoder counts per one rotation. Nominal is 16384

#define HALL_ERROR 2             'Maximum allowed Hall error counts in one rotation

 

 

'Script parameters. Do not modify

 

 

dim channel as integer

dim timeout as integer

dim power as integer

dim command as integer

dim encoderError as integer

 

 

dim hStatus as integer

dim statusCounter as integer

dim encoderCounter as integer

dim hallCounter as integer

 

dim motorConnected as boolean

dim sensorsOk as boolean

dim setupOk as boolean

 

motorConnected false

sensorsOk false

setupOk false

 

 

'check sensors vars

 

dim isOneOnce as boolean

isOneOnce false

'Check alignment vars

 

dim positive[6as integer

dim negative[6as integer

 

dim isAligned as boolean

 

isAligned false

 

'Open Loop vars

 

dim motorRotates as boolean

dim swapHall as boolean

dim swapEnc as boolean

dim isOpenLoopOk as boolean

 

dim maxCurrentFw as integer

dim maxTorqueFw as integer

dim maxFluxFw as integer

 

dim maxEncSpeedFw as integer

dim maxHallSpeedFw as integer

dim minEncSpeedFw as integer

dim minHallSpeedFw as integer

 

dim maxCurrentRv as integer

dim maxTorqueRv as integer

dim maxFluxRv as integer

 

dim maxEncSpeedRv as integer

dim maxHallSpeedRv as integer

dim minEncSpeedRv as integer

dim minHallSpeedRv as integer

 

 

isOpenLoopOk false

motorRotates false

swapHall false

swapEnc false

 

maxCurrentFw 0

maxTorqueFw 0

maxFluxFw 0

maxCurrentRv 0

maxTorqueRv 0

maxFluxRv 0

maxHallSpeedFw 0

maxEncSpeedFw 0

minEncSpeedFw 5000

minHallSpeedFw 5000

maxHallSpeedRv 0

maxEncSpeedRv 0

minEncSpeedRv 5000

minHallSpeedRv 5000

 

encoderError 4*PPR/30

 

 

' closed Loop vars

 

dim isClosedLoopOk as boolean

 

isclosedLoopOk false

 

' wait until released vars

 

dim isreleased as boolean

isreleased false

 

'Load test vars

 

dim isLoadOk as boolean

dim pha[2as integer

 

isLoadOkfalse

pha[0] = 0

pha[1] = 0

 

'general vars

 

dim temp as integer

dim as integer

dim as integer

dim speed[2as integer

dim steps[2as integer

dim error[60as integer

dim warnings[20as integer

dim current as integer

 

temp 

current 

speed[0] = 0

speed[1] = 

steps[0] = 0

steps[1] = 0

 

timeout 

command 

channel 1

power 0

hStatus 0

statusCounter 

encoderCounter 0

hallCounter 0

 

wait(2000' Add 2 second wait, in case of script crash

setcommand(_G,1,0'Make command to both motors zero, in case that previous command is running with RWD 0

setcommand(_G,2,0)

 

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

'               MAIN PROGRAM

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

 

wait(1000)

 

print("This script is used to test the motors having Hall sensors and "PPR," resolution encoder\n \n")

 

wait(4000)

 

print("STARTING\n")

print("--------\n \n")

 

wait(2000)

 

print("1. Initializing profile... \n \n")

 

gosub initialize_profile

 

print("-Profile loaded! \n \n")

 

for channel andwhile (channel < (CHANNELS+1))

 

    gosub initialize_parameters

    

    wait(2000)

    

    print("2. Checking if motor "channel," is connected... \n \n")

    

    wait(2000)

    

    gosub is_motor_connected

        

    if motorConnected

        

        wait(2000)

        steps[channel-1]++ 'step = 1

    

        print("3. Checking if sensors are present... \n \n")

    

        gosub check_sensors

        

    end if

    

    if sensorsOk

    

        wait(1000)    

        steps[channel-1]++ 'step = 2

        

        print("4. Performing motor/sensor setup... \n \n")

    

        gosub motor_setup

        

    end if

    

    if setupOk

 

        wait(1000)    

        steps[channel-1]++ 'step = 3            

        print("5. Checking Hall sensors alignment... \n \n \n")

            

        wait(3000)

        gosub check_alignment

        

    end if

    

    if (channel 1)

        print("\n \nproceeding to channel 2\n \n")

        wait(2000)

    end if

    

 

 

next

 

 

wait(3000)

 

print("\n\nTest finished \n \n")

    

terminate

 

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

'                      SUBS

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

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

'             0. Initialize profile

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

' Initialize the controller's profile. I will 

' configure sinusoidal for both motors, configure

' the reference seek power, disable sensor error

' protection, reset the Hall angle table

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

 

initialize_profile:

 

for channel andwhile channel 3

 

setconfig(_MMOD,channel,0)

wait(1)

setconfig(_SED,channel,0)

wait(1)

setconfig(_BZPW,channel,REFERENCE_POWER)

wait(1)

setconfig(_BMOD,channel,1)

wait(1)

setconfig(_BPOL,channel,POLE_PAIRS)

wait(1)

setconfig(_EPPR,channel,PPR)

wait(1)

setconfig(_BFBK,channel,2)

wait(1)

setconfig(_BLFB,channel,0)

wait(1)

setconfig(_BLSTD,channel,0)

 

setconfig(_ALIM,channel,200)

wait(1)

 

next

 

setconfig(_RWD,0)

wait(1)

setconfig(_EMOD,1,18)

wait(1)

setconfig(_EMOD,2,34)

wait(1)

 

    

for andwhile <25

 

    setconfig(_HSAT,i,0)

    wait(1)

    

next

 

wait(250)

 

 

if((getvalue(_FF,1and 16))

 

    setcommand(_MG,1)

    

end if

 

wait(50)

 

channel 1

 

return

 

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

'             1. Initialize parameters

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

' Checks if at least two of the motor phases are 

' connected by giving a PWM voltage to the motor 

' and measuring the motor current 

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

 

initialize_parameters:

 

    maxCurrentFw 0

    maxTorqueFw 0

    maxFluxFw 0

    maxCurrentRv 0

    maxTorqueRv 0

    maxFluxRv 0

    maxHallSpeedFw 0

    maxEncSpeedFw 0

    minEncSpeedFw 5000

    minHallSpeedFw 5000

    maxHallSpeedRv 0

    maxEncSpeedRv 0

    minEncSpeedRv 5000

    minHallSpeedRv 5000

    timeout 

    command 

    power 0

    hStatus 0

    statusCounter 

    encoderCounter 0

    hallCounter 0    

        

    isAligned false    

    isOpenLoopOk false

    motorRotates false

    swapHall false

    swapEnc false

    isclosedLoopOk false

    isreleased false

    motorConnected false

    sensorsOk false

    setupOk false     

    isOneOnce false

    isLoadOk false

        

return

 

 

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

'             2. Is motor Connected

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

' Checks if at least two of the motor phases are 

' connected by giving a PWM voltage to the motor 

' and measuring the motor current 

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

 

is_motor_connected:

 

motorConnected false

timeout 0

command 

 

while timeout 5000 

 

    command ++

    timeout ++

    

    setcommand(_G,channelcommand/4)

    

    currentabs(getvalue(_A,channel))

    

    if (current 10

        

        setcommand(_G,channel,0)

        motorConnected true

        

        print("-motor "channel," is connected!\n \n")

        

        return

    

    end if 

    

    wait(1)

 

end while

 

setcommand(_G,channel,0)

 

 

print("-motor ",channel," is not connected!\n \n")

 

error[(channel-1)*30+1]=1

 

return

    

 

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

'             3. Check sensors

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

' Checks if at least two of the motor phases are 

' connected by giving a PWM voltage to the motor 

' and measuring the motor current 

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

    

check_sensors:

 

timeout 0

sensorsOk false

isOneOnce false

statusCounter 

 

setcommand(_C,channel,0)

wait(250)

setcommand(_CB,channel,0)

wait(250)

setcommand(_VPM,channel,POLE_PAIRS)

 

while (timeout<1000)

    

    if (getvalue(_A,channel)>REFERENCE_POWER*2/3)

    

        setcommand(_C,channel,0)

        wait(1)

        setcommand(_CB,channel,0)

        wait(1)

        exit while

        

    end if

    

    timeout++

    

    wait(1)

    

end while

 

timeout 0

 

while timeout 10000

    

    power getvalue(_P,channel)

    timeout++

    

    if ((timeout 1000and (power 0))

        

        print("\n \n-VPM Error. Motor power is zero! \n")

        error[(channel-1)*30+2]=1

        setcommand(_VPM,channel,0)

        return

        

    end if    

        

    if ((timeout 2000and (power 0))

    

        exit while

        

    end if

    

    if (timeout 9000)

        

        print("\n \n-VPM Error. Rotation did not finish on time! \n")

        

        setcommand(_VPM,channel,0)

        error[(channel-1)*30+3]=1

        return    

            

    end if

    

    hStatus getvalue(_HS,channel)

    

    if ((hStatus 1and (statusCounter 0))

        statusCounter++

    elseif ((hStatus 2and (statusCounter 1))

        statusCounter++

    elseif ((hStatus 3and (statusCounter 2))    

        statusCounter++

    elseif ((hStatus 4and (statusCounter 3))

        statusCounter++

    elseif ((hStatus 5and (statusCounter 4))

        statusCounter++

    elseif ((hStatus 6and (statusCounter 5))

        statusCounter++

    end if

    

    if(getvalue(_C,channel) = 1)

        isOneOnce true

    end if

    

    wait(1)

 

end while

 

setcommand(_VPM,channel,0)    

 

encoderCounter abs(getvalue(_C,channel))

hallCounter abs(getvalue(_CB,channel))

 

if (encodercounter >= 4*PPR-encoderErrorand (encodercounter <= 4*PPR+encoderErrorand (hallCounter >= 6*POLE_PAIRS-HALL_ERRORand (hallCounter <= 6*POLE_PAIRS+HALL_ERRORand (statusCounter 6)

    

    sensorsOk true

    

    print ("-sensors ok!\n \n")

    

else

    if (encoderCounter 0and (not isOneOnce)

        print("\n \n-Encoder not present! \n")

        error[(channel-1)*30+4]=1        

    elseif (encoderCounter 10and isOneOnce

        print("\n \n-One of the Encoder signals not present! \n")

        error[(channel-1)*30+5]=1

    elseif ((encoderCounter 4*PPR-encoderErroror (encoderCounter 4*PPR+encoderError))

        print ("\n \n-Encoder is malfunctioning. Encoder counts are ",encoderCounter," instead of "4*PPR,"! \n")

        error[(channel-1)*30+6]=1

    end if

    

    if (getvalue(_HS,channel) = 7)

        print("\n \n-Hall is not present! \n")

        error[(channel-1)*30+7]=1        

    else

        

        if ((hallCounter 6*POLE_PAIRS-HALL_ERRORor (hallCounter 6*POLE_PAIRS+HALL_ERROR))

            print ("\n \n- Hall is malfunctioning. Hall counts are ",hallCounter," instead of "6*POLE_PAIRS,"! \n")

            error[(channel-1)*30+8]=1

        end if

        

        if (statusCounter <> 6)

            print("- At least one of the Hall signals is missing! \n")

            error[(channel-1)*30+9]=1

        end if

    

    end if

    

end if    

 

    

return

 

    

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

'             4. Motor/Sensor setup

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

' Checks if at least two of the motor phases are 

' connected by giving a PWM voltage to the motor 

' and measuring the motor current 

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

    

motor_setup:

 

setupOk false

timeout 0

 

setcommand(_MSS,channel)

 

while(timeout 4000)

 

    timeout++

    wait(1)

    

    if (getvalue(_P,channel)>50)

        exit while

    end if

    

end while

 

if (timeout 4000)

    

    print("\n \n-Motor/Sensor setup timeout! \n")

    error[(channel-1)*30+10]=1

    return

    

end if    

 

timeout 

 

print("HS \t A \t P \n")

 

while (timeout<2000)

    

    timeout++

    powergetvalue(_P,channel)

    

    if (power 0)

    

        print("\n \n-Motor/Sensor setup ok!\n \n")

        setupOk true

        return

        

    end if

    

    wait(10)

    

print(getvalue(_HS,channel),"\t",getvalue(_A,channel),"\t",getvalue(_P,channel),"\n")

        

end while

 

print("\n \n-Motor/Sensor setup timeout! \n")

error[(channel-1)*30+10]=1

 

return

 

 

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

'             5. Check Hall Alignment

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

' Checks if at least two of the motor phases are 

' connected by giving a PWM voltage to the motor 

' and measuring the motor current 

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

 

check_alignment:

 

isAligned true

 

' Read the HSAT

 

for andwhile 6

 

    negative[i] = getconfig(_HSAT,((channel-1)*12)+i+1)

    positive[i] = getconfig(_HSAT,((channel-1)*12)+i+7)

    

next

 

'Sort the HSAT

 

for andwhile 6

    for andwhile < (-1 )

        

        if negative[j]>negative[j+1]

            temp negative[j]

            negative[j] = negative[j+1]

            negative[j+1] = temp

        end if

        

        if positive[j]>positive[j+1]

            temp positive[j]

            positive[j] = positive[j+1]

            positive[j+1] = temp

        end if

    next

next

 

 

Print("Hall sensors negative direction:\n \n")

    

for andwhile 6

 

    print(negative[i],"\t")

    

next    

 

wait(250)

 

Print("\n \nNegative direction angle difference:\n \n")

 

for andwhile 5

    

    print(abs(negative[i]-negative[i+1]),"\t")

    

    if ((abs(negative[i]-negative[i+1])> HALL_UP_LIMITor (abs(negative[i]-negative[i+1]) < HALL_DOWN_LIMIT))

    

        isAligned false     

        

    end if

    

next    

 

wait(250)

 

print("\n \n")

 

Print("Hall sensors positive direction:\n \n")

for andwhile 6

 

    print(positive[i],"\t")

    

next    

 

print("\n")

 

wait(250)

 

Print("\n \nPositive direction angle difference:\n \n")

 

for andwhile 5

    

    print(abs(positive[i]-positive[i+1]),"\t")

    if ((abs(positive[i]-positive[i+1])> HALL_UP_LIMITor (abs(positive[i]-positive[i+1]) < HALL_DOWN_LIMIT))

    

        isAligned false    

        

    end if

next

 

wait(250)

 

print("\n")

 

if (isAligned false)    

    print("\n \n \n-Hall sensors not well aligned!\n \n")

    error[(channel-1)*30+11]=1

    warnings[(channel-1)*10+0] = 'Update the first elemnt of the warnings array.

    

else

    print ("\n \n \n-Hall sensors are well aligned! \n \n")

end if

 

isAligned true 'Made the flag again true so the motor test does not finish if the sensors are misaligned

 

return

 

 

 

2. Go at line 8 of the script and configure the encoder resolution (PPR), the motor nominal current and pole pairs. Note that the nominal current should be added in A/10, so 10 A for example should be written as 100. 



3. Click "to device" to download the script on the controller



4. Go at the console tab and clear the logs


5. Run script



6. Once the test is finished copy the logs and send them for evaluation