OK now next step are steped.
I write calculation to increment in CW my variable defined as LONG to be incremented from position buffer
which go from 0-12500 and again and again..
Code:
' Pic 18F4431 @ 20MHz true XTAL
define osc 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 64
DEFINE HSER_CLROERR 1
ADCON0=0
ANSEL0=0
PortA = 0
PortB = 0
PortC = 0
TRISA = %011100
TRISB = %00000000
TRISC = %10000000
QEICON=%10011000
DFLTCON = %00111000
MAXCNTL = %11010100
MAXCNTH = %00110000
PosLow VAR BYTE
PosHigh VAR BYTE
PosTemp VAR BYTE
Position VAR WORD
y var LONG
x var BYTE
x = 0
y = 0
POSCNTL = 0
POSCNTH = 0
PIR3.2 = 0
CLEAR
Start:
Gosub GetPosition
y = (x * 12500) + position
HSEROUT [dec y]
Pause 10
Goto Start
GetPosition:
PosHigh = POSCNTH
PosLow = POSCNTL
PosTemp = POSCNTL
If PosLow - PosTemp = 0 then Goto Done
PosHigh = POSCNTH
PosLow = POSCNTL
Done:
Position = POSHIGH * 256 + PosLow
if PIR3.2 = 1 then x = x+ 1
PIR3.2 = 0
RETURN
END
Now I can count a long trip of mechanic of machine which is present in LONG variable in CW direction.
But I have new problem in my head all these days and it is next.
I have BIT which indicate direction of motor and it is in QEICON.5.
If QEICON.5 is 0 then we go CCW and if it is 1 then we go CW direction.
Now if we go CW and stop motor it wil be 1 all the time to next move
and if we go CCW it will be 0 and after we stop from CCW it will be 0 all time to next move..
Confuse how to make matematic to implement new formula for decrement LONG variable in CCW :
y = y - (12500-position) or similar becous in CCW position go from 12500-0 and again 12500-0....
If any idea or someone want to help THANKS.
Regards Robert
Bookmarks