annotate src/sleepmode.asm @ 650:bc214815deb2

3.19/10.75 release
author heinrichsweikamp
date Sun, 28 Aug 2022 13:13:38 +0200
parents 7d8a4c60ec1a
children 75e90cd0c2c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
3 ; File sleepmode.asm * combined next generation V3.09.4n
0
heinrichsweikamp
parents:
diff changeset
4 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
5 ; Sleep Mode
0
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
8 ;==============================================================================
0
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-08-12 : [mH] moving from OSTC code
heinrichsweikamp
parents:
diff changeset
11
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
12 #include "hwos.inc" ; Mandatory header
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
14 #include "surfmode.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
15 #include "tft.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
16 #include "start.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
17 #include "adc_lightsensor.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
18 #include "math.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
19 #include "ms5541.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
20 #include "eeprom_rs232.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
21 #include "external_flash.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
22 #include "ghostwriter.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
23 #include "i2c.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
24 #include "mcp.inc"
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
25 #include "wait.inc"
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
26 #include "tft_outputs.inc"
0
heinrichsweikamp
parents:
diff changeset
27
133
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 123
diff changeset
28
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
29 extern eeprom_deco_data_write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
30 extern option_check_and_store_all
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
31
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
32
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
33 ;---- Private local Variables -------------------------------------------------
133
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 123
diff changeset
34
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
35 CBLOCK local1 ; max size is 16 Byte !!!
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
36 accel_reference ; acceleration reference value for detecting movement / terminating deep sleep
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
37 sm_timer_10sec ; timer for 10 seconds tasks (pressure check)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
38 sm_timer_10min ; timer for 10 minutes tasks (tissue updating)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
39 ;sm_timer_15min ; timer for 15 minutes tasks (entering deep sleep)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
40 sm_10min_counter ; count #of 10 minutes
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
41 loop_counter ; loop counter, used in init_avg_switches routine
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
42 sm_flags ; local flags
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
43 ENDC ; used: 6 byte, remaining: 10 byte
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
44
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
45
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
46 ;---- Private local Flags -----------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
47
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
48 #DEFINE deep_sleep sm_flags,0 ; =1: in deep sleep mode, =0: normal sleep
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
49 #DEFINE desat_on_10_mins sm_flags,1 ; =1: calculate desaturation every 10 minutes, =0: every minute
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
50 #DEFINE charge_in_sleep sm_flags,2 ; =1: show charging screen
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
51 ; sm_flags,3 ; unused
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
52 ; sm_flags,4 ; unused
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
53 ; sm_flags,5 ; unused
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
54 ; sm_flags,6 ; unused
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
55 ; sm_flags,7 ; unused
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
56
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
57
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
58 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
59 slmode CODE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
60 ;==============================================================================
0
heinrichsweikamp
parents:
diff changeset
61
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
62
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
63 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
64 ; Entry Point for Sleep Mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
65 ;
0
heinrichsweikamp
parents:
diff changeset
66 global sleeploop
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
67 sleeploop:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
68 clrf STKPTR ; clear return addresses stack
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
69 call request_speed_normal ; request CPU speed switch to normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
70
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
71 bcf LEDg ; turn off green LED / release reset to RX circuitry
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
72 bcf LEDr ; turn off red LED
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
73
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
74 IFDEF _screendump
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
75 bcf screen_dump_avail ; disable screen dump function
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
76 ENDIF
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
77
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
78 bsf sleepmode ; flag being in sleep mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
79 bsf block_sensor_interrupt ; suspend ISR from executing sensor interrupts
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
80
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
81 bcf i2c_error_flag ; clear any I2C errors
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
82
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
83 call disable_ir_s8_analog ; power-down IR/S8/analog interface
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
84 call mcp_sleep ; power-down RX power supply
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
85
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
86 clrf ADCON0 ; power-down ADC module
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
87 call disable_rs232 ; power-down USB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
88 call I2C_sleep_compass ; power-down compass
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
89
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
90 call eeprom_deco_data_write ; update deco data in EEPROM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
91 call eeprom_battery_gauge_write ; update battery gauge in EEPROM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
92
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
93 btfsc option_changed ; do the options need to be stored to EEPROM ?
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
94 call option_check_and_store_all ; YES - check and store all option values in EEPROM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
95
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
96 call ext_flash_enable_protection ; enable write protection on external flash
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
97
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
98 clrf sm_timer_10sec ; clear 10 seconds timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
99 clrf sm_timer_10min ; clear 10 minutes timer
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
100 clrf sm_10min_counter ; clear 10mins counter
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
101 clrf sm_flags ; clear all local flags
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
102
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
103 call TFT_Display_FadeOut ; power-down backlight
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
104 call TFT_DisplayOff ; power-down display
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
105
0
heinrichsweikamp
parents:
diff changeset
106 sleeploop_loop:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
107 btfsc trigger_full_second ; one second in sleep?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
108 rcall one_sec_sleep ; YES - check switches, pressure sensor, etc.
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
109
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
110 btfss sleepmode ; shall terminate sleep mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
111 bra sleeploop_exit ; YES
0
heinrichsweikamp
parents:
diff changeset
112
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
113 rcall sleepmode_sleep ; sleep for 62.5...125 ms
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
114
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
115 btfss deep_sleep ; shall enter deep sleep?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
116 bra sleeploop_loop ; NO - remain in normal sleep loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
117 ;bra deepsleep_pre ; YES - enter deep sleep loop
0
heinrichsweikamp
parents:
diff changeset
118
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
119 deepsleep_pre:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
120 bcf PIE1,TMR1IE ; disable timer 1 interrupt
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
121 bcf PIE2,TMR3IE ; disable timer 2 interrupt
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
122 bcf PIE5,TMR7IE ; disable timer 7 interrupt
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
123 bcf PIE5,TMR4IE ; disable timer 4 interrupt
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
124 bcf INTCON, INT0IE ; disable INT0 interrupt
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
125 bcf INTCON3,INT1IE ; disable INT1 interrupt
0
heinrichsweikamp
parents:
diff changeset
126
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
127 bcf power_sw1 ; power-down switch 1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
128 bcf power_sw2 ; power-down switch 2
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
129
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
130 rcall deepsleep_get_accel ; read accelerometer into WREG
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
131 movwf accel_reference ; store as reference value
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
132 tstfsz accel_reference ; = 0 ?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
133 bra deepsleep_loop ; NO - continue
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
134 bra deepsleep_loop_exit ; YES - no deep sleep (fail-safe)
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
135
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
136 deepsleep_loop:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
137 btfsc trigger_full_second ; one second in deep sleep?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
138 rcall check_accelerometer ; YES - check accelerometer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
139
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
140 btfsc trigger_full_second ; one second in deep sleep?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
141 rcall one_sec_sleep ; YES - check switches, check pressure sensor, etc.
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
142
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
143 rcall sleepmode_sleep ; sleep for 62.5...125 ms
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
144
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
145 btfss sleepmode ; shall leave sleep mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
146 bcf deep_sleep ; YES - leave deep sleep mode then, too
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
147
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
148 btfsc deep_sleep ; shall leave deep sleep mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
149 bra deepsleep_loop ; NO - loop in deep sleep loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
150
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
151 deepsleep_loop_exit:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
152 bcf deep_sleep ; clear flag (again)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
153 clrf sm_10min_counter ; clear 10mins counter
650
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
154 bsf power_sw1 ; switch on power supply for switch 1
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
155 nop
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
156 bsf power_sw2 ; switch on power supply for switch 2
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
157 rcall init_avg_switches ; initialize the averaging system
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
158
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
159 bsf PIE1,TMR1IE ; enable timer 1 interrupt
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
160 bsf PIE2,TMR3IE ; enable timer 2 interrupt
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
161 bsf PIE5,TMR7IE ; enable timer 7 interrupt
640
8c1f1f334275 3.13 release
heinrichsweikamp
parents: 634
diff changeset
162 bsf PIE5,TMR4IE ; enable timer 4 interrupt
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
163 bsf INTCON, INT0IE ; enable INT0 interrupt
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
164 bsf INTCON3,INT1IE ; enable INT1 interrupt
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
165
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
166 bra sleeploop_loop ; enter normal sleep loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
167
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
168 sleeploop_exit:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
169 bcf switch_left ; eventually clear left button event
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
170 bcf switch_right ; eventually clear right button event
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
171 movlw .0 ; reset ISR sensor state machine
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
172 movff WREG,sensor_state_counter ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
173 bcf PIR5,TMR7IF ; clear timer 7, driving the ISR sensor interrupts
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
174 bcf block_sensor_interrupt ; re-enable execution of the ISR sensor interrupts
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
175 goto restart ; restart
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
176
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
177
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
178 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
179 ; Helper Function - Tasks every Second in Sleep Mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
180 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
181 one_sec_sleep:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
182 bcf trigger_full_second ; clear trigger flag
650
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
183
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
184 btfss button_hold_down_allowed ; mechanical push buttons?
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
185 bra one_sec_sleep_piezo_buttons ; No
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
186
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
187 btfss switch_left ; left switch pressed?
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
188 bra one_sec_sleep_buttons_done ; no, done
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
189 btfss switch_right ; right switch pressed?
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
190 bra one_sec_sleep_buttons_done ; no, done
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
191 bcf sleepmode ; Both pressed, wake up
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
192 bra one_sec_sleep_buttons_done ; Done.
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
193
650
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
194 one_sec_sleep_piezo_buttons:
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
195 btfsc switch_left ; left switch pressed?
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
196 bcf sleepmode ; YES - terminate sleep mode
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
197 btfsc switch_right ; right switch pressed?
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
198 bcf sleepmode ; YES - terminate sleep mode
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
199
650
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
200 one_sec_sleep_buttons_done:
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
201 bcf switch_right ; clear right button event
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
202 bcf switch_left ; clear left button event
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
203
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
204 btfsc battery_gauge_available ; is a battery gauge IC available?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
205 bra one_sec_sleep_1 ; YES - check for charger
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
206 btfsc ble_available ; Skip "USB" check in all Bluetooth models (Required for very old OSTC sport)
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
207 bra one_sec_sleep_2 ; - continue
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
208 btfsc vusb_in ; NO - USB plugged in?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
209 bcf sleepmode ; YES - terminate sleep mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
210 bra one_sec_sleep_2 ; - continue
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
211
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
212 one_sec_sleep_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
213 call get_battery_voltage ; check for charger
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
214
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
215 ; Test if charging
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
216 btfss cc_active ; charging?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
217 bra one_sec_sleep_1a ; NO
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
218 btfsc charge_in_sleep ; YES - already showing charge screen?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
219 bra one_sec_sleep_1b ; YES - only update data
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
220
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
221 bsf charge_in_sleep
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
222 bcf deep_sleep ; wake-up from deepsleep
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
223 call TFT_boot ; initialize TFT (includes clear screen)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
224 movlw .32
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
225 movff WREG,max_CCPR1L ; bank safe
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
226 call TFT_Display_FadeIn ; dim up the display
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
227 one_sec_sleep_1b:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
228 call TFT_surfmode_batt ; show battery type, voltage and color-coded percentage
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
229 bra one_sec_sleep_2 ; continue
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
230
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
231 one_sec_sleep_1a:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
232 btfss charge_in_sleep ; was showing charge screen?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
233 bra one_sec_sleep_2 ; NO
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
234
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
235 ; yes, power-down screen
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
236 call TFT_Display_FadeOut ; power-down backlight
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
237 call TFT_DisplayOff ; power-down display
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
238 bcf charge_in_sleep
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
239
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
240
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
241 one_sec_sleep_2:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
242 incf sm_timer_10sec,F ; increment 10 seconds timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
243 movlw .10 ; load a 10 into WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
244 cpfslt sm_timer_10sec ; timer < 10 yet?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
245 rcall ten_sec_sleep ; NO - do the every 10 second tasks
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
246
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
247 btfsc trigger_full_minute ; one minute in sleep?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
248 rcall one_min_sleep ; YES - do the every minute tasks
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
249
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
250 btfsc trigger_full_hour ; one hour in sleep?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
251 rcall one_hour_sleep ; YES - do the every hour tasks
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
252
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
253 ; sleepmode pressure sampling for new sensor is done here
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
254 btfss press_sensor_type ; New sensor found?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
255 return ; No, done.
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
256
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
257 btfsc ms5837_state ; =0: result of temperature is in the ADC
650
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
258 goto I2C_get_press_val_MS5837 ; (Will clear ms5837_state) (And return!)
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
259 goto I2C_get_temp_val_MS5837 ; (Will set ms5837_state) (And return!)
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
260 ; done.
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
261
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
262
650
bc214815deb2 3.19/10.75 release
heinrichsweikamp
parents: 643
diff changeset
263
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
264 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
265 ; Helper Function - Tasks every 10 Seconds in Sleep Mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
266 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
267 ten_sec_sleep:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
268 ; tasks every 10 seconds in sleep mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
269 clrf sm_timer_10sec ; clear timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
270 rcall pressuretest_sleep_fast ; get pressure without averaging (faster)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
271 MOVLI wake_up_from_sleep,sub_a ; load wake-up pressure (1160 mbar) into sub_a
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
272 MOVII pressure_abs, sub_b ; load current absolute pressure into sub_b
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
273 call cmpU16 ; sub_a - sub_b = wake-up pressure - current absolute pressure
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
274 btfsc neg_flag ; is the current absolute pressure > 1160 mbar ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
275 bcf sleepmode ; YES - terminate sleep mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
276 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
277
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
278
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
279 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
280 ; Helper Function - Tasks every Minute in Sleep Mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
281 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
282 one_min_sleep:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
283 ; tasks every minute in sleep mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
284 bcf trigger_full_minute ; clear flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
285
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
286 ; tick the 10 minutes timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
287 incf sm_timer_10min,F ; increment 10 minutes timer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
288 movlw .10 ; load a 10 into WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
289 cpfslt sm_timer_10min ; timer < 10 yet?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
290 rcall ten_min_sleep ; NO - do the every 10 minutes tasks
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
291
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
292 one_min_sleep_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
293 ; continue tasks every minute
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
294 btfsc desat_on_10_mins ; shall do desaturation calculation on 10 minute intervals?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
295 return ; YES - that's not here then, so done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
296 call deco_calc_dive_interval_1min ; NO - calculate 1 minute at surface conditions (C-code)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
297 banksel common ; - back to bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
298 return ; - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
299
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
300
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
301 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
302 ; Helper Function - Tasks every 10 Minutes in Sleep Mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
303 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
304 ten_min_sleep:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
305 ; tasks every 10 minutes in sleep mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
306 clrf sm_timer_10min ; reset timer to 0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
307
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
308 call sample_surface_pressure ; sample surface pressure and update ISR and deco engine
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
309
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
310 btfss analog_switches ; OSTC with analog switches?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
311 bra ten_min_sleep_0 ; NO - no analog switches, no deep sleep required
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
312
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
313 ; check if we need to enter deep sleep
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
314 incf sm_10min_counter,F ; count
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
315 movlw deep_sleep_10mins ; threshold
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
316 cpfseq sm_10min_counter ; threshold reached?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
317 bra ten_min_sleep_0 ; NO - threshold not reached yet
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
318
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
319 decf sm_10min_counter,F ; -1 to re-trigger every 10mins (in case of charging)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
320
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
321 btfss cc_active ; charging?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
322 bsf deep_sleep ; NO - activate deep-sleep mode
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
323
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
324 ten_min_sleep_0:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
325 btfss desat_on_10_mins ; shall do desaturation calculation on 10 minute intervals?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
326 bra ten_min_sleep_1 ; NO - continue checking if schedule can be switched to 10 minutes
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
327 call deco_calc_dive_interval_10min ; YES - calculate 10 minutes at surface conditions (C-code)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
328 banksel common ; - back to bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
329 return ; - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
330
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
331 ten_min_sleep_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
332 movff int_O_lead_supersat+0,WREG ; get leading tissue's supersaturation (only the lower byte is used for the value)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
333 bsf desat_on_10_mins ; switch to 10 minute intervals by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
334 tstfsz WREG ; gradient factor = 0 ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
335 bcf desat_on_10_mins ; NO - stay on 1 minute intervals
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
336 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
337
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
338
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
339 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
340 ; Helper Function - Tasks every Hour in Sleep Mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
341 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
342 one_hour_sleep:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
343 ; tasks every hour in sleep mode mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
344 bcf trigger_full_hour ; clear one hour flag
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
345 call eeprom_deco_data_write ; update deco data into EEPROM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 629
diff changeset
346 call eeprom_battery_gauge_write ; update battery gauge into EEPROM
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
347 return ; done
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
348
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
349
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
350 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
351 ; Helper Function - Initialization of the Button Event Averaging System
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
352 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
353 init_avg_switches:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
354 ; pause 4 seconds using CPU sleep mode to conserve on battery
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
355 movlw .4 ; time to pause
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
356 movwf loop_counter ; initialize loop counter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
357 bcf trigger_full_second ; clear 'one second elapsed' flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
358 activate_switches_1:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
359 rcall sleepmode_sleep ; sleep for 62.5...125 ms
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
360 btfss trigger_full_second ; did 1 second elapsed meanwhile?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
361 bra activate_switches_1 ; NO - loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
362 bcf trigger_full_second ; YES - clear flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
363 decfsz loop_counter,F ; - decrement loop counter, done?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
364 bra activate_switches_1 ; NO - loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
365
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
366 ; initialize the averaging system
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
367 movlw .32 ; number of readout cycles
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
368 movwf loop_counter ; initialize loop counter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
369 activate_switches_2:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
370 call get_analog_switches ; do a analog switch readout
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
371 decfsz loop_counter,F ; decrement loop counter, done?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
372 bra activate_switches_2 ; NO - loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
373
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
374 ; clear all button events that may have intermediately occurred
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
375 bcf PIR1,TMR1IF ; clear button-hold-down timer
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
376 bcf INTCON, INT0IF ; clear right button activity
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
377 bcf INTCON3,INT1IF ; clear left button activity
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
378 bcf analog_sw1_pressed ; clear analog switch 1 activity
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
379 bcf analog_sw2_pressed ; clear analog switch 2 activity
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
380 bcf switch_right ; clear right button event
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
381 bcf switch_left ; clear left button event
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
382
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
383 return ; done
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
384
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
385
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
386 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
387 ; Helper Function - Check for Change in Accelerometer Z-Axis
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
388 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
389 check_accelerometer:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
390 rcall deepsleep_get_accel ; read accelerometer into WREG
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
391 subwf accel_reference,W ; reference value - accel_DZ+0 -> WREG
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
392 btfsc STATUS,N ; result negative?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
393 negf WREG ; YES - negate it
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
394 movwf lo ; save as change of acceleration in Z-axis
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
395 movlw .100 ; load threshold (mg)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
396 cpfslt lo ; change of acceleration > threshold ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
397 bcf deep_sleep ; YES - terminate deep sleep mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
398 return ; done
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
399
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
400
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
401 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
402 ; Helper Function - read Accelerometer Z-Axis
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
403 ;
490
8dfb93e80338 NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents: 448
diff changeset
404 deepsleep_get_accel:
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
405 call I2C_init_compass ; start compass
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
406 rcall sleepmode_sleep ; sleep for 62.5...125 ms
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
407 call I2C_RX_accelerometer ; read accelerometer
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
408 call I2C_RX_accelerometer ; read accelerometer
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
409 call I2C_sleep_compass ; shut down compass
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
410 movff accel_DZ+0,WREG ; transfer result to WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
411 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
412
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
413
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
414 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
415 ; Helper Function - read Pressure without Averaging
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
416 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
417 ; faster method to save some power in sleep mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
418 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
419 pressuretest_sleep_fast:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
420 banksel isr_backup ; select bank ISR data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
421
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
422 clrf pressure_abs_avg+0 ; clear pressure average register
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
423 clrf pressure_abs_avg+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
424 clrf pressure_abs_avg+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
425
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
426 CLRI temperature_avg ; clear temperature average register
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
427
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
428 call get_temperature_start ; start temperature integration (73.5 us)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
429
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
430 rcall sleepmode_sleep ; sleep for 62.5...125 ms
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
431 rcall sleepmode_sleep ; sleep for 62.5...125 ms
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
432
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
433 call get_temperature_value ; get temperature... (May return in bank common)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
434 banksel isr_backup ; select bank ISR data
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
435 call get_pressure_start ; start pressure integration
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
436
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
437 rcall sleepmode_sleep ; sleep for 62.5...125 ms
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
438 rcall sleepmode_sleep ; sleep for 62.5...125 ms
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
439
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
440 call get_pressure_value ; state2: get pressure (51 us)(May return in bank common)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 640
diff changeset
441 banksel isr_backup ; select bank ISR data
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
442 call calculate_compensation ; calculate temperature compensated pressure (27 us)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
443
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
444 MOVII pressure_abs_avg,pressure_abs ; get result, bypassing the averaging
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
445
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
446 banksel common ; back to bank common
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 560
diff changeset
447 return
0
heinrichsweikamp
parents:
diff changeset
448
heinrichsweikamp
parents:
diff changeset
449
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
450 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
451 ; Helper Function - sleep for 62.5...125 ms
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
452 ;
0
heinrichsweikamp
parents:
diff changeset
453 sleepmode_sleep:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
454 movff BSR,BSR_backup ; backup current bank selection
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
455 banksel common ; switch to bank common
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
456 btfsc charge_in_sleep ; already showing charge screen?
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
457 bra sleepmode_sleepwalk ; YES - skip the actual sleep (but wait)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
458 sleep ; NO - put CPU into sleep (wakes up by timer 7 IRQ)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
459 sleep ; - put CPU into sleep again
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
460 sleepmode_sleep_1:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
461 movff BSR_backup,BSR ; restore bank selection
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
462 return ; done
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
463
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
464 sleepmode_sleepwalk:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
465 WAITMS d'65' ; wait 65 ms
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
466 bra sleepmode_sleep_1 ; continue with common part
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
467
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
468 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
469
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
470 END