-
Notifications
You must be signed in to change notification settings - Fork 15
/
stepper_motor.asm
87 lines (58 loc) · 1.41 KB
/
stepper_motor.asm
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
80
81
82
83
84
; this is an example of out instruction.
; it writes values to virtual i/o port
; that controls the stepper-motor.
; c:\emu8086\devices\stepper_motor.exe is on port 7
#start=stepper_motor.exe#
name "stepper"
#make_bin#
steps_before_direction_change = 20h ; 32 (decimal)
jmp start
; ========= data ===============
; bin data for clock-wise
; half-step rotation:
datcw db 0000_0110b
db 0000_0100b
db 0000_0011b
db 0000_0010b
; bin data for counter-clock-wise
; half-step rotation:
datccw db 0000_0011b
db 0000_0001b
db 0000_0110b
db 0000_0010b
; bin data for clock-wise
; full-step rotation:
datcw_fs db 0000_0001b
db 0000_0011b
db 0000_0110b
db 0000_0000b
; bin data for counter-clock-wise
; full-step rotation:
datccw_fs db 0000_0100b
db 0000_0110b
db 0000_0011b
db 0000_0000b
start:
mov bx, offset datcw ; start from clock-wise half-step.
mov si, 0
mov cx, 0 ; step counter
next_step:
; motor sets top bit when it's ready to accept new command
wait: in al, 7
test al, 10000000b
jz wait
mov al, [bx][si]
out 7, al
inc si
cmp si, 4
jb next_step
mov si, 0
inc cx
cmp cx, steps_before_direction_change
jb next_step
mov cx, 0
add bx, 4 ; next bin data
cmp bx, offset datccw_fs
jbe next_step
mov bx, offset datcw ; return to clock-wise half-step.
jmp next_step