Friends,
I have decided to make an automatic voltage stabilizer using 16F676. While testing a portion of the project a peculiar working of the PIC is faced. Please see my codes. A pot (4.7K) has been used to feed analogue adc supply from 5V rail. when I rotate the pot to and fro at a point towards lower side the RA1 pin sets and clears. It is OK. Rotating the pot to and fro at a point towards higher side, the same RA1 pin sets and clears again. The RA0 pin remains set all along even I rotate the pot towards extreme high i.e. adc input is 5V. Please suggest any way.
Swapan
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _HS_OSC
cblock 0x20
AD_VALUE1
endc
start
CLRF PORTA
CLRF PORTC
BSF STATUS, RP0
MOVLW b'00111000'
MOVWF TRISA
MOVLW b'00111100'
MOVWF TRISC
MOVLW 0XC0
MOVWF ANSEL
MOVLW b'00100000'
MOVWF ADCON1
BCF STATUS, RP0
MOVLW 0X07
MOVWF CMCON
MAIN_ON:
MOVLW b'00011001'
MOVWF ADCON0
BSF ADCON0,GO
INIT:
BTFSC ADCON0,GO
GOTO INIT
MOVF ADRESH,0
MOVWF AD_VALUE1
MOVLW D'240'
SUBWF AD_VALUE1
BTFSS STATUS,C
GOTO RL_1
MOVLW B'00000000'
MOVWF PORTA
RL_1:
MOVLW D'220'
SUBWF AD_VALUE1
BTFSC STATUS,C
GOTO MAIN_ON
MOVLW b'00000001'
MOVWF PORTA
MOVLW D'200'
SUBWF AD_VALUE1
BTFSC STATUS,C
GOTO MAIN_ON
MOVLW b'00000011'
MOVWF PORTA
GOTO MAIN_ON
END
I have decided to make an automatic voltage stabilizer using 16F676. While testing a portion of the project a peculiar working of the PIC is faced. Please see my codes. A pot (4.7K) has been used to feed analogue adc supply from 5V rail. when I rotate the pot to and fro at a point towards lower side the RA1 pin sets and clears. It is OK. Rotating the pot to and fro at a point towards higher side, the same RA1 pin sets and clears again. The RA0 pin remains set all along even I rotate the pot towards extreme high i.e. adc input is 5V. Please suggest any way.
Swapan
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _HS_OSC
cblock 0x20
AD_VALUE1
endc
start
CLRF PORTA
CLRF PORTC
BSF STATUS, RP0
MOVLW b'00111000'
MOVWF TRISA
MOVLW b'00111100'
MOVWF TRISC
MOVLW 0XC0
MOVWF ANSEL
MOVLW b'00100000'
MOVWF ADCON1
BCF STATUS, RP0
MOVLW 0X07
MOVWF CMCON
MAIN_ON:
MOVLW b'00011001'
MOVWF ADCON0
BSF ADCON0,GO
INIT:
BTFSC ADCON0,GO
GOTO INIT
MOVF ADRESH,0
MOVWF AD_VALUE1
MOVLW D'240'
SUBWF AD_VALUE1
BTFSS STATUS,C
GOTO RL_1
MOVLW B'00000000'
MOVWF PORTA
RL_1:
MOVLW D'220'
SUBWF AD_VALUE1
BTFSC STATUS,C
GOTO MAIN_ON
MOVLW b'00000001'
MOVWF PORTA
MOVLW D'200'
SUBWF AD_VALUE1
BTFSC STATUS,C
GOTO MAIN_ON
MOVLW b'00000011'
MOVWF PORTA
GOTO MAIN_ON
END