Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Digital Voltmeter and Ammeter ( 350V/100A)

Status
Not open for further replies.

hamid159

Full Member level 3
Joined
Aug 25, 2013
Messages
176
Helped
14
Reputation
28
Reaction score
14
Trophy points
1,298
Location
Lahore
Activity points
2,488
Hi Guyz,
i am not understanding why my voltage on lcd is not constant..they are fluctuating within 0.7V range..when i measure e.g, 9V battery voltage,it shows 8.3 and then 9V and again and again...the same case with ammeter but now the range is 0.3A....There is also a problem with the voltmeter that when my terminals are floating,it shows 2.8V but when i short them it shows 0.0V..Please check my code if there is some problem ....
microcontroller used is pic16f688.
Any help would be highly appreciated..

Code:
sbit LCD_RS at RC4_bit;
sbit LCD_EN at RC5_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections


char *l,*m,*q,*v,y[7],u[7],n[7],o[7];
unsigned int k,j,i,b,a;
unsigned int e;
float x;
float t;

void main() {
TRISC = 0x00; // PORTC All Outputs
TRISA = 0b00000110; // PORTA All Outputs, Except RA1 and RA2
  ANSEL=0b00000110;
  ADCON1=0b00000000; // Fosc/8
  CMCON0 = 0x07 ; // Disbale comparators
  Lcd_Init();        // Initialize LCD
  //Lcd_Cmd(_LCD_CLEAR);             // CLEAR display
  Lcd_Cmd(_LCD_CURSOR_OFF);
  //Lcd_Out(1,7,"          ");       // Cursor off
  //Lcd_Out(1,1,Message1);
  //Lcd_Chr(2,10,'V');

//do {
while(1)
{
          ADCON0=0b00001001;
          Delay_us(50);
          ADCON0.GO_DONE=1;

          t = ADC_Read(2);

          k=t;


k=k*6.911961-3510.65;//0.48876;
if (t<509)
Lcd_out(1,7,"-");
else
Lcd_out(1,7," ");
j=k/10;
i=k%10;
inttostr(j,o);
inttostr(i,n);
l=ltrim(o);
m=ltrim(n);
if ((j<=99)&&(j>9)){
Lcd_out(1,8,l);
Lcd_out(1,10,".");
Lcd_out(1,11,m);
}
else if (j<=9)
{
      Lcd_out(1,8,l);
      Lcd_out(1,9,".");
Lcd_out(1,10,m);
//Lcd_out(1,13," ");
}
else
{
Lcd_out(1,8,l);
Lcd_out(1,11,".");
Lcd_out(1,12,m);
}
///////

ADCON0=0b00000101;
Delay_us(30);
ADCON0.GO_DONE=1;
x = ADC_Read(1);
e=x;
e=1.3*(e*3.42131*0.28572*2-1000)-2;//-20;
if (x<509)
Lcd_out(1,1,"-");
else
Lcd_out(1,1," ");
b=e/10;
a=e%10;
inttostr(b,y);
inttostr(a,u);
q=ltrim(y);
v=ltrim(u);
if ((b<=99)&&(b>9)){
Lcd_out(1,2,q);
Lcd_out(1,4,".");
Lcd_out(1,5,v);
//Lcd_out(1,5," ");
}
else if (b<=9)
{
      Lcd_out(1,2,q);
      Lcd_out(1,3,".");
Lcd_out(1,4,v);
//Lcd_out(1,4,"  ");
}
else {
Lcd_out(1,2,q);
Lcd_out(1,5,".");
Lcd_out(1,6,v);

}
   delay_ms(500);

  } //while(1);

 }

- - - Updated - - -

Circuit diagram is here
 

Attachments

  • hallsensor_ammeter.PDF
    38.5 KB · Views: 122

Fluctuations of a few LSB steps are normal operation with PIC built-in ADC. You need to average multple samples to get reduce the noise. For the explanation of DC offset, we should look at the schematic.
 

9V battery has maybe 10 Ohm series resistance depending on quality.
So voltage may drop with load.

Open circuit voltage into 10 or 1 Mohm DMM is from stray E field voltage.
 

Thanks FvM and SunnySkyguy...ok,i take the average of samples say 5..but how to make 2.8V zero..when i put the POT in parallel with R2..then it becomes zero but while shorting the terminals 0-2.8 = -2.8V is shown on LCD.
 

I used for filter R4 =1k and C1=0.01 uf ( 100nf) and I did not use R3 and I further connected output to 5v zener diode for over voltage protection

I also used filter circuit very closed to the Op-amp Vcc

Even though it is using internal reference voltage, usually I observed that the output fluctuation depend on the non stability of reference voltage
 

Expecting noise-free measurements with processor internal ADC is inappropriate. You can affect it to certain degree by setting ADC parameters, or even pausing the processor during measurement. At the end of the day, you get 8 or 9 Bit accuracy for the unfiltered 10 Bit-ADC values.

The 2.5 V Offset is caused by design of the biased voltage divider. You'll either modify the circuit or ignore an offset with open input because the input will be always connected in normal operation.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top