Well I updated the brat code to convert everything to fixed point math instead of floating point and I think I have things working now. But I am not sure in this simple case how much it is worth it. So I created a simple TimerA counter with an ASM interrupt handler and instrumented the Movement function. For example here is the integer version:
[code];--------------------------------------------------------------------
;[MovementCB] = This callback will be called by movement in a loop in between when HServo is called and
; while it waits for the Hservo to complete. The function has the ability to abort the wait and potentially
; other calls to movement by setting the variable fAbortCommand. Note Movement will not clear this flag, as
; this will allow whole sequences to be aborted easily.
MovementCB:
gosub PS2INPUT[0] ; call Ps2input but tell it we are not the main loop
return
;--------------------------------------------------------------------
;[Movement] - This is the main Hservo interface. This function takes new positions for each of the Legs servos
; in 10s of a degree as well as the time we want the movement to take. We then compute the speed
; of each of the servos, such that all of the servos complete their moves at the same time.
; This function does not return until the servos have completed their movement.
;
; This version has a call back function that is called in a loop after the HSERVO command has issued, until
; the movements have completed. This allows the program to call off to other Input devices or dow other background
; tasks while the movement is active.
;Should never need to edit anything below this line. Add user subroutines above this and below main.
lefthippos1 var slong
leftkneepos1 var slong
leftanklepos1 var slong
righthippos1 var slong
rightkneepos1 var slong
rightanklepos1 var slong
last_lefthippos1 var slong
last_leftkneepos1 var slong
last_leftanklepos1 var slong
last_righthippos1 var slong
last_rightkneepos1 var slong
last_rightanklepos1 var slong
lhspeed var slong
lkspeed var slong
laspeed var slong
rhspeed var slong
rkspeed var slong
raspeed var slong
MoveTime var slong
MaxSpeed1 var slong
longestmove1 var slong
;movement [lefthippos1,leftkneepos1,leftanklepos1,righthippos1,rightkneepos1,rightanklepos1,speed1]
movement [rightanklepos1,rightkneepos1,righthippos1,leftanklepos1,leftkneepos1,lefthippos1,MoveTime]
TCA = 0 ; clear out the counter
wTimerCnt = 0 ;
enable timeraint
; several step movements may be interrupted, so check flag and return.
if fAbortCommand then
return
endif
if(MoveTime<> 0)then
gosub getlongest[lefthippos1-last_lefthippos1, |
leftkneepos1-last_leftkneepos1, |
leftanklepos1-last_leftanklepos1, |
righthippos1-last_righthippos1, |
rightkneepos1-last_rightkneepos1, |
rightanklepos1-last_rightanklepos1],longestmove1
MaxSpeed1 = ((longestmove1*stepsperdegree1)/(MoveTime/2))
gosub getspeed[lefthippos1,last_lefthippos1,longestmove1,MaxSpeed1],lhspeed
gosub getspeed[leftkneepos1,last_leftkneepos1,longestmove1,MaxSpeed1],lkspeed
gosub getspeed[leftanklepos1,last_leftanklepos1,longestmove1,MaxSpeed1],laspeed
gosub getspeed[righthippos1,last_righthippos1,longestmove1,MaxSpeed1],rhspeed
gosub getspeed[rightkneepos1,last_rightkneepos1,longestmove1,MaxSpeed1],rkspeed
gosub getspeed[rightanklepos1,last_rightanklepos1,longestmove1,MaxSpeed1],raspeed
else
lhspeed=0;
lkspeed=0;
laspeed=0;
rhspeed=0;
rkspeed=0;
raspeed=0;
endif
; Note, the positions are in 10s of a degree and the steps per are in 10s of degree so need to divide by 100
hservo [lefthip(-lefthippos1stepsperdegree1)/100 + lefthip_start\lhspeed, |
righthip(righthippos1stepsperdegree1)/100 + righthip_start\rhspeed, |
leftknee(-leftkneepos1stepsperdegree1)/100 + leftknee_start\lkspeed, |
rightknee(rightkneepos1stepsperdegree1)/100 + rightknee_start\rkspeed, |
leftankle(-leftanklepos1stepsperdegree1)/100 + leftankle_start\laspeed, |
rightankle(rightanklepos1stepsperdegree1)/100 + rightankle_start\raspeed]
gosub GetTimerVal
disable timeraint
wMovementCalls = wMovementCalls + 1 ; number of times we called this.
lMovementDTSum = LMovementDTSum + wTimerCnt
...[/code]
So I am only measuring the conversion times up through the call to HSERVO. I then added code to the processing of the start button, that when we hit start to turn off the brat it dumps out the counters.
For the integer version I get: Calls: 33 Tot: 43961 Avg: 1332
For the floating point version I get: Calls: 25 Tot: 34503 Avg: 1380
The counter is clock/32 or 2uS. So the floating point/integer math cost about .1ms per call to movement. Probably not worth the trouble
Thoughts?
Kurt