After solving a previous problem with my fledging project of which can be seen in the link below, I've got on with the task of duplicating that solved code which is an ADC input featuring a 10kΩ LDR as a way of controlling the input depending on the level of light with an output being that of a simple LED.
I wanted to have more sensors on this so I duplicated areas of code and assigned more register locations for the data that would be processed later; as a way to create multiple ADC inputs, the second ADC input process went 'easy-as-pie' but when it came to the third and final ADC input, it acted all... weird.
Linky
The output that I got appeared at the wrong LED (pin RB0 instead of pin RB7) and even when at this location, the LED won't continue to stay on even after the 'threshold voltage'
It's obvious that I missed something here, something that I didn't pick up during my 'studying' of the 16F88's datasheet, or is it a perk of the 16F88 that I'm totally unaware of?
Can someone help me on this, please?
Thanks
The code of the third ADC can be seen on red
-Kai-Itza-
I wanted to have more sensors on this so I duplicated areas of code and assigned more register locations for the data that would be processed later; as a way to create multiple ADC inputs, the second ADC input process went 'easy-as-pie' but when it came to the third and final ADC input, it acted all... weird.
Linky
The output that I got appeared at the wrong LED (pin RB0 instead of pin RB7) and even when at this location, the LED won't continue to stay on even after the 'threshold voltage'
It's obvious that I missed something here, something that I didn't pick up during my 'studying' of the 16F88's datasheet, or is it a perk of the 16F88 that I'm totally unaware of?
Can someone help me on this, please?
Thanks
Code:
; TUTAADC.INC 23MAR04
; illustrating use of ADC
;
; Create list file and select processor :
list p = 16f88
;
#DEFINE BANK0 BCF STATUS,5
#DEFINE BANK1 BSF STATUS,5
#DEFINE BLOCK0 BCF STATUS,7 ; clear STATUS bit 7 (IRP)
#DEFINE BLOCK1 BSF STATUS,7 ; set STATUS bit 7 (IRP)
;
#DEFINE CHAN0 iorlw B'00000000'
#DEFINE CHAN1 iorlw B'00001000'
#DEFINE CHAN2 iorlw B'00010000'
#DEFINE CHAN3 iorlw B'00011000'
#DEFINE CHAN4 iorlw B'00100000'
#DEFINE CHAN5 iorlw B'00101000'
#DEFINE CHAN6 iorlw B'00110000'
#DEFINE CHAN7 iorlw B'00111000'
;
; Include file containing register labels:
Include "p16f88.inc"
;
CBLOCK
ADCLDR
ADCTH
ADCSMS
ENDC
;
;
PORTA EQU H'05'
PORTB EQU H'06'
TRISB EQU H'86' ; Port B direction register
TRISA EQU H'85' ; Port A direction register
STATUS EQU H'03' ; STATUS register
z EQU 2 ;Zero flag
c EQU 0
count EQU H'20' ; assign General Purpose Register, Bank 0 for counter
valtes EQU H'35' ;testing value
totldr EQU h'36'
totth EQU h'2A'
totsm EQU h'2B'
half EQU h'2C'
hlvadc EQU h'2D'
;
; set up code for 16F88 ports
BSF 3,5 ;switch to page 1
CLRF H'9b' ;clear ansel file - set ports to digital io
BCF 3,5 ;switch to page 0
;
; *********** SETTING PORTA FOR ANALOGUE ***********
;
point BLOCK0
BANK1
clrf TRISB ; PORTB as output
movlw B'00000000' ; set Left justify, RA0, RA1, RA3 as analog inputs
movwf ADCON1 ; with RA, RE digital, ref to +VE and 0V
movlw B'11011011' ; RA0, RA1, RA3, RA4 as input, RA2, RA5 as output
movwf TRISA
BANK0
;
; *********** SETTING ADC CHANNEL AND READING ITS VALUE *****
;
part1 movlw B'01000101' ; set AD on, Fosc/8
CHAN0 ; set for CHAN0 - RA0
movwf ADCON0
call DELAY ; short delay following channel change
start1 bsf ADCON0,GO ; start data conversion
call DELAY
call GETADC ; get ADC value
goto part2
;
; ******** GET ADC VALUE FROM SELECTED PORT PIN *****
;
GETADC btfsc ADCON0,GO
goto GETADC
movf ADRESH,W ; get ADC MSB val
movwf ADCLDR ; store it into ADCMSB
;
;
;******* TEST ADC VALUE AGAINST "DARK TIME" VALUE
;
movlw d'102'
movwf valtes
;
movf ADCLDR, w
subwf valtes, totldr
btfss STATUS, c
goto ledon
goto ledoff
return
;
;***************SETTING ADC CHANNEL AND READIN ITS VALUE (Thermistor)***************************************
;
part2 movlw B'01000101' ; set AD on, Fosc/8
CHAN1 ; set for CHAN1 - RA1
movwf ADCON0
call DELAY ; short delay following channel change
start2 bsf ADCON0,GO ; start data conversion
call DELAY
call GETAC2 ; get ADC value
goto part3
;
;**************GET ADC VALUE FROM SELECTED PORT PIN ANS1 (THERMISTOR)*********************************
;
GETAC2 btfsc ADCON0,GO
goto GETAC2
movf ADRESH,w ; get ADC MSB val
movwf ADCTH ; store it into ADCTH
;
;***************TEST ADC VALUE AGAINST "HIGH TEMPERATURE" VALUE*************************************
;
movf ADCTH, w
subwf valtes, totth
btfss STATUS, c
goto led12
goto led02
return
;
[COLOR="red"];****************SETTING ADC CHANNEL TO READ ITS VALUE (SOIL MOISTURE SENSOR)
;
part3 movlw B'01000101' ; set AD on, Fosc/8
CHAN2 ; set for CHAN3 - RA3
movwf ADCON0
call DELAY ; short delay following channel change
start3 bsf ADCON0,GO ; start data conversion
call DELAY
call GETAC3 ; get ADC value
goto part1
;
;**************GET ADC VALUE FROM SELECTED PORT PIN ANS1 (SOIL MOISTURE SENSOR)*********************************
;
GETAC3 btfsc ADCON0,GO
goto GETAC3
movf ADRESH,w ; get ADC MSB val
movwf ADCSMS ; store it into ADCSMS
;
;***************TEST ADC VALUE AGAINST "HIGH TEMPERATURE" VALUE*************************************
;
movf ADCSMS, w
subwf valtes, totsm
btfsc STATUS, c
goto led13
goto led03
return[/COLOR]
;
;SUBROUTINE TO GET ANALOGUE INPUT - 20US SETTLING TIME.............
;
DELAY movlw d'007' ;time delay of 7x3=21us
movwf count ;load counter
again decfsz count ;decrement until zero
goto again ;decrement until zero
return
;
;******** If ZERO BIT IS ON, LED GOES ON ********
;
ledon clrf PORTB
bsf PORTB,0 ; set Port B pin 0 to logic
goto part2
;
ledoff bcf PORTB,0 ; clear Port B pin 0
return
;
led12 clrf PORTB
bsf PORTB,6 ; set Port B pin 9 to logic
goto part3
;
led02 bcf PORTB,6 ; clear Port B pin 9
return
;
led13 clrf PORTB
bsf PORTB,7 ; set Port B pin 8 to logic
goto part1
;
led03 bcf PORTB,7 ; clear Port B pin 8
return
;
END
The code of the third ADC can be seen on red
-Kai-Itza-