changeset 238:9581e48a914f

Some cleanup in the ISR
author heinrichsweikamp
date Sun, 20 Mar 2011 17:55:21 +0100
parents 55178aa1f972
children 3ed240d60341
files code_part1/OSTC_code_asm_part1/MAIN.ASM code_part1/OSTC_code_asm_part1/definitions.asm code_part1/OSTC_code_asm_part1/isr.asm
diffstat 3 files changed, 93 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/MAIN.ASM	Sun Mar 20 10:19:19 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/MAIN.ASM	Sun Mar 20 17:55:21 2011 +0100
@@ -59,17 +59,14 @@
 		btfsc	INTCON,TMR0IF				;Timer0 INT (Debounce Timer)
 		call	timer0int
 
-		btfsc	PIR2,TMR3IF					;Timer3 INT (Delay for PWM Buzzer)
-		call	timer3int
-
 		btfsc	PIR1,RCIF					; UART
 		call	uartint
 
 		btfsc	INTCON,INT0IF				; Switch left
-		call	schalter_links
+		call	switch_left_int
 
 		btfsc	INTCON3,INT1IF				; switch right
-		call	schalter_rechts
+		call	switch_right_int
 
 		movff   prod_temp+1,PRODH
 		movff   prod_temp+0,PRODL
@@ -134,5 +131,12 @@
     MESSG "or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details."
     MESSG "You should have received a copy of the GNU General Public License along with this program.If not, see http://www.gnu.org/licenses/."
 
+  ifdef __DEBUG
+   	MESSG "OSTC Mk.2 code compiled in DEBUG configuration!"
+  else
+	MESSG "OSTC Mk.2 code compiled in RELEASE configuration!"
+  endif
+
+
 	END				; end of program
 
--- a/code_part1/OSTC_code_asm_part1/definitions.asm	Sun Mar 20 10:19:19 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/definitions.asm	Sun Mar 20 17:55:21 2011 +0100
@@ -34,6 +34,7 @@
 ;#DEFINE	GERMAN							; Use german_text.asm
 ;#DEFINE	SPANISH							; Use spanish_text.asm
 
+#DEFINE	__DEBUG	; 
 
 #DEFINE	logbook_profile_version	0x20        ; Do not touch!
 #DEFINE	T0CON_debounce	b'00000000'         ; Timer0 Switch Debounce
@@ -183,7 +184,6 @@
 ext_ee_temp2    res 1           ; External EEPROM Temp 2		used in I2C EEPROM
 
 isr1_temp       res 1           ; ISR temp variables
-isr2_temp       res 1
 isr3_temp       res 2
 
 timer1int_counter1  res 1       ;Timer 1 counter
--- a/code_part1/OSTC_code_asm_part1/isr.asm	Sun Mar 20 10:19:19 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/isr.asm	Sun Mar 20 17:55:21 2011 +0100
@@ -81,7 +81,7 @@
 		movff	PRODH,sim_pressure+1
 		bra		uartint1					; exit uart int
 
-schalter_links:								; 
+switch_left_int:
 		bcf		INTCON,INT0IF				; Clear flag
 
 		btfsc	T0CON,TMR0ON				; Timer0 running?
@@ -93,7 +93,7 @@
 		return
 
 
-schalter_rechts:							; 
+switch_right_int:
 		bcf		INTCON3,INT1IF				; Clear flag
 
 		btfsc	T0CON,TMR0ON				; Timer0 running?
@@ -106,7 +106,6 @@
 
 timer0_restart:
 		bcf		INTCON,TMR0IF				; Clear flag
-
 		clrf	T0CON						; Timer0
 		clrf	TMR0H
 		clrf	TMR0L
@@ -120,7 +119,6 @@
 		clrf	TMR0L
 		return
 		
-
 timer0int_left_reset:
 		bcf		INTCON2, INTEDG0			; Interrupt on faling edge again
 		bcf		switch_left_isr				; Clear flag, button press is done
@@ -149,12 +147,6 @@
 		bsf		INTCON2, INTEDG1			; Interrupt on rising edge again
 		return
 
-timer3int:
-		bcf		PIR2,TMR3IF					; Clear flag
-		bcf		T3CON,TMR0ON				; Stop Timer 3
-		bcf		T2CON,2						; stop Timer 2
-		return
-
 timer1int:
 		bcf		PIR1,TMR1IF					; Clear flag
 
@@ -168,94 +160,66 @@
 		movlw	0x08						; Timer1 int after 62.5ms (=16/second)
 		subwf	TMR1H,F			
 	
-		incf	timer1int_counter1,F
+		incf	timer1int_counter1,F		; Increase timer1 counter
+
 		movlw	d'15'						; One second 16
 		cpfsgt	timer1int_counter1			 
 		bra		sensor_int_pre				; only pressure sensor
-		call	RTCisr						; adjust time, then query pressure sensor
+		rcall	RTCisr						; adjust time, then query pressure sensor
 
 sensor_int_pre:
-		btfss	sleepmode					; In sleepmode?
-		bra		sensor_int					; No
-		return
+		btfsc	sleepmode					; In sleepmode?
+		return								; Yes
 
 sensor_int:
 		btfsc		no_sensor_int			; No sensor interrupt (because it's addressed during sleep)
 		return						
 
-		incf		timer1int_counter2,F		; counts to eight for state maschine
-
-		movlw		d'1'
-		cpfseq		timer1int_counter2		; State 1?
-		bra			sensor_int1				; No
+		incf		timer1int_counter2,F	; counts to eight for state maschine
 
-		bcf			pressure_refresh			; clear flags
-		clrf		isr3_temp+0				; pressure average registers
-		clrf		isr3_temp+1
-		clrf		temperature_temp+0
-		clrf		temperature_temp+1
-sensor_int0:
-		call		get_temperature_value		; State 1: Get temperature
-		call		get_pressure_start	 	; and start pressure integration.
-		return						; Done.
-sensor_int1:
-		movlw		d'2'
-		cpfseq		timer1int_counter2		; State 2?
-		bra			sensor_int2				; No
-		
-sensor_int1_1:
-		call		get_pressure_value		; State2: Get pressure (51us)
-		call		get_temperature_start		; and start temperature integration (73,5us)
-		call		calculate_compensation		; calculate temperature compensated pressure (233us)
-		movf		amb_pressure+0,W
-		addwf		isr3_temp+0				; average pressure
-		movf		amb_pressure+1,W
-		addwfc		isr3_temp+1
-		movf		temperature+0,W
-		addwf		temperature_temp+0		; average temperature
-		movf		temperature+1,W
-		addwfc		temperature_temp+1
-		return		
-sensor_int2:
-		movlw		d'3'
-		cpfseq		timer1int_counter2		; State 3?
-		bra			sensor_int3				; No
-		bra			sensor_int0				; Yes, but same as State 1!
-sensor_int3:
-		movlw		d'4'
-		cpfseq		timer1int_counter2		; State 4?
-		bra			sensor_int4				; No
-		bra			sensor_int1_1			; Yes, but same as State 2!
-sensor_int4:
-		movlw		d'5'					
-		cpfseq		timer1int_counter2		; State 5?
-		bra			sensor_int5				; No
-		bra			sensor_int0				; Yes, but same as State 1!
-sensor_int5:
-		movlw		d'6'
-		cpfseq		timer1int_counter2		; State 6?
-		bra			sensor_int6				; No
-		bra			sensor_int1_1			; Yes, but same as State 2!
-sensor_int6:
-		movlw		d'7'
-		cpfseq		timer1int_counter2		; State 7?
-		bra			sensor_int7				; No
-		bra			sensor_int0				; Yes, but same as State 1!
-sensor_int7:
-		rcall		sensor_int1_1			; Do State 2...
-		clrf		timer1int_counter2		; ..then reset State counter...
-		movlw		d'2'					; and calculate average!
-		movwf		isr2_temp				
-sensor_int8:		
+; State 1: Clear flags and average registers, get temperature (51us) and start pressure integration (73,5us)
+; State 2: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
+; State 3: Get temperature (51us) and start pressure integration (73,5us)
+; State 4: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
+; State 5: Get temperature (51us) and start pressure integration (73,5us)
+; State 6: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
+; State 7: Get temperature (51us) and start pressure integration (73,5us)
+; State 8: Get pressure (51us), start temperature integration (73,5us), calculate temperature compensated pressure (233us) and build average for half-second update of tempperature and pressure
+	
+		movff	timer1int_counter2,isr_divB		; isr_divB used as temp here...
+		dcfsnz	isr_divB,F
+		bra		sensor_int_state1_plus_restart	; Do State 1
+		dcfsnz	isr_divB,F
+		bra		sensor_int_state2				; Do State 2
+		dcfsnz	isr_divB,F
+		bra		sensor_int_state1				; Do State 3
+		dcfsnz	isr_divB,F
+		bra		sensor_int_state2				; Do State 4
+		dcfsnz	isr_divB,F
+		bra		sensor_int_state1				; Do State 5
+		dcfsnz	isr_divB,F
+		bra		sensor_int_state2				; Do State 6
+		dcfsnz	isr_divB,F
+		bra		sensor_int_state1				; Do State 7
+;		bra		sensor_int2_plus_average		; Do State 8
+
+;sensor_int2_plus_average:
+		rcall		sensor_int_state2
+sensor_int2_plus_average2:		
 		bcf			STATUS,C
 		rrcf		isr3_temp+1				; isr3_temp / 2
 		rrcf		isr3_temp+0
 		bcf			STATUS,C
 		rrcf		temperature_temp+1		; temperature_temp /2
 		rrcf		temperature_temp+0
-		decfsz		isr2_temp,F
-		bra			sensor_int8				; once more
-		
+
+		bcf			STATUS,C
+		rrcf		isr3_temp+1				; isr3_temp / 4
+		rrcf		isr3_temp+0
+		bcf			STATUS,C
+		rrcf		temperature_temp+1		; temperature_temp /4
+		rrcf		temperature_temp+0
+	
 		movff		isr3_temp+1,amb_pressure+1	; copy into actual register
 		movff		isr3_temp+0,amb_pressure+0
 
@@ -263,6 +227,7 @@
 		movff		temperature_temp+0,temperature+0
 
 		bsf			pressure_refresh 			; Set flag! Temp and pressure were updated!
+		clrf		timer1int_counter2			; Then reset State counter
 
 		btfss		simulatormode_active		; are we in simulator mode?
 		bra			comp_air_pressure			; no
@@ -277,16 +242,44 @@
 		bcf			neg_flag				
 		movf		last_surfpressure+0,W		; compensate airpressure
 		subwf   	amb_pressure+0,W             
-		movwf   	rel_pressure+0			; rel_pressure stores depth!
+		movwf   	rel_pressure+0				; rel_pressure stores depth!
 
 		movf		last_surfpressure+1,W
 		subwfb  	amb_pressure+1,W
 		movwf   	rel_pressure+1
-		btfss		STATUS,N				; result is below zero?
+		btfss		STATUS,N					; result is below zero?
+		return
+		clrf		rel_pressure+0				; Yes, do not display negative depths
+		clrf		rel_pressure+1				; e.g. when surface air pressure dropped during the dive
 		return
-		clrf		rel_pressure+0			; Yes, do not display negative depths
-		clrf		rel_pressure+1			; e.g. when surface air pressure dropped during the dive
-		return
+
+
+sensor_int_state1_plus_restart:
+		bcf			pressure_refresh		; clear flags
+		clrf		isr3_temp+0				; pressure average registers
+		clrf		isr3_temp+1
+		clrf		temperature_temp+0
+		clrf		temperature_temp+1
+
+sensor_int_state1:
+		call		get_temperature_value	; State 1: Get temperature
+		call		get_pressure_start	 	; and start pressure integration.
+		return								; Done.
+
+sensor_int_state2:
+		call		get_pressure_value		; State2: Get pressure (51us)
+		call		get_temperature_start	; and start temperature integration (73,5us)
+		call		calculate_compensation	; calculate temperature compensated pressure (233us)
+		movf		amb_pressure+0,W
+		addwf		isr3_temp+0				; average pressure
+		movf		amb_pressure+1,W
+		addwfc		isr3_temp+1
+		movf		temperature+0,W
+		addwf		temperature_temp+0		; average temperature
+		movf		temperature+1,W
+		addwfc		temperature_temp+1
+		return		
+
 
 RTCisr:			
 		clrf		timer1int_counter1		; counts to 16 (one second / 62.5ms)
@@ -294,15 +287,16 @@
 
 		bcf			STATUS,Z				; are we in dive mode?
 		btfss		divemode
-		bra			RTCisr2				; No, must be surface or sleepmode
+		bra			RTCisr2					; No, must be surface or sleepmode
 
 		incf		samplesecs,F			; CF20 diving seconds done 
 		decf		samplesecs_value,W		; holds CF20 value  (minus 1 into WREG)
 		cpfsgt		samplesecs
-		bra			RTCisr1				; no
+		bra			RTCisr1					; no
 
 		clrf		samplesecs				; clear counter...
 		bsf			store_sample			; ...and set bit for profile storage
+
 RTCisr1:		
 ; Increase re-setable average depth divetime counter
 		incf		average_divesecs+0,F	; increase stopwatch registers	
@@ -316,6 +310,7 @@
 		movlw		d'59'
 		cpfsgt		divesecs
 		bra			RTCisr1a
+
 		clrf		divesecs
 		bsf			realdive				; this bit is always set (again) if the dive is longer then one minute