-
Notifications
You must be signed in to change notification settings - Fork 0
/
servoTest2.spin
60 lines (42 loc) · 858 Bytes
/
servoTest2.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
#define DEBUG
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 5_000_000 ' External oscillator = 5 MHz
OBJ
#ifdef DEBUG
pst: "Parallax Serial Terminal"
#endif
VAR
long width
PUB servoTest | clocksPerNS, interval, lastCount, dir, tick
clocksPerNS:=clkfreq/1000000
interval:=clocksPerNS * 20000
dir:=-50
#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
repeat
tick++
lastCount+=interval
width+=dir
if width=<700
dir:=20
if width=>2000
dir:=-20
#ifdef DEBUG
pst.dec(width)
pst.char($20)
if (tick & $7 == 0)
pst.NewLine
#endif
phsa:=-clocksPerNS*width
waitcnt(lastCount)