birlan97
Junior Member level 3
I have some problems with this voltmeter (value reading are not stable and are not linear).
I configured resistive divisor at imput 1 (AN0) to match lower limit voltage, but when I rise the voltage to be measured, the pic reading is lower than real voltage) and is not stable.
Could anubody help me ?
this is the code:
#include <16F876.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <flex_lcd.c>
unsigned long value,volts,amps;
float volts_read,amps_read;
void main() {
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
delay_ms(10);
value = 0;
volts = 0;
amps = 0;
lcd_init();
printf(lcd_putc,"\f");
printf(lcd_putc," Volts Amps \n");
do {
set_adc_channel( 0 );
volts = Read_ADC();
set_adc_channel( 1 );
amps = Read_ADC();
volts_read = (float)(volts * 23.5)/1023;
amps_read = (float)(amps * 3)/1023;
lcd_gotoxy(2,3);
printf(lcd_putc," %2.2f %2.2f ",volts_read,amps_read);
delay_ms(100);
} while (TRUE);
}
I configured resistive divisor at imput 1 (AN0) to match lower limit voltage, but when I rise the voltage to be measured, the pic reading is lower than real voltage) and is not stable.
Could anubody help me ?
this is the code:
#include <16F876.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <flex_lcd.c>
unsigned long value,volts,amps;
float volts_read,amps_read;
void main() {
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
delay_ms(10);
value = 0;
volts = 0;
amps = 0;
lcd_init();
printf(lcd_putc,"\f");
printf(lcd_putc," Volts Amps \n");
do {
set_adc_channel( 0 );
volts = Read_ADC();
set_adc_channel( 1 );
amps = Read_ADC();
volts_read = (float)(volts * 23.5)/1023;
amps_read = (float)(amps * 3)/1023;
lcd_gotoxy(2,3);
printf(lcd_putc," %2.2f %2.2f ",volts_read,amps_read);
delay_ms(100);
} while (TRUE);
}