-
Notifications
You must be signed in to change notification settings - Fork 0
/
MCP492x_2DAC.asm
130 lines (116 loc) · 3.5 KB
/
MCP492x_2DAC.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
;------------------------------------------------------------------------------
; Ïîäïðîãðàììû äëÿ ðàáîòû ñ MCP4921, MCP4922
; 12-áèòíûé ÖÀÏ
; SPI èíòåðôåéñ
; ñ âîçìîæíîñòüþ èçìåíåíèÿ êîýôôèöèåíòà ïåðåäà÷è âûõîäíîãî áóôåðà
; âõîä äëÿ âíåøíåãî èñòî÷íèêà îïîðíîãî íàïðÿæåíèÿ VREF
;
; Ôîðìàò ïîñûëàåìîé êîìàíäû:
; bit 15 = 0 - çàïèñü â ðåãèñòð ÖÀÏ êàíàë A
; = 1 - çàïèñü â ðåãèñòð ÖÀÏ êàíàë B
; bit 14 = 1 - áóôåðèçîâàííûé âõîä Vref
; = 0 - íåáóôåðèçîâàííûé âõîä Vref
; bit 13 = 1 - 1x(Vout = Vref*D/4096)
; = 0 - 2x(Vout = 2*Vref*D/4096)
; bit 12 = 1 - àêòèâíûé ðåæèì
; = 0 - óñòðîéñòâî âûêëþ÷åíî. Vout ïðèñîåäèíåí ê ðåçèñòîðó 500 êÎì
; bit 11-0 D11:D0 áèòû äàííûõ ÖÀÏ
;
; Äëÿ MCP4921 bit 15 = 0
;
; Ïåðåä èñïîëüçîâàíèåì íåîáõîäèìî ïðîèíèöèàëèçèðîâàòü SPI
;
; Çàäàòü DAC_CS_PORT, DAC_CS_DDR, DAC_CS
;
; (C) 2017-2020 Vitaliy Zinoviev
; https://github.com/nf-zvv/IVC_Tracer_v2
;
; History
; =======
;
;------------------------------------------------------------------------------
#ifndef _MCP492X_ASM_
#define _MCP492X_ASM_
.ifndef __zero_reg__
.def __zero_reg__ = r2
.endif
.equ DAC_CS_PORT = PORTD
.equ DAC_CS_DDR = DDRD
.equ DAC_CS1 = PD6
.equ DAC_CS2 = PD4
.equ DAC_A = 0x00
.equ DAC_B = 0x80
.equ Buffer_on = 0x40
.equ Buffer_off = 0x00
.equ Gain_1X = 0x20
.equ Gain_2X = 0x00
.equ Active = 0x10
.equ Shutdown = 0x00
.dseg
DAC_CH_A: .byte 2
DAC_CH_B: .byte 2
.cseg
;------------------------------------------------------------------------------
; Èíèöèàëèçàöèÿ ÖÀÏ MCP4921
;
; Âûçîâû: DAC_SET
; Èñïîëüçóþòñÿ: r16*, r17*
; Âõîä: -
; Âûõîä: -
;------------------------------------------------------------------------------
DAC_INIT:
; íàñòðîéêà ëèíèé ââîäà/âûâîäà
sbi DAC_CS_DDR,DAC_CS1 ; DAC CS1 output
sbi DAC_CS_DDR,DAC_CS2 ; DAC CS2 output
sbi DAC_CS_PORT,DAC_CS1 ; CS1=1
sbi DAC_CS_PORT,DAC_CS2 ; CS2=1
; Óñòàíàâëèâàåì íà÷àëüíîå çíà÷åíèå ÖÀÏ
sts DAC_CH_A+0,__zero_reg__
sts DAC_CH_A+1,__zero_reg__
rcall DAC_SET_A
sts DAC_CH_B+0,__zero_reg__
sts DAC_CH_B+1,__zero_reg__
rcall DAC_SET_B
ret
;------------------------------------------------------------------------------
; Óñòàíîâêà çíà÷åíèÿ ÖÀÏ MCP4921/MCP4921
; Êàíàë A
;
; Âûçîâû: SPI_RW
; Èñïîëüçóþòñÿ: r16*
; Âõîä: DAC_A
; Âûõîä: -
;------------------------------------------------------------------------------
DAC_SET_A:
cbi DAC_CS_PORT,DAC_CS1 ; CS1=0
lds r16,DAC_CH_A+1 ; ñòàðøèé áàéò
andi r16,0b00001111 ; çàùèòà îò ïðåâûøåíèÿ çíà÷åíèÿ 4095
ori r16,(DAC_A|Buffer_on|Gain_1X|Active) ; áóôåðèçîâàííûé âõîä Vref + GAIN 1x
rcall SPI_RW
lds r16,DAC_CH_A+0 ; ìëàäøèé áàéò
rcall SPI_RW
sbi DAC_CS_PORT,DAC_CS1 ; CS1=1
ret
;------------------------------------------------------------------------------
; Óñòàíîâêà çíà÷åíèÿ ÖÀÏ MCP4922
; Êàíàë B
;
; Âûçîâû: SPI_RW
; Èñïîëüçóþòñÿ: r16*
; Âõîä: DAC_A
; Âûõîä: -
;------------------------------------------------------------------------------
DAC_SET_B:
cbi DAC_CS_PORT,DAC_CS2 ; CS2=0
lds r16,DAC_CH_B+1 ; ñòàðøèé áàéò
andi r16,0b00001111 ; çàùèòà îò ïðåâûøåíèÿ çíà÷åíèÿ 4095
ori r16,(DAC_A|Buffer_on|Gain_1X|Active) ; áóôåðèçîâàííûé âõîä Vref + GAIN 1x
rcall SPI_RW
lds r16,DAC_CH_B+0 ; ìëàäøèé áàéò
rcall SPI_RW
sbi DAC_CS_PORT,DAC_CS2 ; CS2=1
ret
#endif /* _MCP492X_ASM_ */
;------------------------------------------------------------------------------
; End of file
;------------------------------------------------------------------------------