Subversion Repositories svn.mios

Rev

Rev 146 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 146 Rev 285
Line 1... Line 1...
1
; $Id: aout_74hc595.inc 146 2008-03-01 00:04:43Z tk $
1
; $Id: aout_74hc595.inc 285 2008-04-23 20:31:07Z tk $
2
;
2
;
3
; AOUT driver for 74HC595 based DAC (-> MBHP_AOUT_LC module)
3
; AOUT driver for 74HC595 based DAC (-> MBHP_AOUT_LC module)
4
; 
4
; 
5
; See aout.inc for description of the available functions
5
; See aout.inc for description of the available functions
6
;
6
;
Line 10... Line 10...
10
;  Licensed for personal non-commercial use only.
10
;  Licensed for personal non-commercial use only.
11
;  All other rights reserved.
11
;  All other rights reserved.
12
; 
12
; 
13
; ==========================================================================
13
; ==========================================================================
14
;
14
;
15
; Special Option for AOUT_LC module: select either 12/4 bit (0), or 8/8 bit (1) configuration
15
; Special Option for AOUT_LC module: select either 12/4 bit (0), or 8/8 bit (1),
-
 
16
; or 12/12/8 (2) configuration
16
; this has to be done for each module seperately
17
; this has to be done for each module seperately
-
 
18
;
-
 
19
; Note: the 12/12/8 bit selection (2) combines 4 shift registers. The first two SRs
-
 
20
; are working like option 0 (first channel: 12bit, second channel: upper 4bit)
-
 
21
; The third SR outputs the lower bits of second channel, and the fourth SR the
-
 
22
; 8bit value of third channel. The fourth channel is ignored
-
 
23
; (same for channel 4-7... channel 8 ignored)
-
 
24
; For this "combined" option, it is recommented, to set both modes (M1,M2 and/or M3,M4)
-
 
25
; to value 2 for future compatibilty
17
#ifndef AOUT_LC_RESOLUTION_OPTION_M1
26
#ifndef AOUT_LC_RESOLUTION_OPTION_M1
18
#define AOUT_LC_RESOLUTION_OPTION_M1 0
27
#define AOUT_LC_RESOLUTION_OPTION_M1 0
19
#endif
28
#endif
20
#ifndef AOUT_LC_RESOLUTION_OPTION_M2
29
#ifndef AOUT_LC_RESOLUTION_OPTION_M2
21
#define AOUT_LC_RESOLUTION_OPTION_M2 0
30
#define AOUT_LC_RESOLUTION_OPTION_M2 0
Line 63... Line 72...
63
72
64
        bcf	AOUT_LAT_SCLK, AOUT_PIN_SCLK	; ensure that clock starts at low level
73
        bcf	AOUT_LAT_SCLK, AOUT_PIN_SCLK	; ensure that clock starts at low level
65
74
66
	;; update all channels
75
	;; update all channels
67
	SET_BSR	AOUT_INVERTED
76
	SET_BSR	AOUT_INVERTED
-
 
77

68

78
69
	;; 4th AOUT_LC module
79
	;; 4th AOUT_LC module
-
 
80
#if AOUT_LC_RESOLUTION_OPTION_M4 == 2
-
 
81
	lfsr	FSR1, AOUT_VALUES + 3*4-2	; pointer to values in FSR1
-
 
82
	swapf	AOUT_INVERTED, W, BANKED	; inversion flags in MIOS_PARAMETER3[1:0]
-
 
83
	rrf	WREG, W
-
 
84
#else
70
	lfsr	FSR1, AOUT_VALUES + 3*4		; pointer to values in FSR1
85
	lfsr	FSR1, AOUT_VALUES + 3*4		; pointer to values in FSR1
71
	swapf	AOUT_INVERTED, W, BANKED	; inversion flags in MIOS_PARAMETER3[1:0]
86
	swapf	AOUT_INVERTED, W, BANKED	; inversion flags in MIOS_PARAMETER3[1:0]
72
	rrf	WREG, W
87
	rrf	WREG, W
73
	rrf	WREG, W
88
	rrf	WREG, W
74
	andlw	0x03
89
#endif
75
	movwf	MIOS_PARAMETER3
90
	movwf	MIOS_PARAMETER3
76
#if AOUT_LC_RESOLUTION_OPTION_M4
91
#if AOUT_LC_RESOLUTION_OPTION_M4 == 0
77
	rcall	AOUT_Update_Hlp_12_4
92
	rcall	AOUT_Update_Hlp_12_4
78
#else
93
#endif
-
 
94
#if AOUT_LC_RESOLUTION_OPTION_M4 == 1
79
	rcall	AOUT_Update_Hlp_8_8
95
	rcall	AOUT_Update_Hlp_8_8
-
 
96
#endif
-
 
97
#if AOUT_LC_RESOLUTION_OPTION_M4 == 2
-
 
98
	rcall	AOUT_Update_Hlp_12_12_8
80
#endif
99
#endif
81
100
82
	;; 3rd AOUT_LC module
101
	;; 3rd AOUT_LC module
83
	lfsr	FSR1, AOUT_VALUES + 2*4		; pointer to values in FSR1
102
	lfsr	FSR1, AOUT_VALUES + 2*4		; pointer to values in FSR1
84
	swapf	AOUT_INVERTED, W, BANKED	; inversion flags in MIOS_PARAMETER3[1:0]
103
	swapf	AOUT_INVERTED, W, BANKED	; inversion flags in MIOS_PARAMETER3[1:0]
85
	andlw	0x03
-
 
86
	movwf	MIOS_PARAMETER3
104
	movwf	MIOS_PARAMETER3
87
#if AOUT_LC_RESOLUTION_OPTION_M3
105
#if AOUT_LC_RESOLUTION_OPTION_M3 == 1
88
	rcall	AOUT_Update_Hlp_12_4
106
	rcall	AOUT_Update_Hlp_8_8		; used for 8/8 resolution
89
#else
107
#else
90
	rcall	AOUT_Update_Hlp_8_8
108
	rcall	AOUT_Update_Hlp_12_4		; used for 12/4 and 12/12/8 resolution
91
#endif
109
#endif
-
 
110

92
111
93
	;; 2nd AOUT_LC module
112
	;; 2nd AOUT_LC module
-
 
113
#if AOUT_LC_RESOLUTION_OPTION_M2 == 2
-
 
114
	lfsr	FSR1, AOUT_VALUES + 1*4-2	; pointer to values in FSR1
-
 
115
	rrf	AOUT_INVERTED, W, BANKED	; inversion flags in MIOS_PARAMETER3[1:0]
-
 
116
#else
94
	lfsr	FSR1, AOUT_VALUES + 1*4		; pointer to values in FSR1
117
	lfsr	FSR1, AOUT_VALUES + 1*4		; pointer to values in FSR1
95
	rrf	AOUT_INVERTED, W, BANKED	; inversion flags in MIOS_PARAMETER3[1:0]
118
	rrf	AOUT_INVERTED, W, BANKED	; inversion flags in MIOS_PARAMETER3[1:0]
96
	rrf	WREG, W
119
	rrf	WREG, W
97
	andlw	0x03
120
#endif
98
	movwf	MIOS_PARAMETER3
121
	movwf	MIOS_PARAMETER3
99
#if AOUT_LC_RESOLUTION_OPTION_M2
122
#if AOUT_LC_RESOLUTION_OPTION_M2 == 0
100
	rcall	AOUT_Update_Hlp_12_4
123
	rcall	AOUT_Update_Hlp_12_4
101
#else
124
#endif
-
 
125
#if AOUT_LC_RESOLUTION_OPTION_M2 == 1
102
	rcall	AOUT_Update_Hlp_8_8
126
	rcall	AOUT_Update_Hlp_8_8
-
 
127
#endif
-
 
128
#if AOUT_LC_RESOLUTION_OPTION_M2 == 2
-
 
129
	rcall	AOUT_Update_Hlp_12_12_8
103
#endif
130
#endif
104
131
105
	;; 1st AOUT_LC module
132
	;; 1st AOUT_LC module
106
	lfsr	FSR1, AOUT_VALUES + 0*4		; pointer to values in FSR1
133
	lfsr	FSR1, AOUT_VALUES + 0*4		; pointer to values in FSR1
107
	movf	AOUT_INVERTED, W, BANKED	; inversion flags in MIOS_PARAMETER3[1:0]
134
	movf	AOUT_INVERTED, W, BANKED	; inversion flags in MIOS_PARAMETER3[1:0]
108
	andlw	0x03
-
 
109
	movwf	MIOS_PARAMETER3
135
	movwf	MIOS_PARAMETER3
110
#if AOUT_LC_RESOLUTION_OPTION_M1
136
#if AOUT_LC_RESOLUTION_OPTION_M1 == 1
111
	rcall	AOUT_Update_Hlp_12_4
137
	rcall	AOUT_Update_Hlp_8_8		; used for 8/8 resolution
112
#else
138
#else
113
	rcall	AOUT_Update_Hlp_8_8
139
	rcall	AOUT_Update_Hlp_12_4		; used for 12/4 and 12/12/8 resolution
114
#endif
140
#endif
-
 
141

115
142
116
	;; CS line used as RCLK by AOUT_LC module
143
	;; CS line used as RCLK by AOUT_LC module
117
	bsf	AOUT_LAT_CS, AOUT_PIN_CS	; trigger RCLK to update chain
144
	bsf	AOUT_LAT_CS, AOUT_PIN_CS	; trigger RCLK to update chain
118
	nop	
145
	nop	
119
	bcf	AOUT_LAT_CS, AOUT_PIN_CS
146
	bcf	AOUT_LAT_CS, AOUT_PIN_CS
Line 125... Line 152...
125
152
126
	return
153
	return
127

154

128
;; help function to update a single AOUT_LC module
155
;; help function to update a single AOUT_LC module
129
AOUT_Update_Hlp_12_4
156
AOUT_Update_Hlp_12_4
-
 
157
#if AOUT_LC_RESOLUTION_OPTION_M1 != 1 || AOUT_LC_RESOLUTION_OPTION_M2 != 1 || AOUT_LC_RESOLUTION_OPTION_M3 != 1 || AOUT_LC_RESOLUTION_OPTION_M4 != 1
130
	;; map 2 * 16 bit to 12/4 bit
158
	;; map 2 * 16 bit to 12/4 bit
131
	movlw	1				; first channel: 12bit
159
	movlw	1				; first channel: 12bit
132
	movf	PLUSW1, W			; high-byte -> MIOS_PARAMETER1
160
	movf	PLUSW1, W			; high-byte -> MIOS_PARAMETER1
133
	btfsc	MIOS_PARAMETER3, 0		; inversion?
161
	btfsc	MIOS_PARAMETER3, 0		; inversion?
134
	xorlw	0xff
162
	xorlw	0xff
Line 144... Line 172...
144
	andlw	0x0f
172
	andlw	0x0f
145
	btfsc	MIOS_PARAMETER3, 1		; inversion?
173
	btfsc	MIOS_PARAMETER3, 1		; inversion?
146
	xorlw	0x0f
174
	xorlw	0x0f
147
	iorwf	MIOS_PARAMETER2, F
175
	iorwf	MIOS_PARAMETER2, F
148
	rgoto	AOUT_LoadWord
176
	rgoto	AOUT_LoadWord
-
 
177
#else
-
 
178
	return					; neither 12/4, nor 12/12/4 option used - save memory
-
 
179
#endif
-
 
180

-
 
181
149
182
150
AOUT_Update_Hlp_8_8
183
AOUT_Update_Hlp_8_8
-
 
184
#if AOUT_LC_RESOLUTION_OPTION_M1 == 1 || AOUT_LC_RESOLUTION_OPTION_M2 == 1 || AOUT_LC_RESOLUTION_OPTION_M3 == 1 || AOUT_LC_RESOLUTION_OPTION_M4 == 1
151
	;; map 2 * 16 bit to 8/8 bit
185
	;; map 2 * 16 bit to 8/8 bit
152
	movlw	1				; first channel: 8bit
186
	movlw	1				; first channel: 8bit
153
	movf	PLUSW1, W			; high-byte -> MIOS_PARAMETER1
187
	movf	PLUSW1, W			; high-byte -> MIOS_PARAMETER1
154
	btfsc	MIOS_PARAMETER3, 0		; inversion?
188
	btfsc	MIOS_PARAMETER3, 0		; inversion?
155
	xorlw	0xff
189
	xorlw	0xff
Line 159... Line 193...
159
	movf	PLUSW1, W			; high-byte -> MIOS_PARAMETER2
193
	movf	PLUSW1, W			; high-byte -> MIOS_PARAMETER2
160
	btfsc	MIOS_PARAMETER3, 1		; inversion?
194
	btfsc	MIOS_PARAMETER3, 1		; inversion?
161
	xorlw	0xff
195
	xorlw	0xff
162
	movwf	MIOS_PARAMETER2
196
	movwf	MIOS_PARAMETER2
163
	rgoto	AOUT_LoadWord
197
	rgoto	AOUT_LoadWord
-
 
198
#else
-
 
199
	return					; 8/8 option not used - save memory
-
 
200
#endif
164
201

-
 
202
-
 
203
	
-
 
204
AOUT_Update_Hlp_12_12_8
-
 
205
#if AOUT_LC_RESOLUTION_OPTION_M1 == 2 || AOUT_LC_RESOLUTION_OPTION_M2 == 2 || AOUT_LC_RESOLUTION_OPTION_M3 == 2 || AOUT_LC_RESOLUTION_OPTION_M4 == 2
-
 
206
	;; first channel, and upper bits of second channel already uploaded via 12_4 function
-
 
207
	;; now we have to upload the lower bits of the second channel + 8 bits of the third channel
-
 
208
	;; the fourth channel is ignored
-
 
209
	movlw	1				; second: lower 8bit
-
 
210
	swapf	PLUSW1, W			; [3:0] of high-byte -> MIOS_PARAMETER1[7:4]
-
 
211
	btfsc	MIOS_PARAMETER3, 0		; inversion?
-
 
212
	xorlw	0xf0
-
 
213
	andlw	0xf0
-
 
214
	movwf	MIOS_PARAMETER1
-
 
215
	swapf	INDF1, W			; [7:4] of low-byte -> MIOS_PARAMETER1[3:0]
-
 
216
	andlw	0x0f
-
 
217
	btfsc	MIOS_PARAMETER3, 0		; inversion?
-
 
218
	xorlw	0x0f
-
 
219
	iorwf	MIOS_PARAMETER1, F
-
 
220
-
 
221
	movlw	3				; third channel: 8bit
-
 
222
	movf	PLUSW1, W			; high-byte -> MIOS_PARAMETER2
-
 
223
	btfsc	MIOS_PARAMETER3, 1		; inversion?
-
 
224
	xorlw	0xff
-
 
225
	movwf	MIOS_PARAMETER2
-
 
226
	rgoto	AOUT_LoadWord
-
 
227
#else
-
 
228
	return					; 12/12/8 option not used - save memory
-
 
229
#endif
165
230

166
231
167
;; --------------------------------------------------------------------------
232
;; --------------------------------------------------------------------------
168
;;  Internal function to load a 16bit value into two 74HC595
233
;;  Internal function to load a 16bit value into two 74HC595
169
;;  IN: word in MIOS_PARAMETER[12]
234
;;  IN: word in MIOS_PARAMETER[12]