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