-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMXD2125.spin
79 lines (68 loc) · 9.78 KB
/
MXD2125.spin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
''******************************************
''* Memsic Dual Accelerometer Driver v1.0 *
''* Author: Paul Baker *
''* Copyright (c) 2007 Parallax, Inc. *
''* See end of file for terms of use. *
''******************************************
VAR
long cog, XVal, YVal 'variable which contains the cog identifier and Raw sensor data
PUB stop
'' Stop driver - frees a cog
if cog
cogstop(cog)
PUB start(Xin,Yin):okay
ctramode := %1000 << 26 + Xin 'construct value for counter A mode (POS accumulator)
ctrbmode := %1000 << 26 + Yin 'construct value for counter B mode (POS accumulator)
pinwaitm := |< Xin + |< Yin 'construct pin mask for waiting
'' Start driver - starts a cog
'' returns false if no cog available
okay := cog := cognew(@MXD2125, @XVal)
PUB x
return XVal 'return current X axis pulse width
PUB y
return YVal 'return current Y axis pulse width
DAT
MXD2125 org
'set shared memory locations
mov Xarg, par 'store location to write X value
mov Yarg, par 'store location to write Y value
add Yarg, #4 'adjust location of Y value
'establish counter A as pulse width counter
mov frqa, #1 'add 1 to counter A total each cycle pin is high
mov ctra, ctramode
'establish counter B as pulse width counter
mov frqb, #1 'add 1 to counter B total each cycle pin is high
mov ctrb, ctrbmode
:loop waitpeq zero, pinwaitm 'wait until both channels have completed thier cycle
mov temp, phsa 'copy X axis value to hub
wrlong temp, Xarg
mov temp, phsb 'copy Y axis value to hub
wrlong temp, Yarg
mov phsa, zero 'reset counter values
mov phsb, zero
waitpeq pinwaitm, pinwaitm 'wait until both channels start thier cycle
jmp #:loop 'do it again
zero LONG 0 'value zero
temp LONG 0 'temporary loaction to store counter value
Xarg LONG 0 'address to store X axis pulse width
Yarg LONG 0 'address to store X axis pulse width
ctramode LONG 0 'counter A mode value
ctrbmode LONG 0 'counter B mode value
pinwaitm LONG 0 'pin mask used in waitpeq instruction
{{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ TERMS OF USE: MIT License │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │
│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │
│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
│is furnished to do so, subject to the following conditions: │
│ │
│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
│ │
│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │
│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │
│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
}}