Hi darel,
i have a motor control application. in my application pic 16f877 is reading 2 position and then take the ratio of these values and multiply with the constant velocity. for example
x=5 y=10 then Vy = Vc (constan velocity) , Vx = Vc*x/y
so two motor begin and stop at the same time. i wrote some code by using Div32 but sometimes i cannot get the values thet it must be.
// for Trial i give posy greater than posx
POSX VAR WORD
POSX1 VAR POSX.BYTE1
POSX0 VAR POSX.BYTE0
POSY VAR WORD
POSY1 VAR POSY.BYTE1
POSY0 VAR POSY.BYTE0
V VAR WORD
V0 VAR V.BYTE0
V1 VAR V.BYTE1
HV VAR WORD
HV0 VAR HV.BYTE0
HV1 VAR HV.BYTE1
A VAR WORD
A0 VAR A.BYTE0
A1 VAR A.BYTE1
C VAR WORD
C1 VAR C.BYTE1
C0 VAR C.BYTE0
DUMMY VAR WORD
Asm
PutMulResult macro Const32
MOVE?CB Low Const32, R2
MOVE?CB Low (Const32 >> 8), R2 + 1
MOVE?CB Low (Const32 >> 16), R0
MOVE?CB Low (Const32 >> 24), R0 + 1
endm
EndAsm
GoSub USBREAD
POSX1=HB
POSX0=LB
GoSub USBREAD
POSY1=HB
POSY0=LB
IF POSY > 6554 Then
DUMMY = POSY * 10 // i scale posy by 10
C= Div32 POSX
@ PutMulResult 2236920 // i also enter here the scaled c constant velocity by 10
V= Div32 C
HV = 34 / C
Else
DUMMY = POSY * 10
C = DUMMY / POSX
@ PutMulResult 2236920
V= Div32 C // when this is greter than 16 bits it returns ffff
HV = 34 / C
EndIF
how can i get the V when it is greater than 16 bit ?
thanks




Bookmarks