Return to previous page
The following QBasic program is the core code of a program I wrote to allow me to use the Kulaga/Mauch DRO card as a data logger. Theis core code reads a single parameter from a text file called dro.ini that is located in the same directory as this QBasic program and uses this parameter as the base address of the DRO card. In my implementation it is the address 544. The program will initialize the DRO card and then read X and Y incremental count values and both write them to the screen and to a file called myTest.txt in the current directory. You have to create the myText.txt file before you run the program, but it does not need anything in the file and if you have anything in the file it will be overwritten the each time you run the program.
If you want to create a full DRO out of this core code you will need to convert the incremental counts to linear (or angular if desired) displacements and you will need to watch the incremental counts for overflows (it maxes at 2^24 and then rolls to 0) and watch when going in the opposite direction as the counter goes from 0 to 2^24 and then counts backwards so your movement in that direction are really the 2^24 - the count received displayed as a negative.
If you have any questions feel free to contact me at timg@ktmarketing.com
DIM CLOCKDATA AS INTEGER
DIM CLOCKSETUP AS INTEGER
DIM INPUTSETUP AS INTEGER
DIM QUADX1 AS INTEGER
DIM QUADX2 AS INTEGER
DIM QUADX4 AS INTEGER
DIM BPRESET AS INTEGER
DIM BPRESETB AS INTEGER
DIM CNTRRESET AS INTEGER
DIM CNTRRESETB AS INTEGER
DIM TRSFRPRCNTR AS INTEGER
DIM TRSFRCNTROL AS INTEGER
DIM EFLAGRESET AS INTEGER
DIM INDEXDISABLE AS INTEGER
DIM BASE7266 AS INTEGER
DIM XAXISDATA AS INTEGER
DIM XAXISCTRL AS INTEGER
DIM YAXISDATA AS INTEGER
DIM YAXISCTRL AS INTEGER
DIM ZAXISDATA AS INTEGER
DIM ZAXISCTRL AS INTEGER
DIM WAXISDATA AS INTEGER
DIM WAXISCTRL AS INTEGER
DIM CurrentCountX AS LONG 'Current value of X Counter
DIM myCountX AS INTEGER 'Decimal equivalent low bit X
DIM myCount2X AS LONG 'Decimal equivalent mid bit X
DIM myCount3X AS LONG 'Decimal equivalent high bit X
DIM CurrentCountY AS LONG 'Current value of Y Counter
DIM myCountY AS INTEGER 'Decimal equivalent low bit Y
DIM myCount2Y AS LONG 'Decimal equivalent mid bit Y
DIM myCount3Y AS LONG 'Decimal equivalent high bit Y
'reads portbase file set variables
OPEN "dro.ini" FOR INPUT AS #1
INPUT #1, BASE7266
CLOSE #1
'End reading in parameters
'Sets static parameters for LS7622
CLOCKDATA = 14
CLOCKSETUP = &H98 '152
INPUTSETUP = &HC1 '193
QUADX1 = &HA8 '168
QUADX2 = &HB0 '176
QUADX4 = &HB8 '184
BPRESET = &H1 '1
BPRESETB = &H81 '129
CNTRRESET = &H2 '2
CNTRRESETB = &H82 '130
TRSFRPRCNTR = &H8 '8
TRSFRCNTROL = &H90 '144
EFLAGRESET = &H86 '134
INDEXDISABLE = &HE0 '224
'BASE7266 = &H220 '544 This param moved to ini file
'END SET Static Parameters
'Set variable parameters
XAXISDATA = BASE7266 + 0
XAXISCTRL = BASE7266 + 1
YAXISDATA = BASE7266 + 2
YAXISCTRL = BASE7266 + 3
ZAXISDATA = BASE7266 + 4
ZAXISCTRL = BASE7266 + 5
WAXISDATA = BASE7266 + 6
WAXISCTRL = BASE7266 + 7
'End Set variable parameters
'Initial LS7266
OUT XAXISCTRL, INDEXDISABLE
OUT XAXISCTRL, EFLAGRESET
OUT XAXISCTRL, BPRESETB
OUT XAXISDATA, CLOCKDATA
OUT XAXISCTRL, CLOCKSETUP
OUT XAXISCTRL, INPUTSETUP
OUT XAXISCTRL, QUADX4
OUT XAXISCTRL, CNTRRESETB
OUT XAXISCTRL, BPRESET
OUT XAXISDATA, 0
OUT XAXISDATA, 0
OUT XAXISDATA, 0
OUT XAXISCTRL, TRSFRPRCNTR
OUT XAXISCTRL, TRSFRCNTROL
OUT XAXISCTRL, BPRESET
OUT YAXISCTRL, BPRESET
OUT YAXISDATA, 0
OUT YAXISDATA, 0
OUT YAXISDATA, 0
OUT YAXISCTRL, TRSFRPRCNTR
OUT YAXISCTRL, TRSFRCNTROL
OUT YAXISCTRL, BPRESET
OUT YAXISCTRL, INDEXDISABLE
OUT YAXISCTRL, EFLAGRESET
OUT YAXISCTRL, BPRESETB
OUT YAXISDATA, CLOCKDATA
OUT YAXISCTRL, CLOCKSETUP
OUT YAXISCTRL, INPUTSETUP
OUT YAXISCTRL, QUADX4
OUT YAXISCTRL, CNTRRESETB
OUT YAXISCTRL, BPRESET
'The following will initialize the Z and W axis if using a 4 channel card.
'Uncomment if needed
' OUT ZAXISCTRL, INDEXDISABLE
' OUT ZAXISCTRL, EFLAGRESET
' OUT ZAXISCTRL, BPRESETB
' OUT ZAXISDATA, CLOCKDATA
' OUT ZAXISCTRL, CLOCKSETUP
' OUT ZAXISCTRL, INPUTSETUP
' OUT ZAXISCTRL, QUADX1
' OUT ZAXISCTRL, CNTRRESETB
' OUT ZAXISCTRL, BPRESET
' OUT ZAXISDATA, 0
' OUT ZAXISDATA, 0
' OUT ZAXISDATA, 0
' OUT ZAXISCTRL, TRSFRPRCNTR
' OUT ZAXISCTRL, TRSFRCNTROL
' OUT ZAXISCTRL, BPRESET
' OUT WAXISCTRL, BPRESET
' OUT WAXISDATA, 0
' OUT WAXISDATA, 0
' OUT WAXISDATA, 0
' OUT WAXISCTRL, TRSFRPRCNTR
' OUT WAXISCTRL, TRSFRCNTROL
' OUT WAXISCTRL, BPRESET
'End Initilize
CLS
OPEN "myTest.txt" FOR OUTPUT AS #3 'OPEN FILE TO CLEAR IT
PRINT #3, "StartTest"
CLOSE #3
OPEN "myTest.txt" FOR APPEND AS #2 'Open file for capture
'Run main loop until quit is signaled
PRINT "Press any key to halt test"
DO WHILE INKEY$ = ""
'Read in from LS7266 X Axis
OUT XAXISCTRL, TRSFRCNTROL
OUT XAXISCTRL, BPRESET
myDataX = INP(XAXISDATA)
myData2X = INP(XAXISDATA)
myData3X = INP(XAXISDATA)
'Finish Read from LS7266
'Change myDataX counts to a single decimal number
myCountX = myDataX
myCount2X = myData2X * 256
myCount3X = myData3X * 65536
CurrentCountX = myCountX + myCount2X + myCount3X
'End convert to decimal
'Read in from LS7266 Y Axis
OUT YAXISCTRL, TRSFRCNTROL
OUT YAXISCTRL, BPRESET
myDataY = INP(YAXISDATA)
myData2Y = INP(YAXISDATA)
myData3Y = INP(YAXISDATA)
'Finish Read from LS7266
'Change myDataY counts to a single decimal number
myCountY = myDataY
myCount2Y = myData2Y * 256
myCount3Y = myData3Y * 65536
CurrentCountY = myCountY + myCount2Y + myCount3Y
'End convert to decimal
'Record to file & write to screen
PRINT CurrentCountX, CurrentCountY
PRINT #2, CurrentCountX, CurrentCountY
LOOP
myExit:
CLOSE #2
END
Return to previous page