-
Notifications
You must be signed in to change notification settings - Fork 0
/
servoTest.spin
65 lines (46 loc) · 957 Bytes
/
servoTest.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
#define DEBUG
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 5_000_000 ' External oscillator = 5 MHz
OBJ
'qsb: "Quickstart Buttons"
mcp: "MCP3208"
#ifdef DEBUG
pst: "Parallax Serial Terminal"
#endif
VAR
long width
PUB servoTest | clocksPerNS, interval, lastCount, in, tick
clocksPerNS:=clkfreq/1000000
interval:=clocksPerNS * 20000
mcp.start(14,13,15,1)
'qsb.start
#ifdef DEBUG
pst.start(115200)
pst.str(string("servoTest"))
pst.NewLine
#endif
dira[8]~~
ctra[30..26]:=%00100
ctra[5..0]:=8
frqa:=1
width:=1500
lastCount:=cnt
tick:=0
in:=0
repeat
tick++
lastCount+=interval
in+=mcp.in(0)
if (tick & $7 == 0)
in>>=3
width:=(in>>1 <# 1500) + 750
#ifdef DEBUG
pst.dec(in)
pst.char($20)
pst.dec(width)
pst.NewLine
#endif
in:=0
phsa:=-clocksPerNS*width
waitcnt(lastCount)