I'm a little new working with ADC so i need your help.
I'm trying to make an overvoltage, undervoltage and overload circuit. What concerns to voltage I have to regulate a trimmer in 2.5V that corresponds to 230V. If voltage goes above than 250V or under than 195V I have to turn on an led. What I did was
1024--------5V
x------------2.5V
x=409
230V---------409
250V----------y
y=446
230V---------409
195V---------z
z=348
In corrent I have to measure values between 0 and 15.9A. I have an output in voltage (0-5V) that´s proportional to the corrent it´s passing. What I did was
15.9 ---------- 5V
and 5V it´s 1024, so
15.9------1024
x---------ADC_value
x= (15.9*ADC_value)/1024
To voltage and corrent my code is:
DEFINE OSC 4 'o programa irá correr a 4MHz
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
ADC_corrente var word
ADC_tensao var word
corrente var byte
unid_corrente var byte
dec_corrente var byte
unidade var byte
decimal var byte
ADCON1 = $8D 'temos RA0 e RA1 como entradas analógicas e RA2, RA3 como referências e RA5 como entrada digital.
'o ADRESH tem 6 bits mais significativos a zero pág. 80 datasheet
TRISA = $0F 'SSSSEEEE - Porta A
TRISB = $FF 'EEEEEEEE - Porta B
TRISC = $0F 'SSSSEEEE - Porta C
porta.5 = 1
ADC:
ADCIN 0, ADC_corrente
ADCIN 1, ADC_tensao
if ADC_tensao < 348 then
portc.4 = 1
porta.5 = 0
endif
if ADC_tensao > 446 then
portc.5 = 1
porta.5 = 0
endif
if ADC_tensao > 348 && ADC_tensao < 446 then
portc.4 = 0
portc.5 = 0
endif
corrente = (159*ADC_corrente)/1024
unid_corrente = corrente / 10
dec_corrente = corrente // 10
Bookmarks