Mercurial > public > hwos_code
comparison src/adc_lightsensor.asm @ 656:8af5aefbcdaf default tip
Update to 3.31 beta
| author | heinrichsweikamp |
|---|---|
| date | Thu, 27 Nov 2025 18:32:58 +0100 |
| parents | 75e90cd0c2c3 |
| children |
comparison
equal
deleted
inserted
replaced
| 655:c7b7b8a358cd | 656:8af5aefbcdaf |
|---|---|
| 45 global get_battery_voltage | 45 global get_battery_voltage |
| 46 get_battery_voltage: | 46 get_battery_voltage: |
| 47 btfss battery_gauge_available ; battery gauge IC available? | 47 btfss battery_gauge_available ; battery gauge IC available? |
| 48 bra get_battery_voltage_2 ; NO - OSTC hardware without gauge IC | 48 bra get_battery_voltage_2 ; NO - OSTC hardware without gauge IC |
| 49 bsf battery_is_36v ; YES - gauge IC available, 3.6V battery | 49 bsf battery_is_36v ; YES - gauge IC available, 3.6V battery |
| 50 call lt2942_get_accumulated_charge ; - read coulomb counter | 50 call lt2942_get_voltage ; - read battery voltage (and coulomb counter) |
| 51 call lt2942_get_voltage ; - read battery voltage | |
| 52 call lt2942_get_temperature ; - read battery temperature | 51 call lt2942_get_temperature ; - read battery temperature |
| 53 tstfsz batt_voltage+1 ; - read voltage < 256 mV ? | 52 tstfsz batt_voltage+1 ; - read voltage < 256 mV ? |
| 54 bra get_battery_voltage_1 ; NO - proceed | 53 bra get_battery_voltage_1 ; NO - proceed |
| 55 call lt2942_get_accumulated_charge ; YES - re-read coulomb counter | 54 call lt2942_get_voltage ; - re-read battery voltage (and coulomb counter) |
| 56 call lt2942_get_voltage ; - re-read battery voltage | |
| 57 call lt2942_get_temperature ; - re-read battery temperature | 55 call lt2942_get_temperature ; - re-read battery temperature |
| 58 ;bra get_battery_voltage_1 ; - proceed | 56 ;bra get_battery_voltage_1 ; - proceed |
| 59 | 57 |
| 60 get_battery_voltage_1: | 58 get_battery_voltage_1: |
| 59 ; rcall double_check_battery_percent ; make sure batt_percent is adjusted when voltage does not comply with the computed value | |
| 61 rcall get_battery_voltage_low ; check for battery low condition | 60 rcall get_battery_voltage_low ; check for battery low condition |
| 62 btfsc divemode ; in dive mode? | 61 btfsc divemode ; in dive mode? |
| 63 return ; YES - done | 62 return ; YES - done |
| 64 | 63 |
| 65 bcf cv_active ; clear CV charing status by default | 64 bcf cv_active ; clear CV charing status by default |
| 86 btfsc surfmode_menu ; YES - in surface menus? | 85 btfsc surfmode_menu ; YES - in surface menus? |
| 87 bsf trigger_timeout ; YES - exit to surface mode during charging | 86 bsf trigger_timeout ; YES - exit to surface mode during charging |
| 88 charge_cv_active1: | 87 charge_cv_active1: |
| 89 decfsz get_bat_volt_counter,F ; decrement counter, became zero? | 88 decfsz get_bat_volt_counter,F ; decrement counter, became zero? |
| 90 return ; NO - not yet, done | 89 return ; NO - not yet, done |
| 91 movlw .15 ; YES - battery voltage >= 16*256mV (4.096V) | 90 movlw .16 ; YES - battery voltage >= 16*256mV (4.096V) and < 17*256mV (4.352V) |
| 92 cpfsgt batt_voltage+1 ; - ... ? | 91 cpfseq batt_voltage+1 ; - ... ? |
| 93 bra charge_cc_active ; NO | 92 bra charge_cc_active ; NO |
| 94 bsf cc_active ; YES - set CC charging status | 93 bsf cc_active ; YES - set CC charging status |
| 95 bsf cv_active ; - set CV charging status | 94 bsf cv_active ; - set CV charging status |
| 96 bsf LEDr ; - indicate charging | 95 bsf LEDr ; - indicate charging |
| 97 call lt2942_charge_done ; - reset accumulating registers to 0xFFFF | 96 call lt2942_charge_done ; - reset accumulating registers to 0xFFFF |
| 125 bra charge_cv_active ; YES | 124 bra charge_cv_active ; YES |
| 126 charge_cc_active2: | 125 charge_cc_active2: |
| 127 movlw .10 ; NO - set counter to 10 | 126 movlw .10 ; NO - set counter to 10 |
| 128 movwf get_bat_volt_counter ; - ... | 127 movwf get_bat_volt_counter ; - ... |
| 129 return ; - done | 128 return ; - done |
| 129 | |
| 130 double_check_battery_percent: ; make sure batt_percent is adjusted when voltage does not comply with the computed value | |
| 131 ; batt_voltage:2 is in mV | |
| 132 ; use thresholds rechargeable_36V_80 to rechargeable_36V_00 | |
| 133 ; return, if computed value is lower then fixed threshold | |
| 134 ; overwrite batt_percent if computed value is bigger then threshold | |
| 135 ; in 2024, it's no longer enough to explain the old behavior in the manual... | |
| 136 ; used up as temp here | |
| 137 movlw .100 | |
| 138 movwf up ; initialize | |
| 139 | |
| 140 MOVII batt_voltage,sub_b | |
| 141 MOVLI rechargeable_36V_80,sub_a ; load threshold 80% | |
| 142 call cmpU16 ; sub_a - sub_b | |
| 143 movlw .80 | |
| 144 btfss neg_flag ; battery voltage > rechargeable_36V_80 ? | |
| 145 movwf up ; no, overwrite up with a fix value | |
| 146 MOVII batt_voltage,sub_b | |
| 147 MOVLI rechargeable_36V_60,sub_a ; load threshold 60% | |
| 148 call cmpU16 ; sub_a - sub_b | |
| 149 movlw .60 | |
| 150 btfss neg_flag ; battery voltage > rechargeable_36V_60 ? | |
| 151 movwf up ; no, overwrite up with a fix value | |
| 152 MOVII batt_voltage,sub_b | |
| 153 MOVLI rechargeable_36V_40,sub_a ; load threshold 40% | |
| 154 call cmpU16 ; sub_a - sub_b | |
| 155 movlw .40 | |
| 156 btfss neg_flag ; battery voltage > rechargeable_36V_40 ? | |
| 157 movwf up ; no, overwrite up with a fix value | |
| 158 MOVII batt_voltage,sub_b | |
| 159 MOVLI rechargeable_36V_20,sub_a ; load threshold 20% | |
| 160 call cmpU16 ; sub_a - sub_b | |
| 161 movlw .20 | |
| 162 btfss neg_flag ; battery voltage > rechargeable_36V_20 ? | |
| 163 movwf up ; no, overwrite up with a fix value | |
| 164 MOVII batt_voltage,sub_b | |
| 165 MOVLI rechargeable_36V_00,sub_a ; load threshold 0% | |
| 166 call cmpU16 ; sub_a - sub_b | |
| 167 movlw .0 | |
| 168 btfss neg_flag ; battery voltage > rechargeable_36V_0 ? | |
| 169 movwf up ; no, overwrite up with a fix value | |
| 170 | |
| 171 movf up,W | |
| 172 cpfsgt batt_percent ; up < batt_percent | |
| 173 return | |
| 174 movwf batt_percent ; YES, overwritze | |
| 175 return | |
| 130 | 176 |
| 131 get_battery_voltage_2: ; no gauge IC available, use ADC to measure battery voltage | 177 get_battery_voltage_2: ; no gauge IC available, use ADC to measure battery voltage |
| 132 ; additional charging disable in software | 178 ; additional charging disable in software |
| 133 bsf charge_disable ; set charging-inhibit signal | 179 bsf charge_disable ; set charging-inhibit signal |
| 134 bcf charge_enable ; activate charging-inhibit signal | 180 bcf charge_enable ; activate charging-inhibit signal |
| 281 btfsc ambient_sensor ; - ambient sensor available? | 327 btfsc ambient_sensor ; - ambient sensor available? |
| 282 bra get_ambient_level1 ; YES - use sensor | 328 bra get_ambient_level1 ; YES - use sensor |
| 283 get_ambient_level0: | 329 get_ambient_level0: |
| 284 banksel isr_backup ; NO - back to ISR default bank | 330 banksel isr_backup ; NO - back to ISR default bank |
| 285 movff brightness,isr_lo ; - get brightness selection | 331 movff brightness,isr_lo ; - get brightness selection |
| 286 incf isr_lo,F ; - 0-2 -> 1-3 | 332 incf isr_lo,F ; - 0-2 -> 1-3 |
| 287 movlw ambient_light_max_high_cr ; - default selection to brightest setting | 333 movlw ambient_no_sensor_high ; - default selection to brightest setting |
| 288 dcfsnz isr_lo,F ; - level 0 (eco) selected? | 334 dcfsnz isr_lo,F ; - level 0 (eco) selected? |
| 289 movlw ambient_light_max_eco ; YES - select eco brightness | 335 movlw ambient_no_sensor_eco ; YES - select eco brightness |
| 290 dcfsnz isr_lo,F ; - level 1 (medium) selected? | 336 dcfsnz isr_lo,F ; - level 1 (medium) selected? |
| 291 movlw ambient_light_max_medium ; YES - select medium brightness | 337 movlw ambient_no_sensor_medium ; YES - select medium brightness |
| 292 movwf ambient_light+0 ; - store selection | 338 movwf ambient_light+0 ; - store selection |
| 293 movwf max_CCPR1L ; - store value for dimming in TMR7 interrupt | 339 movwf max_CCPR1L ; - store value for dimming in TMR7 interrupt |
| 294 return ; - done | 340 return ; - done |
| 295 | 341 |
| 296 get_ambient_level1: ; using ambient sensor | 342 get_ambient_level1: ; using ambient sensor |
| 297 banksel isr_backup ; back to ISR default bank | 343 banksel isr_backup ; back to ISR default bank |
| 298 clrf ADCON1 ; Vref+ = Vdd | 344 clrf ADCON1 ; Vref+ = Vdd |
| 299 movlw b'00011101' ; power on ADC, select AN7 | 345 movlw b'00011101' ; power on ADC, select AN7 |
| 300 rcall wait_adc | 346 rcall wait_adc |
| 301 MOVII ADRESL,ambient_light | 347 MOVII ADRESL,ambient_light |
| 348 ; MOVII ADRESL,gp_debug ; for debugging only | |
| 302 bcf ADCON0,0 ; power off ADC | 349 bcf ADCON0,0 ; power off ADC |
| 303 | 350 |
| 304 btfsc ambient_light+1,7 ; result negative? | 351 btfsc ambient_light+1,7 ; result negative? |
| 305 return ; Yes, skip this measurement | 352 return ; Yes, skip this measurement |
| 306 ; ambient_light:2 is between 4096 (direct sunlight) and about 200 (darkness) | 353 ; ambient_light:2 is between 4096 (direct sunlight) and about 200 (darkness) |
| 307 ; first: divide by 16 | 354 ; first: divide by 16 |
| 308 movlw .4 ; divide by 2^4 = 16 | 355 movlw .4 ; divide by 2^4 = 16 |
| 356 btfsc dn_flag | |
| 357 movlw .1 ; divide by 1^4 = 4, increased sensitivity for dn hardware | |
| 309 get_ambient_level1_loop: | 358 get_ambient_level1_loop: |
| 310 bcf STATUS,C ; clear carry | 359 bcf STATUS,C ; clear carry |
| 311 rrcf ambient_light+1 ; rotate right high byte, carry into MSB, LSB into carry | 360 rrcf ambient_light+1 ; rotate right high byte, carry into MSB, LSB into carry |
| 312 rrcf ambient_light+0 ; rotate right low byte, carry into MSB, LSB into carry | 361 rrcf ambient_light+0 ; rotate right low byte, carry into MSB, LSB into carry |
| 313 decfsz WREG ; decrement counter, done? | 362 decfsz WREG ; decrement counter, done? |
| 336 | 385 |
| 337 banksel HW_descriptor ; select bank where hardware descriptor and model variant are stored | 386 banksel HW_descriptor ; select bank where hardware descriptor and model variant are stored |
| 338 movlw ambient_light_max_high_cr ; default to cR and 2 hardware brightest setting | 387 movlw ambient_light_max_high_cr ; default to cR and 2 hardware brightest setting |
| 339 btfss battery_gauge_available ; battery gauge available? | 388 btfss battery_gauge_available ; battery gauge available? |
| 340 movlw ambient_light_max_high_15V ; NO - change to 1.5V battery brightest setting | 389 movlw ambient_light_max_high_15V ; NO - change to 1.5V battery brightest setting |
| 341 btfsc battery_is_36v ; 3.6V battery in use? | 390 btfsc battery_is_36v ; 3.6V battery in use? |
| 342 movlw ambient_light_max_high_36V ; YES - change to 3.6V battery brightest setting | 391 movlw ambient_light_max_high_36V ; YES - change to 3.6V battery brightest setting |
| 392 btfsc dn_flag ; dn hardware | |
| 393 movlw ambient_light_max_high_dn ; YES - change to dn hardware brightest setting | |
| 343 banksel isr_backup ; back to ISR default bank | 394 banksel isr_backup ; back to ISR default bank |
| 344 | 395 |
| 345 dcfsnz isr_lo,F ; eco setting? | 396 dcfsnz isr_lo,F ; eco setting? |
| 346 movlw ambient_light_max_eco ; YES | 397 movlw ambient_light_max_eco ; YES |
| 347 dcfsnz isr_lo,F ; medium setting? | 398 dcfsnz isr_lo,F ; medium setting? |
| 371 ;----------------------------------------------------------------------------- | 422 ;----------------------------------------------------------------------------- |
| 372 ; Read analog external Sensors | 423 ; Read analog external Sensors |
| 373 ; | 424 ; |
| 374 ; called from outside ISR only | 425 ; called from outside ISR only |
| 375 ; | 426 ; |
| 376 IFDEF _external_sensor | 427 IFDEF _external_sensor_eccr |
| 377 | 428 |
| 378 global get_analog_inputs | 429 global get_analog_inputs |
| 379 get_analog_inputs: | 430 get_analog_inputs: |
| 380 bsf adc_is_running ; =1: the ADC is in use | 431 bsf adc_is_running ; =1: the ADC is in use |
| 381 btfsc screen_type3 ; display 3 ? | 432 btfsc screen_type3 ; display 3 ? |
| 431 movlw ignore_mv_below ; NO - get lower limit of operational range | 482 movlw ignore_mv_below ; NO - get lower limit of operational range |
| 432 cpfsgt mpr+0 ; - > limit ? | 483 cpfsgt mpr+0 ; - > limit ? |
| 433 clrf mpr+0 ; NO - ignore this reading | 484 clrf mpr+0 ; NO - ignore this reading |
| 434 return ; - done | 485 return ; - done |
| 435 | 486 |
| 436 ENDIF ; _external_sensor | 487 ENDIF ; _external_sensor_eccr |
| 437 | 488 |
| 438 | 489 |
| 439 ;----------------------------------------------------------------------------- | 490 ;----------------------------------------------------------------------------- |
| 440 ; Set the Sensitivity of the Piezo Buttons | 491 ; Set the Sensitivity of the Piezo Buttons |
| 441 ; | 492 ; |
