Subversion Repositories svn.mios

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
44 tk 1
; $Id: sid_aout_ng.inc 44 2008-01-30 21:39:30Z tk $
1 tk 2
;
3
; AOUT driver for TLV5630
4
;
5
; ==========================================================================
6
;
7
;  Copyright 1998-2007 Thorsten Klose (tk@midibox.org)
8
;  Licensed for personal non-commercial use only.
9
;  All other rights reserved.
10
;
11
; ==========================================================================
12
;
13
; The pins to which the MBHP_AOUT_NG module is connected have to be defined here:
14
;
15
#define SID_AOUT_NG_LAT_CS	LATC	; The chip select pin CS#
16
#define SID_AOUT_NG_TRIS_CS	TRISC	; is connected to Port C.3
17
#define SID_AOUT_NG_PIN_CS	3	; (CANNOT be shared with other outputs!)
18
;
19
#define SID_AOUT_NG_LAT_DIN	LATC	; The data input pin DIN
20
#define SID_AOUT_NG_TRIS_DIN	TRISC	; is connected to Port C.1
21
#define SID_AOUT_NG_PIN_DIN	1	; (can be shared with other outputs)
22
;
23
#define SID_AOUT_NG_LAT_SCLK	LATC	; The shift clock input pin SCLK
24
#define SID_AOUT_NG_TRIS_SCLK	TRISC	; is connected to Port C.0
25
#define SID_AOUT_NG_PIN_SCLK	0	; (can be shared with other outputs)
26
;
27
 
28
;; --------------------------------------------------------------------------
29
;;  FUNCTION: SID_AOUT_NG_Init
30
;;  DESCRIPTION: This function initializes the TLV5630
31
;;  IN:   -
32
;;  OUT:  -
33
;;  USES: BSR
34
;; --------------------------------------------------------------------------
35
SID_AOUT_NG_Init
36
	;; enable pin drivers
37
	bcf	SID_AOUT_NG_TRIS_CS, SID_AOUT_NG_PIN_CS
38
	bcf	SID_AOUT_NG_TRIS_DIN, SID_AOUT_NG_PIN_DIN
39
	bcf	SID_AOUT_NG_TRIS_SCLK, SID_AOUT_NG_PIN_SCLK
40
 
41
	;; deactivate chip select
42
	bsf	SID_AOUT_NG_LAT_CS, SID_AOUT_NG_PIN_CS
43
 
44
	;; clear the AOUT gate pins
45
	SET_BSR	AOUT_GATE
46
	clrf	AOUT_GATE, BANKED
47
 
48
	;; set voltages to 0V
49
	lfsr	FSR0, AOUT0_L
50
	movlw	8
51
	movwf	MIOS_PARAMETER3	; used as loop counter here
52
SID_AOUT_NG_InitVoutLoop
53
	clrf	POSTINC0	; AOUTx_L
54
	clrf	POSTINC0	; AOUTx_H
55
	decfsz	MIOS_PARAMETER3, F
56
	rgoto	SID_AOUT_NG_InitVoutLoop
57
 
58
	;; update the AOUT pins
59
	rcall	SID_AOUT_NG_Update
60
 
61
	;; initialize CTRL0
62
	movlw	(1 << 3) | (3 << 1) ; DO=1 (DOUT Enable), R=3 (internal reference, 2V)
63
	movwf	TMP1
64
	movlw	0x8 << 4
65
	movwf	TMP2
66
	rcall	SID_AOUT_NG_Load2SR
67
 
68
	;; initialize CTRL1
69
	movlw	0x00
70
	movwf	TMP1
71
	movlw	0x9 << 4
72
	movwf	TMP2
73
	rcall	SID_AOUT_NG_Load2SR
74
 
75
	return
76
 
77
;; --------------------------------------------------------------------------
78
;;  FUNCTION: SID_AOUT_NG_Load2SR
79
;;  DESCRIPTION: This function loads a value into a single TLV5630
80
;;  IN:   o low byte of first SR value in TMP1
81
;;        o high byte of first SR value in TMP2
82
;;  OUT:  -
83
;;  USES: TMP[12345]
84
;; --------------------------------------------------------------------------
85
SID_AOUT_NG_Load2SR
86
        bcf	SID_AOUT_NG_LAT_SCLK, SID_AOUT_NG_PIN_SCLK	; clear clock
87
	bcf	SID_AOUT_NG_LAT_CS, SID_AOUT_NG_PIN_CS	; activate chip select
88
 
89
	;; NOTE: you will notice that the instructions are sometimes arranged
90
	;; in a special order to ensure proper output signals - for example:
91
	;; between a rising and a falling SCLK edge there is at least one
92
	;; other instruction to ensure that the high pulse of the SCLK
93
	;; is longer than 100 nS
94
 
95
	movlw	16	; init loop counter
96
	movwf	TMP5
97
SID_AOUT_NG_Load2SR_Loop
98
	bcf	SID_AOUT_NG_LAT_DIN, SID_AOUT_NG_PIN_DIN	; set DIN depending on current MSB
99
	btfsc	TMP2, 7
100
	bsf	SID_AOUT_NG_LAT_DIN, SID_AOUT_NG_PIN_DIN
101
	rlf	TMP1, F				; start to shift the 32-bit value
102
	bsf	SID_AOUT_NG_LAT_SCLK, SID_AOUT_NG_PIN_SCLK	; rising clock edge
103
	rlf	TMP2, F				; second step for the 32-bit shift
104
	bcf	SID_AOUT_NG_LAT_SCLK, SID_AOUT_NG_PIN_SCLK	; falling clock edge
105
	decfsz	TMP5, F				; loop 16 times
106
	rgoto	SID_AOUT_NG_Load2SR_Loop
107
 
108
	bsf	SID_AOUT_NG_LAT_CS, SID_AOUT_NG_PIN_CS; deactivate chip select
109
 
110
	return
111
 
112
 
113
;; --------------------------------------------------------------------------
114
;;  FUNCTION: SID_AOUT_NG_Update
115
;;  DESCRIPTION: refreshes the AOUT pins if AOUT values have been changed
116
;;  OUT:  -
117
;;  USES: TMP[12345] and MIOS_PARAMETER[123]
118
;; --------------------------------------------------------------------------
119
SID_AOUT_NG_Update
120
	lfsr	FSR0, AOUT0_L
121
	clrf	MIOS_PARAMETER1		; used as loop counter here
122
					; counts: 0x00, 0x10, 0x20, .., 0x70 (optimization for code below)
123
	movff	SID_LOCAL_ENS+SID_ENSx_AOUT_INVERTED, MIOS_PARAMETER3	; inversion flags for all 8 AOUTs
124
SID_AOUT_NG_Update_Loop
125
	IRQ_DISABLE			; disable interrupts to ensure data consistency
126
 
127
	;; commands to load and update the DAC register:
128
	;; bit [15] = 0, bit [14:12] channel number, bit [11:0] DAC value
129
	movf	POSTINC0, W		; transfer low/high byte of first SR to TMP[12]
130
	btfsc	MIOS_PARAMETER3, 0; invert if inversion flag is set
131
	xorlw 0xff
132
	movwf	TMP1
133
	movf	INDF0, W
134
	andlw	0x0f
135
	btfsc	MIOS_PARAMETER3, 0; invert if inversion flag is set
136
	xorlw 0x0f
137
	iorwf	MIOS_PARAMETER1, W
138
	movwf	TMP2
139
 
140
	;; load SR if AOUT value has been changed
141
	BRA_IFSET INDF0, 7, ACCESS, SID_AOUT_NG_Update_Loop_Next
142
 
143
	IRQ_ENABLE			; enable interrupts
144
 
145
	rcall	SID_AOUT_NG_Load2SR
146
 
147
	;; notify that upload has been done
148
	bsf	INDF0, 7
149
 
150
SID_AOUT_NG_Update_Loop_Next
151
	IRQ_ENABLE			; enable interrupts
152
	;; increment to next low bytes
153
	movf	POSTINC0, W
154
	;; shiftright inversion flags
155
	rrf	MIOS_PARAMETER3, F
156
	;; increment 0x10 to loop counter until it reaches 0x80
157
	movlw	0x10
158
	addwf	MIOS_PARAMETER1, F
159
	BRA_IFCLR MIOS_PARAMETER1, 7, ACCESS, SID_AOUT_NG_Update_Loop
160
 
161
SID_AOUT_NG_Update_Gates
162
	;; do nothing if gate bits have not been changed
163
	SET_BSR	AOUT_GATE
164
	movf	AOUT_GATE, W, BANKED
165
	xorwf	AOUT_GATE_SHADOW, W, BANKED
166
	bz	SID_AOUT_NG_UpdateGates_End
167
 
168
	IRQ_DISABLE			; disable interrupts to ensure data consistency
169
 
170
	;; optionally forward to DOUT
171
#if DEFAULT_EXT_SWITCH_DOUT
172
	movff	AOUT_GATE, MIOS_PARAMETER1
173
	movlw	(DEFAULT_EXT_SWITCH_DOUT-1) & 0x0f
174
	call	MIOS_DOUT_SRSet
175
#endif
176
 
177
	;; optionally forward to J5
178
	SET_BSR	AOUT_GATE
179
#if DEFAULT_J5_FUNCTION == 3
180
	movf	AOUT_GATE, W, BANKED
181
	call	J5_DOUT_Set
182
#endif
183
 
184
	;; update shadow register
185
	movf	AOUT_GATE, W, BANKED
186
	movwf	AOUT_GATE_SHADOW, BANKED
187
	IRQ_ENABLE			; enable interrupts
188
 
189
SID_AOUT_NG_UpdateGates_End
190
SID_AOUT_NG_Update_End
191
 
192
	return