summaryrefslogtreecommitdiff
path: root/software/main.asm
blob: 35fb24bfdefb55207e87252da227797e8dd20dcf (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
.device ATmega328P

.def 	step_mask = r16
.def 	step_reg = r17
.def 	loop_count = r18
.def 	inner_loop_reg_low = r26
.def 	inner_loop_reg_high = r27

.equ inner_val = 39998

; Port B Macros
.equ 	DDRB = 0x04
.equ 	PORTB = 0x05
.equ	PINB0	= 0	; Port B Input Pins bit 0
.equ	PINB1	= 1	; Port B Input Pins bit 1
.equ	PINB2	= 2	; Port B Input Pins bit 2
.equ	PINB3	= 3	; Port B Input Pins bit 3
.equ	PINB4	= 4	; Port B Input Pins bit 4
.equ	PINB5	= 5	; Port B Input Pins bit 5

; Port D Macros
.equ	DDRD = 0x0a
.equ 	PORTD = 0x0b
.equ	PIND2	= 2	; Port D Input Pins bit 2
.equ	PIND3	= 3	; Port D Input Pins bit 3
.equ	PIND7	= 7	; Port D Input Pins bit 7

.org 0x00
	jmp	setup

setup:
	; enable data direction registers; iref, diag1, diag0 are disabled
	sbi	DDRB,PINB0
	sbi DDRB,PINB1
	sbi DDRB,PINB2
	sbi DDRB,PINB3
	sbi DDRB,PINB4
	sbi DDRB,PINB5

	sbi DDRD,PIND2
	sbi DDRD,PIND3
	sbi DDRD,PIND7
	
	; configure tmc2100 cfg pins
	cbi PORTD,PIND7 ; chopper time off (140t_clk), cfg0
	sbi PORTD,PINB2 ; current setting (internal sense resistors), cfg3
	cbi PORTD,PINB3 ; chopper histeresis (5), cfg4
	sbi PORTD,PINB4 ; chopper blank time (24), cfg5
	cbi PORTD,PINB5 ; tmc2100 enable pin, cfg6

	; set direction
	sbi PORTD,(1<<PIND2)

	clr step_reg ; clear step register
	ldi step_mask,(1<<PIND3) ; put 1 into step register

main:
	eor step_reg,step_mask
	out PORTD,step_reg

	ldi loop_count,1
	rcall delay10ms

	rjmp main

delay10ms:
	ldi inner_loop_reg_low,LOW(inner_val)
	ldi inner_loop_reg_high,HIGH(inner_val)

inner_loop:
	sbiw inner_loop_reg_low,1
	brne inner_loop

	dec loop_count
	brne delay10ms

	nop

	ret