11.7 Step 6. Closed Loop Position Control
(BUILDLEVEL == CLOSED_LOOP_POSITION)
This build level closes the position
loop in addition to the speed and current loops.
Go to the settings.h file and
change the definitions to match the following (closed loop position control,
debug buffers on, 8000 cycles per set point):
Figure 11-28 Closed Loop Position -
BUILDLEVEL
If desired, go to the
single_chip_servo.c file and modify the Speed set point array. Default values
shown below.
Values are duplicated to
give the motor time to get to the position before the setpoint cycle
count is up.
Once the project is loaded, open
the 'single_chip_servo.c' file and find the following line, then right-click and
select 'Run to Line'.
Figure 11-29 Closed Loop Position -
Run to Line
Running to this line allows the
control code to run through the eight different setpoints and fill up the debug
buffer so that the grap can be viewed.
Check
the output by importing the following graphs:
Figure 11-30 Closed Loop Position -
Position and Speed Graph 1
Example output shown below (speed
and position graphed from top to bottom). Notice how speed goes to +-500RPMs
during the position changes and stays there until the position is reached. The
position ramp slope is determined by the MAX_POS_CHANGE definition in the
settings.h file.
Figure 11-31 Closed Loop Position -
Position and Speed Graph 2
It is a difficult to see how
accurate the position is in the CCS graph above, so you can also use the CCS
memory browser to dump 'gDebugBuff5' to a text file in order review in Excel or
Matlab. Once you do that, you can see how accurate the position actually is:
typically +-0.001° from the requested target once the position has settled
(shown in Figure 11-32 for two of the requested positions):
Figure 11-32 Closed Loop Position -
Position Control Accuracy