comparison src/adc_lightsensor.asm @ 113:f3062a611eef

Merge
author heinrichsweikamp
date Mon, 23 Jun 2014 16:14:33 +0200
parents 18fe4e668baa
children 6c577737c34e
comparison
equal deleted inserted replaced
112:a24581f0b372 113:f3062a611eef
10 10
11 #include "ostc3.inc" 11 #include "ostc3.inc"
12 #include "math.inc" 12 #include "math.inc"
13 #include "wait.inc" 13 #include "wait.inc"
14 #include "eeprom_rs232.inc" 14 #include "eeprom_rs232.inc"
15 #include "i2c.inc"
15 16
16 sensors CODE 17 sensors CODE
17 18
18 wait_adc: 19 wait_adc:
19 movwf ADCON0 20 movwf ADCON0
24 bra wait_adc2 25 bra wait_adc2
25 return 26 return
26 27
27 global get_battery_voltage 28 global get_battery_voltage
28 get_battery_voltage: ; starts ADC and waits until fnished 29 get_battery_voltage: ; starts ADC and waits until fnished
30 btfss c3_hardware
31 bra get_battery_voltage1 ; Normal ostc3 hardware
32
33 call lt2942_get_accumulated_charge
34 call lt2942_get_voltage
35 return
36
37 get_battery_voltage1:
29 bsf adc_running ; =1: The ADC is in use 38 bsf adc_running ; =1: The ADC is in use
30 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV 39 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV
31 movwf ADCON1 40 movwf ADCON1
32 movlw b'00011001' ; power on ADC, select AN6 41 movlw b'00011001' ; power on ADC, select AN6
33 rcall wait_adc 42 rcall wait_adc
184 global get_ambient_level 193 global get_ambient_level
185 get_ambient_level: ; starts ADC and waits until finished 194 get_ambient_level: ; starts ADC and waits until finished
186 btfsc adc_running ; ADC in use? 195 btfsc adc_running ; ADC in use?
187 return ; Yes, return 196 return ; Yes, return
188 197
198 btfss c3_hardware
199 bra get_ambient_level1 ; Normal ostc3 hardware
200 movlw .250
201 movwf ambient_light+0
202 clrf ambient_light+1 ; Set to max
203 bra get_ambient_level2 ; Continue as normal
204
205 get_ambient_level1:
189 movlw b'00000000' ; Vref+ = Vdd 206 movlw b'00000000' ; Vref+ = Vdd
190 movwf ADCON1 207 movwf ADCON1
191 movlw b'00011101' ; power on ADC, select AN7 208 movlw b'00011101' ; power on ADC, select AN7
192 rcall wait_adc 209 rcall wait_adc
193 210
264 movwf ambient_light+0 ; No, set to min 281 movwf ambient_light+0 ; No, set to min
265 282
266 movff ambient_light+0,max_CCPR1L ; Store value for dimming in TMR7 interrupt 283 movff ambient_light+0,max_CCPR1L ; Store value for dimming in TMR7 interrupt
267 return 284 return
268 285
269 global get_rssi_level 286 global get_analog_inputs
270 get_rssi_level: ; starts ADC and waits until fnished 287 get_analog_inputs: ; starts ADC and waits until finished
271 bsf adc_running ; =1: The ADC is in use 288 bsf adc_running ; =1: The ADC is in use
289 btfsc TFT_PWM
290 bra get_analog_inputs ; Wait for PWM low
291 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV
292 movwf ADCON1
293 movlw b'00100001' ; power on ADC, select AN8
294 rcall wait_adc
295 bcf STATUS,C
296 rrcf ADRESH,F ; /2
297 rrcf ADRESL,F
298 movff ADRESL,o2_mv_sensor1+0 ; in 0.1mV steps
299 movff ADRESH,o2_mv_sensor1+1
300 bcf STATUS,C
301 rlcf ADRESL,F
302 rlcf ADRESH,F
272 movlw b'00100000' ; 2.048V Vref+ 303 movlw b'00100000' ; 2.048V Vref+
273 movwf ADCON1 304 movwf ADCON1
274 movlw b'01000101' ; power on ADC, select AN17 305 movlw b'00100101' ; power on ADC, select AN9
275 rcall wait_adc 306 rcall wait_adc
276 307 bcf STATUS,C
277 movff ADRESL,rssi_value 308 rrcf ADRESH,F ; /2
309 rrcf ADRESL,F
310 movff ADRESL,o2_mv_sensor2+0 ; in 0.1mV steps
311 movff ADRESH,o2_mv_sensor2+1
312 movlw b'00100000' ; 2.048V Vref+
313 movwf ADCON1
314 movlw b'00101001' ; power on ADC, select AN10
315 rcall wait_adc
316 bcf STATUS,C
317 rrcf ADRESH,F ; /2
318 rrcf ADRESL,F
319 movff ADRESL,o2_mv_sensor3+0 ; in 0.1mV steps
320 movff ADRESH,o2_mv_sensor3+1
278 bcf ADCON0,0 ; power off ADC 321 bcf ADCON0,0 ; power off ADC
279 bcf adc_running ; =1: The ADC is in use 322 bcf adc_running ; =1: The ADC is in use
280 return 323 return
281 324
325 global piezo_config ; Sets up piezo sensitivity of heinrichs weikamp Piezo buttons (~30ms)
326 piezo_config:
327 movlw .20
328 rcall piezo_config_tx ; Send one byte
329 movlw .20
330 rcall piezo_config_tx ; Send one byte
331 movlw .100
332 rcall piezo_config_tx ; Send one byte
333 movlw .200
334 rcall piezo_config_tx ; Send one byte
335 return
336
337 piezo_config_tx:
338 movwf uart1_temp ; Store byte
339 movlw .8
340 movwf uart2_temp ; Bit counter
341 bcf TX3_PIEZO_CFG ; Startbit
342 rcall piezo_config_wait_bit
343 piezo_config_tx_loop:
344 btfss uart1_temp,0 ; LSB first
345 bcf TX3_PIEZO_CFG
346 btfsc uart1_temp,0 ; LSB first
347 bsf TX3_PIEZO_CFG
348 rcall piezo_config_wait_bit
349 rrncf uart1_temp,F
350 decfsz uart2_temp,F
351 bra piezo_config_tx_loop
352 bsf TX3_PIEZO_CFG ; Stopbit
353 rcall piezo_config_wait_bit
354 return
355
356 piezo_config_wait_bit:
357 setf TMR5H
358 movlw .255-.26 ;26 x 31,5µs = 819us
359 movwf TMR5L
360 bcf PIR5,TMR5IF ; Clear flag
361 piezo_config_wait_bit3:
362 btfss PIR5,TMR5IF
363 bra piezo_config_wait_bit3 ; Wait loop
364 return
365
282 global reset_battery_pointer 366 global reset_battery_pointer
283 reset_battery_pointer: ; Resets battery pointer 0x07-0x0C and battery_gauge:5 367 reset_battery_pointer: ; Resets battery pointer 0x07-0x0C and battery_gauge:5
284 clrf EEADRH 368 extern lt2942_charge_done
369 call lt2942_charge_done ; Reset accumulating registers to 0xFFFF
370 clrf EEADRH
285 clrf EEDATA ; Delete to zero 371 clrf EEDATA ; Delete to zero
286 write_int_eeprom 0x07 372 write_int_eeprom 0x07
287 write_int_eeprom 0x08 373 write_int_eeprom 0x08
288 write_int_eeprom 0x09 374 write_int_eeprom 0x09
289 write_int_eeprom 0x0A 375 write_int_eeprom 0x0A