रविवार, 9 अगस्त 2015

DIGITAL_DC_VOLTMETER_USING_PIC16F887

                                                                                                                                 DC_Voltmeter_using PIC 16F887


Hi friend now we make a dc voltmeter to measure voltage at a point. Generally
Microcontroller measure voltage range (0-5V) . So we need input voltage less than equal to 5V. For make voltage in range of 5V. We can use voltage divider or preset

for Ex.  We need to measure voltage in range of 0-50V. Now we convert this voltage range 0-5V. We can use a preset of 47K ohm and take output of preset give to Micro- controller .Now set the preset as input is 50V and give output 5V.we use a zener of 5.1V with in pin to secure the Microcontroller. Connect the preset as in fig.



Hear a code of voltmeter in C lang.


 unsigned short convert(unsigned short y);
unsigned short x;
unsigned long  volt_sample = 0;           // long use becouse volt sample is not rang of intger
unsigned int voltage;
void main()
{
 TRISB = 0x00;                                   // port B as o/p
 TRISA = 0x08;                                   // portC.F3 as input
 TRISC=0x00;                                     // port c as o/p
 ANSEL = 0x08;                                 // i/p is analog
 ADC_Init();                                       // ADC Initialisation
 while(1)                                             // infinit loop
 {
  volt_sample = ADC_Read(3);          // Read analog input at AN3
  delay_ms(2);
  voltage=(volt_sample*500/1023);    // formula to convert ADC valu to 3 digit of i/p voltage

  x=voltage%10;
  PORTB=convert(x);

  PORTC=0x06;
  delay_ms(2);
  x=voltage/10;
  x=x%10;
  PORTB=convert(x);
  PORTC=0x05;
  delay_ms(2);
  x=voltage/100;
  PORTB=convert(x);
  PORTC=0x03;
  delay_ms(2);
  }
}
unsigned short convert(unsigned short y)
{
switch(y)
{
 case 0:
 return 0x3F;
 case 1:
 return 0x06;
 case 2:
 return 0x5B;
 case 3:
 return 0x4F;
 case 4:
 return 0x66;
 case 5:
 return 0x6D;
 case 6:
 return 0x7D;
 case 7:
 return 0x07;
 case 8:
 return 0x7F;
 case 9:
 return 0x6F;
}
 }


 NOT:-by using this voltmeter we can make any meter i.e. digital temperature meter,ac voltmeter etc.