Help regarding 16F688 LCD Voltmeter...

Status
Not open for further replies.
HI all

I just make the voltmeter. But how it convert to measure 0 to 2000 mV (0-2 V)? .

and this is the code the author supplied..

Code:
/*
  Digital Voltmeter based on PIC16F688
  Rajendra Bhatt, Oct 12, 2010
*/

// LCD module connections
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 Message1[] = "DVM Project";
unsigned int ADC_Value, DisplayVolt;
char *volt = "00.0";

void main() {
  ANSEL = 0b00000100; // RA2/AN2 is analog input
  ADCON0 = 0b00001000; // Analog channel select @ AN2
  ADCON1 = 0x00;
  CMCON0 = 0x07 ; // Disbale comparators
  TRISC = 0b00000000; // PORTC All Outputs
  TRISA = 0b00001100; // PORTA All Outputs, Except RA3 and RA2
  Lcd_Init();  // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);  // CLEAR display
  Lcd_Cmd(_LCD_CURSOR_OFF);  // Cursor off
  Lcd_Out(1,1,Message1);
  Lcd_Chr(2,10,'V');

do {

  ADC_Value = ADC_Read(2);
  DisplayVolt = ADC_Value * 2;
  volt[0] = DisplayVolt/1000 + 48;
  volt[1] = (DisplayVolt/100)%10 + 48;
  volt[3] = (DisplayVolt/10)%10 + 48;
  Lcd_Out(2,5,volt);
  delay_ms(100);
  } while(1);

}

[code]
 
Last edited:
Its work perfect....

this is the actual link...

https://www.electronics-lab.com/project/pic16f688-digital-voltmeter/





and this is the calculations.....


The accuracy depends upon the accuracy of the resistors at the input end and the stability of reference voltage, Vdd = +5V. I found Vdd is stable to +5.02 V. I measured R1 and R2, and their values are 1267 and 3890 Ohms. So this gives,



0 – 5.02 V Analog I/P ---> 0-1023 Digital Count

=> Resolution = (5.02 - 0)/(1023-0) = 0.004907 V/Count

Va = 1267*Vin/(1267+3890) = 0.2457*Vin

=> I/P voltage = 4.07*Va = 4.07* Digital Count * 0.004907

= 0.01997 * Digital Count

= 0.02*Digital Count (Approx.)


To avoid floating point, use I/P voltage = 2*Digital Count.


Example, suppose Vin = 7.6V. Then,

Va = 0.2457*Vin = 1.87V

=> Digital Count = 1.87/0.004907 = 381

=> Calculated I/P Voltage = 2*381 = 0762 = 07.6V (First 3 digits of 4 digit product)



Thanks in Advance.....
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…