Mercurial > public > hwos_code
comparison src/adc_lightsensor.asm @ 640:8c1f1f334275
3.13 release
author | heinrichsweikamp |
---|---|
date | Thu, 29 Oct 2020 09:29:15 +0100 |
parents | 2737ddc643bb |
children | 7d8a4c60ec1a 5b7fe7777425 |
comparison
equal
deleted
inserted
replaced
639:0ff82370991d | 640:8c1f1f334275 |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File adc_lightsensor.asm * combined next generation V3.09.4e | 3 ; File adc_lightsensor.asm * combined next generation V3.11.1 |
4 ; | 4 ; |
5 ; | 5 ; |
6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | 6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. |
7 ;============================================================================= | 7 ;============================================================================= |
8 ; HISTORY | 8 ; HISTORY |
64 bcf cv_active ; clear CV charing status by default | 64 bcf cv_active ; clear CV charing status by default |
65 bcf cc_active ; clear CC charing status ny default | 65 bcf cc_active ; clear CC charing status ny default |
66 bcf LEDr ; switch off red LED | 66 bcf LEDr ; switch off red LED |
67 bcf TRISJ,2 ; activate Chrg-Out output | 67 bcf TRISJ,2 ; activate Chrg-Out output |
68 bsf CHRG_OUT ; start charger | 68 bsf CHRG_OUT ; start charger |
69 nop ; Ignore some noise | 69 nop ; ignore some noise |
70 nop | 70 nop ; ... |
71 nop | 71 nop ; ... |
72 nop | 72 nop ; ... |
73 btfss CHRG_IN ; charging? | 73 btfss CHRG_IN ; charging? |
74 bra charge_cc_active ; YES - charging in CC mode | 74 bra charge_cc_active ; YES - charging in CC mode |
75 bcf CHRG_OUT ; NO - stop charger | 75 bcf CHRG_OUT ; NO - stop charger |
76 bsf TRISJ,2 ; - set Chrg-Out output to high impedance | 76 bsf TRISJ,2 ; - set Chrg-Out output to high impedance |
77 WAITMS d'1' ; - wait 1 ms | 77 WAITMS d'1' ; - wait 1 ms |
254 global get_ambient_level | 254 global get_ambient_level |
255 get_ambient_level: | 255 get_ambient_level: |
256 btfsc sleepmode ; in sleep mode? | 256 btfsc sleepmode ; in sleep mode? |
257 return ; YES - done | 257 return ; YES - done |
258 btfsc adc_is_running ; NO - ADC in use? | 258 btfsc adc_is_running ; NO - ADC in use? |
259 return ; YES - return | 259 return ; YES - abort |
260 banksel HW_descriptor ; NO - select bank where hardware descriptor is stored | 260 banksel HW_descriptor ; NO - select bank where hardware descriptor is stored |
261 btfsc ambient_sensor ; - ambient sensor available? | 261 btfsc ambient_sensor ; - ambient sensor available? |
262 bra get_ambient_level1 ; YES - use sensor | 262 bra get_ambient_level1 ; YES - use sensor |
263 banksel isr_backup ; NO - back to ISR default bank | 263 banksel isr_backup ; NO - back to ISR default bank |
264 movff opt_brightness,isr_lo ; - get brightness selection | 264 movff opt_brightness,isr_lo ; - get brightness selection |
281 bcf ADCON0,0 ; power off ADC | 281 bcf ADCON0,0 ; power off ADC |
282 | 282 |
283 ; ambient_light:2 is between 4096 (direct sunlight) and about 200 (darkness) | 283 ; ambient_light:2 is between 4096 (direct sunlight) and about 200 (darkness) |
284 ; first: divide by 16 | 284 ; first: divide by 16 |
285 | 285 |
286 ; bcf STATUS,C ; old /16 code | |
287 ; rrcf ambient_light+1 | |
288 ; rrcf ambient_light+0 | |
289 ; bcf STATUS,C | |
290 ; rrcf ambient_light+1 | |
291 ; rrcf ambient_light+0 | |
292 ; bcf STATUS,C | |
293 ; rrcf ambient_light+1 | |
294 ; rrcf ambient_light+0 | |
295 ; bcf STATUS,C | |
296 ; rrcf ambient_light+1 | |
297 ; rrcf ambient_light+0 | |
298 | |
299 movlw .4 ; divide by 2^4 = 16 | 286 movlw .4 ; divide by 2^4 = 16 |
300 get_ambient_level1_loop: | 287 get_ambient_level1_loop: |
301 bcf STATUS,C ; clear carry | 288 bcf STATUS,C ; clear carry |
302 rrcf ambient_light+1 ; rotate right high byte, carry into MSB, LSB into carry | 289 rrcf ambient_light+1 ; rotate right high byte, carry into MSB, LSB into carry |
303 rrcf ambient_light+0 ; rotate right low byte, carry into MSB, LSB into carry | 290 rrcf ambient_light+0 ; rotate right low byte, carry into MSB, LSB into carry |
316 | 303 |
317 movlw .254 | 304 movlw .254 |
318 movwf ambient_light+0 ; avoid ADC clipping | 305 movwf ambient_light+0 ; avoid ADC clipping |
319 | 306 |
320 get_ambient_level2: | 307 get_ambient_level2: |
321 ; movlw .10 | |
322 ; subwf ambient_light+0,F ; subtract 10 (ADC Offset) | |
323 ; btfsc STATUS,N | |
324 ; movwf ambient_light+0 ; avoid clipping | |
325 | |
326 movff opt_brightness,isr_lo ; get brightness setting | 308 movff opt_brightness,isr_lo ; get brightness setting |
327 | 309 |
328 btfsc RCSTA1,7 ; UART module on? | 310 btfsc RCSTA1,7 ; UART module on? |
329 clrf isr_lo ; YES - set temporary to eco mode | 311 clrf isr_lo ; YES - set temporary to eco mode |
330 | 312 |
331 incf isr_lo,F ; adjust 0-2 to 1-3 | 313 incf isr_lo,F ; adjust 0-2 to 1-3 |
332 | 314 |
333 movlw ambient_light_max_high_cr ; cR and 2 hardware brightest setting | 315 banksel HW_descriptor ; select bank where hardware descriptor and model variant are stored |
334 | 316 movlw ambient_light_max_high_cr ; default to cR and 2 hardware brightest setting |
335 banksel HW_descriptor ; select bank where hardware descriptor and model variant is stored | 317 btfss battery_gauge_available ; battery gauge available? |
336 btfss battery_gauge_available | 318 movlw ambient_light_max_high_15V ; NO - change to 1.5V battery brightest setting |
337 movlw ambient_light_max_high_15V ; 1.5V battery brightest setting | |
338 btfsc battery_is_36v ; 3.6V battery in use? | 319 btfsc battery_is_36v ; 3.6V battery in use? |
339 movlw ambient_light_max_high_36V ; YES - 3.6V battery brightest setting | 320 movlw ambient_light_max_high_36V ; YES - change to 3.6V battery brightest setting |
340 banksel isr_backup ; back to ISR default bank | 321 banksel isr_backup ; back to ISR default bank |
341 | 322 |
342 dcfsnz isr_lo,F ; eco setting? | 323 dcfsnz isr_lo,F ; eco setting? |
343 movlw ambient_light_max_eco ; YES | 324 movlw ambient_light_max_eco ; YES |
344 dcfsnz isr_lo,F ; medium setting? | 325 dcfsnz isr_lo,F ; medium setting? |
373 IFDEF _external_sensor | 354 IFDEF _external_sensor |
374 | 355 |
375 global get_analog_inputs | 356 global get_analog_inputs |
376 get_analog_inputs: | 357 get_analog_inputs: |
377 bsf adc_is_running ; =1: the ADC is in use | 358 bsf adc_is_running ; =1: the ADC is in use |
359 btfsc screen_type3 ; display 3 ? | |
360 bra get_analog_inputs2 ; yes, skip here | |
378 btfsc TFT_PWM ; PWM active? | 361 btfsc TFT_PWM ; PWM active? |
379 bra get_analog_inputs ; YES - wait for PWM low | 362 bra get_analog_inputs ; YES - wait for PWM low |
380 | 363 |
364 get_analog_inputs2: | |
381 movlw b'00100000' ; 2.048V Vref+ -> 1 LSB = 500 µV | 365 movlw b'00100000' ; 2.048V Vref+ -> 1 LSB = 500 µV |
382 movwf ADCON1 ; ... | 366 movwf ADCON1 ; ... |
383 | 367 |
384 ; Sensor 1 | 368 ; Sensor 1 |
385 movlw b'00100001' ; power on ADC, select AN8 | 369 movlw b'00100001' ; power on ADC, select AN8 |
525 return ; YES - abort | 509 return ; YES - abort |
526 btfsc cc_active ; NO - charging? | 510 btfsc cc_active ; NO - charging? |
527 bra get_analog_switches0 ; YES - abort (and clear both flags) | 511 bra get_analog_switches0 ; YES - abort (and clear both flags) |
528 | 512 |
529 get_analog_switches_2: | 513 get_analog_switches_2: |
514 ; reset the latch register in case it's externally pulled down. mH This is a test | |
515 bsf power_sw1 ; switch on power supply for switch 1 | |
516 bsf power_sw2 ; switch on power supply for switch 2 | |
517 | |
530 bsf adc_is_running ; flag that ADC is in use | 518 bsf adc_is_running ; flag that ADC is in use |
531 bcf ADCON2,ADFM ; left justified | 519 bcf ADCON2,ADFM ; left justified |
532 clrf ADCON1 ; | 520 clrf ADCON1 ; |
533 movlw b'00100101' ; power on ADC, select AN9 | 521 movlw b'00100101' ; power on ADC, select AN9 |
534 rcall wait_adc ; wait for ADC | 522 rcall wait_adc ; wait for ADC |