Subversion Repositories svn.mios

Rev

Rev 52 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
53 tk 1
; $Id: mios_ain.inc 53 2008-01-30 22:52:41Z tk $
1 tk 2
;
3
; MIOS AIN Handler
4
;
5
; ==========================================================================
6
;
7
;  Copyright 1998-2006 Thorsten Klose (tk@midibox.org)
8
;  Licensed for personal non-commercial use only.
9
;  All other rights reserved.
10
;
11
; ==========================================================================
12
 
13
;; ADC MUX Pins
14
MIOS_AIN_LAT_MUX_0       EQU     LATC   ; Pin C.0
15
MIOS_AIN_PIN_MUX_0       EQU     0
16
MIOS_AIN_LAT_MUX_1       EQU     LATC   ; Pin C.1
17
MIOS_AIN_PIN_MUX_1       EQU     1
18
MIOS_AIN_LAT_MUX_2       EQU     LATC   ; Pin C.3
19
MIOS_AIN_PIN_MUX_2       EQU     3
20
 
21
;; AIN flags
22
MIOS_AIN_CTRL_DYNPRIO_DISABLE EQU 0
23
MIOS_AIN_CTRL_DYNPRIO_ACTIVE  EQU 1
24
MIOS_AIN_CTRL_DYNPRIO_POT     EQU 2
25
 
26
MIOS_AIN_CTRL_STATE	EQU	3
27
MIOS_AIN_CTRL_MF	EQU	6
28
MIOS_AIN_CTRL_MUXED	EQU	7
29
 
30
 
31
;; --------------------------------------------------------------------------
32
;;  FUNCTION: USER_AIN_NotifyChange
33
;;  C_DECLARATION: void AIN_NotifyChange(unsigned char pin, unsigned int pin_value)
34
;;  DESCRIPTION: This function is called by MIOS when a pot has been moved
35
;;  IN: Pot number in WREG and MIOS_PARAMETER1
36
;;      LSB value in MIOS_PARAMETER2
37
;;      MSB value in MIOS_PARAMETER3
38
;;  C_IN: Pot number in <pin>
39
;;      10bit value in <pin_value>
40
;;  OUT:  -
41
;;  ISR: no
42
;; --------------------------------------------------------------------------
43
 
44
;; --------------------------------------------------------------------------
45
;;  FUNCTION: MIOS_AIN_Muxed
46
;;  C_DECLARATION: void MIOS_AIN_Muxed(void)
47
;;  DESCRIPTION: enables the MUX mode (up to 64 pots can be connected via
48
;;  AIN multiplexers
49
;;  IN:	  -
50
;;  C_IN:  -
51
;;  OUT:  -
52
;;  C_OUT:  -
53
;;  USES: BSR
54
;; --------------------------------------------------------------------------
55
MIOS_AIN_Muxed
56
	SET_BSR	MIOS_AIN_CTRL
57
	bsf	MIOS_AIN_CTRL, MIOS_AIN_CTRL_MUXED, BANKED
58
	return
59
 
60
;; --------------------------------------------------------------------------
61
;;  FUNCTION: MIOS_AIN_UnMuxed
62
;;  C_DECLARATION: void MIOS_AIN_UnMuxed(void)
63
;;  DESCRIPTION: disables the MUX mode (8 pots can be connected directly
64
;;  to the analog input pins of the PIC
65
;;  IN:	  -
66
;;  C_IN: -
67
;;  OUT:  -
68
;;  C_OUT:  -
69
;;  USES: BSR
70
;; --------------------------------------------------------------------------
71
MIOS_AIN_UnMuxed
72
	SET_BSR	MIOS_AIN_CTRL
73
	bcf	MIOS_AIN_CTRL, MIOS_AIN_CTRL_MUXED, BANKED
74
	return
75
 
76
 
77
;; --------------------------------------------------------------------------
78
;;  FUNCTION: MIOS_AIN_Pin7bitGet
79
;;  C_DECLARATION: unsigned char MIOS_AIN_Pin7bitGet(unsigned char pin)
80
;;  DESCRIPTION: returns 7-bit value of AIN input
81
;;  IN:	  number of analog input pin in WREG
82
;;  C_IN: number of analog input pin in <pin>
83
;;  OUT:  7-bit value in MIOS_PARAMETER1 and WREG
84
;;  C_OUT: 7-bit value
85
;;  USES: BSR, FSR1, MIOS_PARAMETER[12]
86
;; --------------------------------------------------------------------------
87
MIOS_AIN_Pin7bitGet
88
	andlw	0x3f
89
	lfsr	FSR1, MIOS_AIN_RESULT_L_00
90
	addwf	FSR1L, F
91
	movff	INDF1, MIOS_PARAMETER1
92
	bsf	FSR1L, 6
93
	movff	INDF1, MIOS_PARAMETER2
94
 
95
	;; note: a multiplication would work faster, but would overwrite PRODL/PRODH
96
	rrf	MIOS_PARAMETER2, F
97
	rrf	MIOS_PARAMETER1, F
98
	rrf	MIOS_PARAMETER2, F
99
	rrf	MIOS_PARAMETER1, F
100
	rrf	MIOS_PARAMETER1, W
101
	andlw	0x7f
102
	movwf	MIOS_PARAMETER1
103
	return
104
 
105
;; --------------------------------------------------------------------------
106
;;  FUNCTION: MIOS_AIN_PinMSBGet
107
;;  C_DECLARATION: unsigned char MIOS_AIN_PinMSBGet(unsigned char pin)
108
;;  DESCRIPTION: returns MSB value of AIN input
109
;;  IN:	  pin number in WREG
110
;;  C_IN: pin number in <pin>
111
;;  OUT:  MSB value in MIOS_PARAMETER1 and WREG
112
;;  C_OUT: MSB value
113
;;  USES: FSR1
114
;; --------------------------------------------------------------------------
115
MIOS_AIN_PinMSBGet
116
	andlw	0x3f
117
	lfsr	FSR1, MIOS_AIN_RESULT_H_00
118
	addwf	FSR1L, F
119
	movf	INDF1, W
120
	andlw	0x03
121
	movwf	MIOS_PARAMETER1
122
	return
123
 
124
;; --------------------------------------------------------------------------
125
;;  FUNCTION: MIOS_AIN_PinLSBGet
126
;;  C_DECLARATION: unsigned char MIOS_AIN_PinLSBGet(unsigned char pin)
127
;;  DESCRIPTION: returns LSB value of AIN input
128
;;  IN:	  pin number in WREG
129
;;  C_IN: pin number in <pin>
130
;;  OUT:  LSB value in MIOS_PARAMETER1 and WREG
131
;;  C_OUT: LSB value
132
;;  USES: FSR1
133
;; --------------------------------------------------------------------------
134
MIOS_AIN_PinLSBGet
135
	andlw	0x3f
136
	lfsr	FSR1, MIOS_AIN_RESULT_L_00
137
	addwf	FSR1L, F
138
	movf	INDF1, W
139
	movwf	MIOS_PARAMETER1
140
	return
141
 
142
;; --------------------------------------------------------------------------
143
;;  FUNCTION: MIOS_AIN_PinGet
144
;;  C_DECLARATION: unsigned int MIOS_AIN_PinGet(unsigned char pin)
145
;;  DESCRIPTION: returns value of AIN input
146
;;  IN:	  pin number in WREG
147
;;  C_IN: pin number in <pin>
148
;;  OUT:  MSB in MIOS_PARAMETER2, LSB in MIOS_PARAMETER1 and WREG
149
;;  C_OUT: 10bit value
150
;;  USES: FSR1
151
;; --------------------------------------------------------------------------
152
MIOS_AIN_PinGet
153
	andlw	0x3f
154
	lfsr	FSR1, MIOS_AIN_RESULT_H_00
155
	addwf	FSR1L, F
156
	movf	INDF1, W
157
	andlw	0x03
158
	movwf	MIOS_PARAMETER2
159
	bcf	FSR1L, 6
160
	movf	INDF1, W
161
	movwf	MIOS_PARAMETER1
162
	return
163
 
164
;; --------------------------------------------------------------------------
165
;;  FUNCTION: MIOS_AIN_NumberSet
166
;;  C_DECLARATION: void MIOS_AIN_NumberSet(unsigned char pots)
167
;;  DESCRIPTION: sets number of available AIN pins<BR>
168
;;  If number > 64, value will be forced to 64
169
;;  IN:	  number of analog pins in WREG
170
;;  C_IN: number of analog pins in <pots>
171
;;  OUT:  -
172
;;  C_OUT:  -
173
;;  USES: BSR
174
;; --------------------------------------------------------------------------
175
MIOS_AIN_NumberSet
176
	;; clear input counter
177
	SET_BSR	MIOS_AIN_INPUT_CTR
178
	clrf	MIOS_AIN_INPUT_CTR, BANKED
179
 
180
	;; write number of pots into MIOS_AIN_NUMBER register. Ensure that not more than 64 pots are active
181
	movwf	MIOS_AIN_NUMBER, BANKED
182
	andlw	0xc0
183
	skpnz
184
	rgoto	MIOS_AIN_NumberSet_Cont
185
	movlw	0x40
186
	movwf	MIOS_AIN_NUMBER, BANKED
187
MIOS_AIN_NumberSet_Cont
188
 
189
	;; if MF module enabled, ensure that max. 8 faders are active
190
	BRA_IFCLR MIOS_AIN_CTRL, MIOS_AIN_CTRL_MF, BANKED, MIOS_AIN_NumberSet_NoMF
191
MIOS_AIN_NumberSet_MF
192
	movlw	0x08
193
	cpfsgt	MIOS_AIN_NUMBER, BANKED
194
	rgoto MIOS_AIN_NumberSet_MFOk
195
	movwf	MIOS_AIN_NUMBER, BANKED
196
MIOS_AIN_NumberSet_MFOk
197
MIOS_AIN_NumberSet_NoMF
198
 
199
	;; enable timer0 and IRQ. If number of pots is zero, timer will disable itself
200
	bsf	INTCON, T0IE
201
	bsf	T0CON, TMR0ON
202
	return
203
 
204
;; --------------------------------------------------------------------------
205
;;  FUNCTION: MIOS_AIN_NumberGet
206
;;  C_DECLARATION: unsigned char MIOS_AIN_NumberGet(void)
207
;;  DESCRIPTION: returns number of available analog pins
208
;;  IN:	  -
209
;;  C_IN:	  -
210
;;  OUT:  number of analog pins in MIOS_PARAMETER1 and WREG
211
;;  C_OUT:  number of analog pins
212
;;  USES: BSR
213
;; --------------------------------------------------------------------------
214
MIOS_AIN_NumberGet
215
	SET_BSR	MIOS_AIN_NUMBER
216
	movf	MIOS_AIN_NUMBER, W, BANKED
217
	movwf	MIOS_PARAMETER1
218
	return
219
 
220
;; --------------------------------------------------------------------------
221
;;  FUNCTION: MIOS_AIN_DeadbandSet
222
;;  C_DECLARATION: void MIOS_AIN_DeadbandSet(unsigned char deadband)
223
;;  DESCRIPTION: sets the difference between last and current pot value
224
;;  which has to be achieved to trigger the "NotifyChange" function
225
;;  IN:	  deadband value in WREG
226
;;  C_IN: deadband value in <deadband>
227
;;  OUT:  -
228
;;  C_OUT:  -
229
;;  USES: BSR
230
;; --------------------------------------------------------------------------
231
MIOS_AIN_DeadbandSet
232
	SET_BSR	MIOS_AIN_DEADBAND
233
	movwf	MIOS_AIN_DEADBAND, BANKED
234
	return
235
 
236
;; --------------------------------------------------------------------------
237
;;  FUNCTION: MIOS_AIN_DeadbandGet
238
;;  C_DECLARATION: unsigned char MIOS_AIN_DeadbandGet(void)
239
;;  DESCRIPTION: returns the difference between last and current pot
240
;;  value which has to be achieved to trigger the "NotifyChange" function
241
;;  IN:	  -
242
;;  C_IN:  -
243
;;  OUT:  diff value in MIOS_PARAMETER1 and WREG
244
;;  C_OUT:  diff value
245
;;  USES: BSR
246
;; --------------------------------------------------------------------------
247
MIOS_AIN_DeadbandGet
248
	SET_BSR	MIOS_AIN_DEADBAND
249
	movf	MIOS_AIN_DEADBAND, W, BANKED
250
	movwf	MIOS_PARAMETER1
251
	return
252
 
253
 
254
;; --------------------------------------------------------------------------
255
;;  FUNCTION: MIOS_AIN_DynamicPrioSet
256
;;  C_DECLARATION: void MIOS_AIN_DynamicPrioSet(unsigned char enable)
257
;;  DESCRIPTION: enables or disables the dynamic priority sampling feature.
258
;;  The flag will only be taken into account in multiplexed mode (more than 8
259
;;  pots connected to the core module via AINX4). If active, the sampling
260
;;  frequency of the two last turned pots will be dynamically increased
261
;;  for a better accuracy.
262
;;  IN:	  WREG = 0x00: dynamic priority sampling disabled
263
;;        WREG = 0x01: dynamic priority sampling enabled (default)
264
;;  C_IN: 0x00: dynamic priority sampling disabled
265
;;        0x01: dynamic priority sampling enabled (default)
266
;;  OUT:  -
267
;;  C_OUT:  -
268
;;  USES: BSR
269
;; --------------------------------------------------------------------------
270
MIOS_AIN_DynamicPrioSet
271
	SET_BSR	MIOS_AIN_CTRL
272
	bsf	MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_DISABLE, BANKED
273
	btfsc	WREG, 0
274
	bcf	MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_DISABLE, BANKED
275
	return
276
 
277
;; --------------------------------------------------------------------------
278
;;  FUNCTION: MIOS_AIN_DynamicPrioGet
279
;;  C_DECLARATION: unsigned char MIOS_AIN_DynamicPrioGet(void)
280
;;  DESCRIPTION: returns the status of the dynamic priority sampling feature.
281
;;  The flag will only be taken into account in multiplexed mode (more than 8
282
;;  pots connected to the core module via AINX4). If active, the sampling
283
;;  frequency of the two last turned pots will be dynamically increased
284
;;  for a better accuracy.
285
;;  IN:   -
286
;;  C_IN:  -
287
;;  OUT:  WREG = 0x00: dynamic priority sampling disabled or non-multiplexed mode active
288
;;        WREG = 0x01: dynamic priority sampling enabled (default)
289
;;  C_OUT:  0x00: dynamic priority sampling disabled or non-multiplexed mode active
290
;;        0x01: dynamic priority sampling enabled (default)
291
;;  USES: BSR
292
;; --------------------------------------------------------------------------
293
MIOS_AIN_DynamicPrioGet
294
	SET_BSR	MIOS_AIN_CTRL
295
	movlw	0x00
296
	btfss	MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_DISABLE, BANKED
297
	movlw	0x01
298
	andlw	0xff		; fix STATUS
299
	return
300
 
301
;; --------------------------------------------------------------------------
302
;;  FUNCTION: MIOS_AIN_LastPinsGet
303
;;  C_DECLARATION: unsigned char MIOS_AIN_LastPinsGet(void)
304
;;  DESCRIPTION: returns the index of the two pins which have been
305
;;  sampled with a different value at last.<BR>
306
;;  In less abstract words: returns the number of the last two turned pots.
307
;;  IN:   -
308
;;  C_IN:   -
309
;;  OUT:  WREG and MIOS_PARAMETER1: last pin
310
;;        MIOS_PARAMETER2: last but one pin
311
;;  C_OUT:  returned value and MIOS_PARAMETER1: last pin
312
;;        MIOS_PARAMETER2: last but one pin
313
;;  USES: BSR
314
;; --------------------------------------------------------------------------
315
MIOS_AIN_LastPinsGet
316
	SET_BSR	MIOS_AIN_LAST_POT0
317
	movff	MIOS_AIN_LAST_POT1, MIOS_PARAMETER2
318
	movf	MIOS_AIN_LAST_POT0, W, BANKED
319
	movwf	MIOS_PARAMETER1
320
	return
321
 
322
;; --------------------------------------------------------------------------
323
;;  MIOS AIN Handler
324
;;  check changed AIN pins, call USER_AIN_NotifyChange when conversion result
325
;;  of AIN pin has been changed
326
;; --------------------------------------------------------------------------
327
MIOS_AIN_Handler
328
	SET_BSR	MIOS_TMP_CTR
329
	clrf	MIOS_TMP_CTR, BANKED
330
 
331
	movf	MIOS_AIN_NUMBER, W, BANKED
332
	skpnz
333
	return
334
 
335
	lfsr	FSR0, MIOS_AIN_RESULT_H_00
336
	movf	MIOS_TMP_CTR, W, BANKED
337
MIOS_AIN_Handler_Loop
338
	BRA_IFCLR PLUSW0, 7, ACCESS, MIOS_AIN_Handler_Loop_Next
339
	bcf	PLUSW0, 7
340
 
341
	movff	PLUSW0, MIOS_PARAMETER3
342
	bcf	FSR0L, 6
343
	movff	PLUSW0, MIOS_PARAMETER2
344
	;; call hook
345
	movwf	MIOS_PARAMETER1
346
	CALL_IFCLR MIOS_BOX_STAT, MIOS_BOX_STAT_SUSPEND_USER, ACCESS, USER_AIN_NotifyChange
347
 
348
	lfsr	FSR0, MIOS_AIN_RESULT_H_00
349
	SET_BSR	MIOS_TMP_CTR
350
MIOS_AIN_Handler_Loop_Next
351
	incf	MIOS_TMP_CTR, F, BANKED
352
	movf	MIOS_TMP_CTR, W, BANKED
353
	cpfseq	MIOS_AIN_NUMBER, BANKED
354
	rgoto MIOS_AIN_Handler_Loop
355
	return
356
 
357
 
358
;; --------------------------------------------------------------------------
359
;;  MIOS AIN Tick
360
;;  called by timer0 interrupt every 100 us
361
;; --------------------------------------------------------------------------
362
MIOS_AIN_Tick
363
	SET_BSR	MIOS_AIN_CTRL			; branch depending on state
364
	BRA_IFSET MIOS_AIN_CTRL, MIOS_AIN_CTRL_STATE, BANKED, MIOS_AIN_Tick_State1
365
 
366
	;; STATE0: start conversion
367
MIOS_AIN_Tick_State0
368
	bsf	MIOS_AIN_CTRL, MIOS_AIN_CTRL_STATE, BANKED	; set next state
369
	bsf	ADCON0, GO					; do a dummy conversion
370
	rgoto	MIOS_AIN_Tick_End
371
 
372
	;; STATE1: get result and set multiplexers for next input
373
MIOS_AIN_Tick_State1
374
	bcf	MIOS_AIN_CTRL, MIOS_AIN_CTRL_STATE, BANKED	; set next state
375
 
376
	lfsr	FSR2, MIOS_AIN_RESULT_L_00
377
	movf	MIOS_AIN_INPUT_CTR, W, BANKED
378
	BRA_IFCLR MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_ACTIVE, BANKED, MIOS_AIN_Tick_State1_NoDP
379
	movf	MIOS_AIN_LAST_POT0, W, BANKED
380
	btfsc	MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_POT, BANKED
381
	movf	MIOS_AIN_LAST_POT1, W, BANKED
382
MIOS_AIN_Tick_State1_NoDP
383
	addwf	FSR2L, F
384
 
385
	;; calc IRQ_TMP_[12] = ADRES_[LH] - INDF2_[LH]
386
	movf	INDF2, W
387
	subwf	ADRESL, W
388
	movwf	IRQ_TMP1
389
	bsf	FSR2L, 6
390
	movf	INDF2, W
391
	andlw	0x7f		; (clear "changed" bit)
392
	subwfb	ADRESH, W
393
	movwf	IRQ_TMP2
394
	;; if result negative, invert values
395
	btfsc	IRQ_TMP2, 7
396
	comf	IRQ_TMP1, F
397
	btfsc	IRQ_TMP2, 7
398
	comf	IRQ_TMP2, F
399
 
400
	movf	IRQ_TMP1, W
401
	movf	IRQ_TMP2, F
402
	skpz
403
	movlw	0xff
404
	movwf	MIOS_AIN_POTSPEED, BANKED	; this value is also used by the MF driver
405
 
406
	;; save new result if absolute difference > MIOS_AIN_DEADBAND
407
	movf	MIOS_AIN_DEADBAND, W, BANKED
408
	cpfsgt	MIOS_AIN_POTSPEED, BANKED
409
	rgoto MIOS_AIN_Tick_State1_NoNew
410
 
411
MIOS_AIN_Tick_State1_New
412
	;; save new result
413
	bcf	FSR2L, 6
414
	movff	ADRESL, INDF2
415
	bsf	FSR2L, 6
416
	movff	ADRESH, INDF2
417
	bsf	INDF2, 7	; set "changed" bit
418
	bcf	FSR2L, 6
419
 
420
	;; if result < 5, then clear it (lowest position reached)
421
	movf	ADRESH, W
422
	bnz	MIOS_AIN_Tick_State1_New_No0
423
	movlw	0x05
424
	cpfslt	ADRESL, ACCESS
425
	rgoto MIOS_AIN_Tick_State1_New_No0
426
	clrf	INDF2
427
MIOS_AIN_Tick_State1_New_No0
428
 
429
	;; save pot number in MIOS_AIN_POT_LAST[01]
430
	movf	FSR2L, W
431
	andlw	0x3f
432
	cpfseq	MIOS_AIN_LAST_POT0, BANKED
433
	rgoto MIOS_AIN_Tick_State1_NewLast0
434
	rgoto	MIOS_AIN_Tick_State1_NoNew
435
MIOS_AIN_Tick_State1_NewLast0
436
	movff	MIOS_AIN_LAST_POT0, MIOS_AIN_LAST_POT1
437
	movwf	MIOS_AIN_LAST_POT0, BANKED
438
MIOS_AIN_Tick_State1_NoNew
439
 
440
	;; if motorfader mode: branch to MF tick, else use standard result handler
441
	BRA_IFSET MIOS_AIN_CTRL, MIOS_AIN_CTRL_MF, BANKED, MIOS_MF_Tick
442
MIOS_MF_Tick_Return
443
	SET_BSR	MIOS_AIN_INPUT_CTR
444
MIOS_AIN_Tick_State1_NoMF
445
 
446
	;; dynamic priority feature (only used in muxed mode)
447
MIOS_AIN_Tick_State1_DynPrio
448
	BRA_IFCLR MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_ACTIVE, BANKED, MIOS_AIN_Tick_State1_DynPrioChk
449
	bcf	MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_ACTIVE, BANKED
450
	rgoto	MIOS_AIN_Tick_State1_NoDynPrio
451
MIOS_AIN_Tick_State1_DynPrioChk
452
	BRA_IFCLR MIOS_AIN_CTRL, MIOS_AIN_CTRL_MUXED, BANKED, MIOS_AIN_Tick_State1_NoDynPrio
453
	BRA_IFSET MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_DISABLE, BANKED, MIOS_AIN_Tick_State1_NoDynPrio
454
	;; every 4th conversion...
455
	movf	MIOS_AIN_INPUT_CTR, W, BANKED
456
	andlw	0x03
457
	bnz	MIOS_AIN_Tick_State1_NoDynPrio
458
	;; ...convert one of the last two turned pots if dynamic priority function is enabled
459
	bsf	MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_ACTIVE, BANKED
460
	btg	MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_POT, BANKED
461
	rgoto	MIOS_AIN_Tick_State1_DynPrioNow; (don't increment input counter)
462
MIOS_AIN_Tick_State1_NoDynPrio
463
 
464
	;; continue with next input pin
465
	incf	MIOS_AIN_INPUT_CTR, F, BANKED		; increment input counter
466
	movf	MIOS_AIN_NUMBER, W, BANKED
467
	bz	MIOS_AIN_Tick_Stop
468
	xorwf	MIOS_AIN_INPUT_CTR, W, BANKED		; reset if max value reached
469
	skpnz
470
	clrf	MIOS_AIN_INPUT_CTR, BANKED
471
MIOS_AIN_Tick_State1_DynPrioNow; (don't increment input counter)
472
 
473
	BRA_IFSET MIOS_AIN_CTRL, MIOS_AIN_CTRL_MUXED, BANKED, MIOS_AIN_Tick_State1_Muxed
474
MIOS_AIN_Tick_State1_UnMuxed
475
	swapf	MIOS_AIN_INPUT_CTR, W, BANKED ; calc ADCON0 value (0x81 | (pot number << 3)
476
	movwf	IRQ_TMP1
477
	rrf	IRQ_TMP1, W
478
	rgoto	MIOS_AIN_Tick_State1_UnMuxedCnt
479
 
480
MIOS_AIN_Tick_State1_Muxed
481
	movf	MIOS_AIN_INPUT_CTR, W, BANKED
482
	BRA_IFCLR MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_ACTIVE, BANKED, MIOS_AIN_Tick_State1_Muxed_NoDP
483
	movf	MIOS_AIN_LAST_POT0, W, BANKED
484
	btfsc	MIOS_AIN_CTRL, MIOS_AIN_CTRL_DYNPRIO_POT, BANKED
485
	movf	MIOS_AIN_LAST_POT1, W, BANKED
486
MIOS_AIN_Tick_State1_Muxed_NoDP
487
 
488
	BRA_IFSET WREG, 2, ACCESS, MIOS_AIN_Tick_State1_Muxed4567
489
MIOS_AIN_Tick_State1_Muxed0123
490
	BRA_IFSET WREG, 1, ACCESS, MIOS_AIN_Tick_State1_Muxed23
491
MIOS_AIN_Tick_State1_Muxed01
492
	bsf	MIOS_AIN_LAT_MUX_0, MIOS_AIN_PIN_MUX_0
493
	bsf	MIOS_AIN_LAT_MUX_2, MIOS_AIN_PIN_MUX_2
494
	BRA_IFSET WREG, 0, ACCESS, MIOS_AIN_Tick_State1_Muxed1
495
 
496
MIOS_AIN_Tick_State1_Muxed0
497
	bcf	MIOS_AIN_LAT_MUX_1, MIOS_AIN_PIN_MUX_1
498
	rgoto	MIOS_AIN_Tick_State1_MuxedCont
499
MIOS_AIN_Tick_State1_Muxed1
500
	bsf	MIOS_AIN_LAT_MUX_1, MIOS_AIN_PIN_MUX_1
501
	rgoto	MIOS_AIN_Tick_State1_MuxedCont
502
 
503
MIOS_AIN_Tick_State1_Muxed23
504
	bsf	MIOS_AIN_LAT_MUX_0, MIOS_AIN_PIN_MUX_0
505
	bcf	MIOS_AIN_LAT_MUX_2, MIOS_AIN_PIN_MUX_2
506
	BRA_IFSET WREG, 0, ACCESS, MIOS_AIN_Tick_State1_Muxed3
507
 
508
MIOS_AIN_Tick_State1_Muxed2
509
	bsf	MIOS_AIN_LAT_MUX_1, MIOS_AIN_PIN_MUX_1
510
	rgoto	MIOS_AIN_Tick_State1_MuxedCont
511
MIOS_AIN_Tick_State1_Muxed3
512
	bcf	MIOS_AIN_LAT_MUX_1, MIOS_AIN_PIN_MUX_1
513
	rgoto	MIOS_AIN_Tick_State1_MuxedCont
514
 
515
MIOS_AIN_Tick_State1_Muxed4567
516
	BRA_IFSET WREG, 1, ACCESS, MIOS_AIN_Tick_State1_Muxed67
517
MIOS_AIN_Tick_State1_Muxed45
518
	bcf	MIOS_AIN_LAT_MUX_0, MIOS_AIN_PIN_MUX_0
519
	BRA_IFSET WREG, 0, ACCESS, MIOS_AIN_Tick_State1_Muxed5
520
 
521
MIOS_AIN_Tick_State1_Muxed4
522
	bsf	MIOS_AIN_LAT_MUX_1, MIOS_AIN_PIN_MUX_1
523
	bcf	MIOS_AIN_LAT_MUX_2, MIOS_AIN_PIN_MUX_2
524
	rgoto	MIOS_AIN_Tick_State1_MuxedCont
525
MIOS_AIN_Tick_State1_Muxed5
526
	bcf	MIOS_AIN_LAT_MUX_1, MIOS_AIN_PIN_MUX_1
527
	bsf	MIOS_AIN_LAT_MUX_2, MIOS_AIN_PIN_MUX_2
528
	rgoto	MIOS_AIN_Tick_State1_MuxedCont
529
 
530
MIOS_AIN_Tick_State1_Muxed67
531
	bcf	MIOS_AIN_LAT_MUX_0, MIOS_AIN_PIN_MUX_0
532
	BRA_IFSET WREG, 0, ACCESS, MIOS_AIN_Tick_State1_Muxed7
533
 
534
MIOS_AIN_Tick_State1_Muxed6
535
	bcf	MIOS_AIN_LAT_MUX_1, MIOS_AIN_PIN_MUX_1
536
	bcf	MIOS_AIN_LAT_MUX_2, MIOS_AIN_PIN_MUX_2
537
	rgoto	MIOS_AIN_Tick_State1_MuxedCont
538
MIOS_AIN_Tick_State1_Muxed7
539
	bsf	MIOS_AIN_LAT_MUX_1, MIOS_AIN_PIN_MUX_1
540
	bsf	MIOS_AIN_LAT_MUX_2, MIOS_AIN_PIN_MUX_2
541
	;; 	rgoto	MIOS_AIN_Tick_State1_MuxedCont
542
 
543
MIOS_AIN_Tick_State1_MuxedCont
544
	;; 	movf	MIOS_AIN_INPUT_CTR, W, BANKED
545
	;; already in WREG
546
	;; can be different when dynamic priority active
547
MIOS_AIN_Tick_State1_UnMuxedCnt
548
#if PIC_DERIVATIVE_NEW_ADC	; PIC18F4620, PIC18F4520, ...
549
	rrf	WREG, W
550
	andlw	0x1c
551
	iorlw	0x01
552
#else
553
	andlw	0x38
554
	iorlw	0x81
555
#endif
556
	movwf	ADCON0
557
	bsf	ADCON0, GO	; do a dummy conversion
558
 
559
MIOS_AIN_Tick_End
560
	return
561
 
562
 
563
	;; called when MIOS_AIN_NUMBER is zero: stop this timer
564
	;; timer can be enabled again with the MIOS_AIN_NumberSet
565
MIOS_AIN_Tick_Stop
566
	bcf	INTCON, T0IE
567
	bcf	T0CON, TMR0ON
568
	return
569