# Displaying voltage & current in LCD using ADC pic18f452

Status
Not open for further replies.

#### Cheng

##### New Member
Hi all!

We are doing a project to display voltage & current values which are input from a 10k potentiometer into a PIC18f452 and outputting them into readable data on a LCD. We have been told that the chip can only detect and convert the voltage values but not the current's. Does anyone have any suggestions on how to find the current values?

#### ericgibbs

##### Well-Known Member
Hi all!

We are doing a project to display voltage & current values which are input from a 10k potentiometer into a PIC18f452 and outputting them into readable data on a LCD. We have been told that the chip can only detect and convert the voltage values but not the current's. Does anyone have any suggestions on how to find the current values?

hi,
One way is to use a low value resistor in the current path and then measure the voltage across the resistor.
The resistor is usually in series withthe 0V line.

Using ohms law the current can be calculated.

Last edited:

#### Cheng

##### New Member
Thanks for the reply Eric! Actually what our project does is acting like a multimeter. We do not have external measuring devices to measure voltage, current or resistor values, just the chip itself. Is there any way that the chip could calculate the voltage and current values just by programming the pic18 to read the data inputs from the pot?

#### ericgibbs

##### Well-Known Member
Thanks for the reply Eric! Actually what our project does is acting like a multimeter. We do not have external measuring devices to measure voltage, current or resistor values, just the chip itself. Is there any way that the chip could calculate the voltage and current values just by programming the pic18 to read the data inputs from the pot?

hi,
The resistor/current method is the way many modern DMM's work.

I assume you are using a PIC with ADC inputs.?

The PIC cant measure/read a pots resistance value directly, it has to be done measuring the voltage between the pot wiper and 0V.

Can you give us an example on how you want the PIC to measure the current.?

#### Cheng

##### New Member
Ya we're using microchip's pic18F452 with A/D inputs. And yes we have exactly no idea how we're going to measure the current with no external measuring equipments. Thus our post here. Except that we know we're not supposed to use any external measuring equipments, other than for testing purposes to find out whether our circuit is accurate. Here's a schematic drawing:

[/URL][/IMG]

Also, can you explain what u meant by "it has to be done measuring the voltage between the pot wiper and 0V."? Do you mean measuring using a multimeter? I'm sorry for all the trouble coz all our teammates have no idea what's going on except for a bit of the programming.

#### ericgibbs

##### Well-Known Member
We are doing a project to display voltage & current values which are input from a 10k potentiometer into a PIC18f452 and outputting them into readable data on a LCD. We have been told that the chip can only detect and convert the voltage values but not the current's. Does anyone have any suggestions on how to find the current values?

hi,
Looking at your diagram.

You show two 10K0 variable resistors connected between +5V and 0V, with the slider/wiper of the pots going to a ADC inputs.

Which current are you trying to measure.?

The current thru each pot is I = V/R = 5/10000 = 0.5mA [ 500µA].
The current into the PIC's ADC is very very small and could be considered as zero.

Answer: current into the ADC input = 0.0

Last edited:

#### Cheng

##### New Member
Thanks for the reply Eric. We're trying to measure the current running through each pot. Actually when the resistance of the pot is varied via the wiper/swiper, the current and voltage changes too right? Therefore all the changes must be concurrently displayed via our LCD. We are gonna try connecting: pin1 of the pot to ground, pin2 to PORTA aka the ADC input, and pin3 to 5V. I'll let you know the results once we've tried it out, about 2 days later. =)

#### ericgibbs

##### Well-Known Member
Thanks for the reply Eric. We're trying to measure the current running through each pot. Actually when the resistance of the pot is varied via the wiper/swiper, the current and voltage changes too right? Therefore all the changes must be concurrently displayed via our LCD. We are gonna try connecting: pin1 of the pot to ground, pin2 to PORTA aka the ADC input, and pin3 to 5V. I'll let you know the results once we've tried it out, about 2 days later. =)

hi,
As the 10K0 pot is a fixed value and the input resistance of the ADC is very high the current will NOT change
as you vary the position of the pot.

The current thru the pot will always be 5V/10000 = 500uAmps.!

I would recheck the assignment details, I think you must have misread it.

EDIT: please attach your images to the post by using the 'Manage Attachments' button

Last edited:

#### Cheng

##### New Member
Hi. We've jumped to the programming part of our project as we've not much time left, and the programming usually takes a lot more time (for us). Any help with the programming would be appreciated. We're using pic18F452 with the picdem 2 plus demo board. Our input would be that from the circuit with the pot mentioned above but right now we're using the pot connected via RA0.

Code:
#include <p18xxxx.h>
#include <delays.h>
#include "lcd.h"
#include <string.h>

#define LCD_RS PORTAbits.RA3
#define LCD_EN PORTAbits.RA1
#define LCD_WR PORTAbits.RA2

#define set_dd_line1_pos1 0x80
#define set_dd_line2_pos1 0x80

char value1 [ ] = "0V";
char value2 [ ] = "5V";

void lcd_write_cmd(unsigned char cmd)
{
unsigned char temp2;
LCD_RS = 0;
Delay10TCYx(4);

temp2 = cmd;
temp2 = temp2 >> 4;
PORTD = temp2 & 0x0F;

Delay1KTCYx(1);
lcd_strobe();
Delay1KTCYx(1);

temp2 = cmd;
PORTD = temp2 & 0x0F;

Delay1KTCYx(1);
lcd_strobe();
Delay1KTCYx(1);

}

void lcd_clear(void)
{
lcd_write_cmd(0x01);
Delay1KTCYx(2);

}

void lcd_write_data(char data)
{
char temp1;

LCD_RS = 1;
Delay10TCYx(4);

temp1 = data;
temp1 = temp1 >> 4;
PORTD = temp1 & 0x0F;

Delay1KTCYx(1);
lcd_strobe();
Delay1KTCYx(1);

temp1 = data;
PORTD = temp1 & 0x0F;

Delay1KTCYx(1);
lcd_strobe();
Delay1KTCYx(1);

}

void lcd_goto(unsigned char LCD_POS)
{
lcd_write_cmd(LCD_POS);
Delay1KTCYx(2);

}

void lcd_strobe(void)
{
LCD_EN = 1;
Delay10TCYx(4);

LCD_EN = 0;
Delay10TCYx(4);
}

void lcd_init(void)
{
LCD_RS = 0;
LCD_WR = 0;

Delay1KTCYx(250);
Delay1KTCYx(250);
Delay1KTCYx(250);
Delay1KTCYx(250);

PORTD = 0x03;

lcd_strobe();
Delay1KTCYx(250);

PORTD = 0x03;
lcd_strobe();
Delay1KTCYx(250);

PORTD = 0x03;
lcd_strobe();
Delay1KTCYx(250);

PORTD = 0x02;
lcd_strobe();
Delay1KTCYx(250);
Delay1KTCYx(250);

lcd_write_cmd(0x28)

lcd_write_cmd(0x01);
Delay1KTCYx(20);
Delay1KTCYx(20);
lcd_write_cmd(0x0F);

Delay1KTCYx(20);

lcd_write_cmd(0x06);

Delay1KTCYx(20);
}

main(void)
{

char outchar;
unsigned char Sizevalue1, Sizevalue2, Sizevalue3;
unsigned char index;
#define constant [B]0x01[/B]
#define constant2 [B]0x05[/B]

TRISA = 0x00;
TRISD = 0x00;

PORTD = 0x00;

for(;;)
{

{
Sizevalue1 = strlen(value1); // get size of array
LCD_EN = 0;
LCD_RS = 0;
LCD_WR = 0;
lcd_init();
LCD_RS = 1;

lcd_goto(set_dd_line1_pos1);
for (index = 0; index < Sizevalue1; index++)
{
outchar = value1[index];
lcd_write_data(outchar);
}
Delay1KTCYx(250);
Delay1KTCYx(250);
Delay1KTCYx(250);
lcd_goto(set_dd_line1_pos1);
lcd_clear();
}

{
Sizevalue2 = strlen(value2);
LCD_EN = 0;
LCD_RS = 0;
LCD_WR = 0;
lcd_init();
LCD_RS = 1;

lcd_goto(set_dd_line1_pos1);
for (index = 0; index < Sizevalue1; index++)
{
outchar = value2[index];
lcd_write_data(outchar);
}
Delay1KTCYx(250);
Delay1KTCYx(250);
Delay1KTCYx(250);
lcd_goto(set_dd_line1_pos1);
lcd_clear();
}
}
}

I've managed to display 0V and 5V on the lcd when i turn the wiper of the pot CCW or CW completely. Now I'm trying to detect 1V when I'm adjusting the wiper but there are 2 problems. Firstly, As you can see from my programming, my constant values are 0x01 and 0x05, which I assume should read analog inputs of lower than 1V and higher than 5V. (Am I right?) It works on the program but still would like to double check it. My second problem is designing a subroutine to detect the 1V. How should I go about it?

Last edited:

#### stereovestro

##### New Member
hi.... im using mplab ide

im intersted with you code. how can i alter ur code to fit into mplab software?

#### Pommie

##### Well-Known Member
That code will work in MPLAB as long as you select the C18 compiler. If you don't have the C18 compiler you can download a free version from Microchip.

Mike.

#### stereovestro

##### New Member
alright thnx pommie!
i tink i did already download the c18 compiler. under:

Project> set language tool location >Microchip C18 toolsuite>executables> MPlab C18 C compiler(mcc18.exe)

this is what ive selected.
when i build that code, error is here #include "lcd.h" unable to locate lcd.h.

so wat need to be change?

#### Pommie

##### Well-Known Member
You can remove the include "LCD.h" and just put the prototypes at the top of the file or, you can make an LCD.h file that contains the prototypes.

Mike.

#### MrDEB

##### Well-Known Member
This website has exactly what your looking for but a different PIC
BUT it measures voltage, current, frequency etc. look at the super probe
Mondo Technology - Pic Projects
It has the code, just need to convert for the desired PIC

#### stereovestro

##### New Member
alright thnx....

but in mondo technology, it uses seven segment output. i need to display voltage, current and temperature in 1 lcd16x2. i can figure that out.

but what i need to understand now is; for sensing the voltage and current, which type of ic is needed. im using microcontroller pic 18f4520. can those ic connected to pic18f4520?

#### Pommie

##### Well-Known Member
If you learn how to program the chip then you will be able to make it do whatever you want. You do not need another chip, the chip you have can do what you want. Try to write some code and then post it here. If it doesn't work we will help you to get it working.

Mike.

Status
Not open for further replies.

Replies
0
Views
846
Replies
1
Views
1K
Replies
4
Views
1K
Replies
2
Views
1K
Replies
6
Views
1K