Actually this is the another version of my older DVM project that was based on PIC12F683. The older version displays the measured voltage on a LCD that is driven serially by PIC12F683 using 3 I/O pins. The new one uses PIC16F688 microcontroller that doesn't require the serial driver as it has got enough pins to drive a LCD directly in 4-bit mode. The theory and math is just the same. You can read my PIC12F683 version of this project here.
Circuit Diagram
Important: You need a regulated +5V supply for accuracy of the output. The ADC uses Vdd as the reference for conversion, and all computations are done with Vdd = 5V. You can get a regulated +5V using a LM7805 linear regulator IC.
Read the detail theory and math involved in this project here.
Software
Use mikroC compiler to compile this code. Use options Internal Clock @ 4 MHz, MCLR Enabled, and Power-Up Timer Enabled.
/*
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);
}
Output
The DVM has been tested with various input voltages ranging from 0-20 V and found to be very accurate. Here are some of the pictures of testing.
Circuit Diagram
Circuit on breadboard
Important: You need a regulated +5V supply for accuracy of the output. The ADC uses Vdd as the reference for conversion, and all computations are done with Vdd = 5V. You can get a regulated +5V using a LM7805 linear regulator IC.
My source for a regulated +5V using LM7805
My variable power supply source for testing the DVM
Read the detail theory and math involved in this project here.
Software
Use mikroC compiler to compile this code. Use options Internal Clock @ 4 MHz, MCLR Enabled, and Power-Up Timer Enabled.
/*
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);
}
Output
The DVM has been tested with various input voltages ranging from 0-20 V and found to be very accurate. Here are some of the pictures of testing.
'
ReplyDeletevolt[0] = DisplayVolt/1000 + 48;
volt[1] = (DisplayVolt/100)%10 + 48;
volt[3] = (DisplayVolt/10)%10 + 48;
'
You can read more? What is +48?
+48 is to convert the numeric value to the equivalent character's ASCII value. The LCD is character display.
ReplyDeleteI am new to MikroC but have some experiance with PIC. Can you help me by explaining the following lines ?
ReplyDeleteDisplayVolt = 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);
Measured voltage is got on DisplayVolt, then what the need for next 3 lines.Lcd_Out(2,5,volt); will display the value of volt in 2nd line 5th position of LCD Display
volt[] contains the string of characters to be displayed (DisplayVolt is an integer) and you are right, it will display in the second row, 5th columns.
ReplyDeletei dont understand want means ICSP header?..and what are the connection pin from ICSP going??..
ReplyDeleteI am new and I had wanted to build it but you never listed all the components u used and how you arranged them on the board so I mind it pretty Hard yo try...
ReplyDeleteHow i can use this for -48V .....
ReplyDelete