Mouse encoder
I found this guy who hacked a mouse to use as a position sensor for a robot based on an article by Kronos robotics.
home.roadrunner.com/~maccody/robotics/mouse_hack/mouse_hack.html
but the code is written in forth.Can anyone translate this code into Basic?
home.roadrunner.com/~maccody/robotics/mouse_hack/mouse_hack.html
but the code is written in forth.Can anyone translate this code into Basic?
\ Dual synchronous serial port (DSSP) dual optical encoder (DOE) interface HEX 46FE R-TOP ! 4700 DUP H ! H-FENCE ! 8080 CONSTANT DSSP_OUT_BUS_BITS 0101 CONSTANT DSSP_IN_BUS_BITS 0002 CONSTANT DSSP_WRITE_EN 0001 CONSTANT DSSP_SCLK_LOW \ 8080 CONSTANT DSSP_FRAME_START 0080 CONSTANT DSSP_FRAME_START \ Used for testing of one optical encoder. \ 4040 CONSTANT DSSP_DATA_VALID 0040 CONSTANT DSSP_DATA_VALID \ Used for testing of one optical encoder. : DSSP_WRITE_BITS ( n -- ) DSSP_OUT_BUS_BITS AND \ Isolate the MSB of both bytes. DSSP_WRITE_EN OR \ Maintain the SSP bus drivers on. DUP \ Make a copy of the data. DSSP_SCLK_LOW OR \ Bring the SSP clock line low. 0018 FOR NEXT \ Extend duration of clock level 1A G! \ Output the data. NOP NOP \ Delay two clock cycles. 1A G! \ Output the data, bring the SSP clock line high. 0018 FOR NEXT \ Extend duration of clock level ; : DSSP_WRITE_BYTES ( n -- ) 7 FOR \ Enter loop to write out eight bits for each byte. DUP \ Make a copy of the data. DSSP_WRITE_BITS \ Write out the MSB of both bytes. 2* \ Shift the data left by one bit. NEXT \ Continue the loop. DROP \ Discard the trash data. ; : DSSP_WRITE_REGISTERS ( data addr -- ) DSSP_WRITE_EN 1A G! \ Output data to turn on the SSP bus drivers. DSSP_WRITE_BYTES \ Output address bytes onto SSP busses. DSSP_WRITE_BYTES \ Output data bytes onto SSP busses. 0000 1A G! \ Output data to turn off the SSP bus drivers. ; : DSSP_READ_BITS ( -- n ) DSSP_SCLK_LOW 1A G! \ Output data to bring the SSP clock line low. 0018 FOR NEXT \ Extend duration of clock level DSSP_IN_BUS_BITS \ Set up mask to isolate the incomming bits. 0000 1A G! \ Output data to bring the SSP clock line high. 0018 FOR NEXT \ Extend duration of clock level 1A G@ \ Input the data. AND \ Isolate the LSB of both bytes. ; : DSSP_READ_BYTES ( -- n ) 0 \ Initially start with an empty bit field. 7 FOR \ Enter loop to read in eight bits for each byte. 2* \ Shift the data left by one bit DSSP_READ_BITS \ Read in bits into LSB bit of both bytes. OR \ Combine new bits with shifted bits. NEXT ; : DSSP_READ_REGISTERS ( addr -- data ) DSSP_WRITE_EN 1A G! \ Output data to turn on the SSP bus drivers. DSSP_WRITE_BYTES \ Output address bytes onto SSP busses. NOP \ Pause for last bit before bus driver shut-off. 0000 1A G! \ Output data to turn off the SSP bus drivers. 00C7 FOR NEXT \ Loop 200 times for delay between write and read. DSSP_READ_BYTES \ Input data bytes from the SSP busses. ; : DOE_RESET ( -- ) 8080 8080 DSSP_WRITE_REGISTERS ; : DOE_POWER_DOWN ( -- ) 4040 8080 DSSP_WRITE_REGISTERS ; : DOE_KEEP_AWAKE ( -- ) 0101 8080 DSSP_WRITE_REGISTERS ; : DOE_LET_SLEEP ( -- ) 0000 8080 DSSP_WRITE_REGISTERS ; : DOE_CONFIG_PORTS ( -- data ) 0000 DSSP_READ_REGISTERS ; : DOE_STATUS ( -- data ) 0101 DSSP_READ_REGISTERS ; : DOE_DELTA_Y ( -- data ) 0202 DSSP_READ_REGISTERS ; : DOE_DELTA_X ( -- data ) 0303 DSSP_READ_REGISTERS ; : DOE_SQUAL ( -- data ) 0404 DSSP_READ_REGISTERS ; : DOE_MAX_PIXEL ( -- data ) 0505 DSSP_READ_REGISTERS ; : DOE_MIN_PIXEL ( -- data ) 0606 DSSP_READ_REGISTERS ; : DOE_PIXEL_SUM ( -- data ) 0707 DSSP_READ_REGISTERS ; : DOE_RESET_PIXEL_DATA ( -- ) 0000 8888 DSSP_WRITE_REGISTERS ; : DOE_READ_PIXEL_DATA ( addr -- code) DOE_RESET_PIXEL_DATA \ Reset the pixel hardware. 0640 FOR NEXT \ Delay loop of 1600 loops. 0143 FOR \ Loop 324 times to read in pixels 0808 \ Address for pixel data. DSSP_READ_REGISTERS \ Read bytes. SWAP \ Bring address to TOS. !+2 \ Write out values and increment by two bytes. NEXT \ Loop if all status bits are true. DROP \ Discard the address. ; : DOE_SHUTTER_UPPER ( -- data ) 0909 DSSP_READ_REGISTERS ; : DOE_SHUTTER_LOWER ( -- data ) 0A0A DSSP_READ_REGISTERS ; : DOE_INV_PRODUCT_ID ( -- data ) 1111 DSSP_READ_REGISTERS ; : CRUDE_FOCUS ( n -- ) 0 DO DOE_SQUAL 00FF AND 2 .H CR LOOP ; : PIXEL-DUMP ( addr -- ) ." {" CR \ Output initial open brace for data. 12 0 DO \ Eighteen rows in the image. ." {" \ Output open brace for row. 12 0 DO \ Eighteen pixels in each row. @+2 \ Read data value and increment pointer by two. SWAP \ Bring data value to TOS. 003F AND \ Mask to clear unused bits. 2* 2* \ Shift left by two to increase dynamic range. ." #" \ Output color triplet indicator DUP 2 .H \ Output first copy of byte for red color. DUP 2 .H \ Output second copy of byte for green color. 2 .H ." " \ Output third copy of byte for blue color. LOOP ." }" CR \ Output close brace for row and newline. LOOP ." }" CR \ Output close brace for data and newline. ; : GET-PIXELS R @ DOE_READ_PIXEL_DATA R @ PIXEL-DUMP ; : RAW-PIXEL-DUMP ( addr -- ) 12 0 DO \ Eighteen rows in the image. 12 0 DO \ Eighteen pixels in each row. @+2 \ Read data value and increment pointer by two. SWAP \ Bring data value to TOS. 00FF AND \ Mask to clear unused bits. 2 .H ." " \ Output byte. LOOP CR \ Output newline. LOOP CR \ Output newline. ; : GET-RAW-PIXELS R @ DOE_READ_PIXEL_DATA R @ RAW-PIXEL-DUMP ;
Comments
If you want to interface with the mouse in Basic you should definitely reference the original Kronos Robotics article.
- Sparks
·
The BASIC Stamp cannot communicate with a PS/2 or USB mouse. Speed and clock signals are issues.
·
I have been using the PAK VI and PAK XI co-processors from AWE Electronics with great success. I have been able to read the X & Y movement registers and buttons and I have been able to set the scaling, sample rate and resolution of most PS/2 mice. BS2 code is provided from AWE with the data sheets and application notes.
·
Some mice do not respond to all the commends and some mice do not respond to the middle button. The AWE products will not support the intelli mouse protocols with the rolling wheel and 5 buttons. However, almost all mice will power up to the IBM PS/2 or non-intelli mouse protocol.
·
I use the devices to pan & tilt using servos a laser pointer to keep my dog busy. The device is also being used to remotly control a TV and DVD using IR.
·
Attached are some links for reading.
·
http://www.awce.com/
·
http://www.awce.com/pak6.htm
http://www.awce.com/pak6.pdf
http://www.awce.com/pak6mou.htm
http://www.awce.com/pak6mou1.htm
·
http://www.awce.com/pak11.htm
http://www.awce.com/pak11.pdf
http://www.awce.com/pak11note.htm
http://www.computer-engineering.org/ps2mouse/
·
You might also want to try this co-processor from MultiLabs:
http://www.multilabs.net/ezMOUSE.html
·
and an application note for the Basic Stamp: http://www.multilabs.net/Files/Using_the_ezMOUSE_with_the_BASIC_Stamp_2.pdf
I am not familiar with the MultiLabs EzMouse products.
·
SJW
·
Thank's a lot for sharing this info!
Already ordered mouse and floating math coprocessors [noparse]:)[/noparse]
Janis
Some commands require the PAKVI to return one (1) byte of data. Others require the PAKVI to return two (2) and sometime four (4) bytes of data. You must read all the bytes from the PAK to the BS2 even the ACK acknowledge byte.
Good luck.
SJW