swapan
Full Member level 4
Friends,
I have decided to make an automatic voltage stabilizer using 16F676. What I want to do is driving the electromagnetic relays of an automatic voltage stabilizer using PIC. Before proceeding further I wanted to carry a test of the adc module. For this purpose I have arranged in the following manner. Two relays are driven by RA0 and RA1. RC2/AN6 and RC3/AN7 are used for AD input. A 4.7K Pot is used as potential driver connecting to 5V supply rail and ground so that any value of AD Sampling voltage could be provided (0V to 5V) by rotating the pot. Now according to the code, when the AD input is 5V, both RA0 and RA1 will go low making the relays OFF. At a point where AD input is lower than D'220', RA1 will go high making one of the relays ON. Similarly, at a point where AD input is lower than D'200', both RA0 and RA1 will go high making all the relays ON. In practical, when the AD input is below D'200', both RA0 and RA1 is held high. On gradual rotating the pot, making AD input above D'200', RA1 becomes clear. Upto this, the operation is OK. But rotating the pot further, making AD input above D'220', the RA1 goes again high whereas as per code it should remain low. At AD input above D'240' both RA0 and RA1 should held low. But making the AD input about 5V (D'255') both RA1 and RA0 remain high. Please see if there is any error in my code.
Swapan
_CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _HS_OSC
cblock 0x20
AD_VALUE1
endc
I have decided to make an automatic voltage stabilizer using 16F676. What I want to do is driving the electromagnetic relays of an automatic voltage stabilizer using PIC. Before proceeding further I wanted to carry a test of the adc module. For this purpose I have arranged in the following manner. Two relays are driven by RA0 and RA1. RC2/AN6 and RC3/AN7 are used for AD input. A 4.7K Pot is used as potential driver connecting to 5V supply rail and ground so that any value of AD Sampling voltage could be provided (0V to 5V) by rotating the pot. Now according to the code, when the AD input is 5V, both RA0 and RA1 will go low making the relays OFF. At a point where AD input is lower than D'220', RA1 will go high making one of the relays ON. Similarly, at a point where AD input is lower than D'200', both RA0 and RA1 will go high making all the relays ON. In practical, when the AD input is below D'200', both RA0 and RA1 is held high. On gradual rotating the pot, making AD input above D'200', RA1 becomes clear. Upto this, the operation is OK. But rotating the pot further, making AD input above D'220', the RA1 goes again high whereas as per code it should remain low. At AD input above D'240' both RA0 and RA1 should held low. But making the AD input about 5V (D'255') both RA1 and RA0 remain high. Please see if there is any error in my code.
Swapan
_CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _HS_OSC
cblock 0x20
AD_VALUE1
endc
Code:
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