divide two signals in pic 16f877

Thread Starter

pravvish

Joined Aug 12, 2008
8
can anyone please help me with this?

i have two analog inputs to A2D converter in pic16f877

i want to divide signal in channel a by signal in channel b

can any one help me with this??

i asked many no one seems to know how ....

my aim is to display the result in an 2x16 LCD ...

eg: 1.6v divided by 5 = .32 so thats what i want displayed on he lcd...

but no one seems to know how to do it ...
please please help me...
 

beenthere

Joined Apr 20, 2004
15,819
You need an analog switch controlled by the uC so you can convert the signals separately. First signal A and then signal B. Use the numeric values that result for the division.

It is possible to get an IC that will do the division, but switching the input signals is much easier to achieve. Analog Devices makes many switches.
 

mik3

Joined Feb 4, 2008
4,843
You can read the one analog signal with analog port A0 (for example) and the other analog signal with analog port A1 (for example). Then take the readings and divide them. See an example code below:

set_ADC_channel(0);
delay_us(10);
a=read_adc();


set_ADC_channel(1);
delay_us(10);
b=read_adc();

c=a/b;


This is a part of the program, you have to identify the variables a,b and c are long numbers.
 

Thread Starter

pravvish

Joined Aug 12, 2008
8
the problem is that i want a fraction display and how can i divide the two signals in pic ???can any one give me any code samples??
 

Thread Starter

pravvish

Joined Aug 12, 2008
8
You can read the one analog signal with analog port A0 (for example) and the other analog signal with analog port A1 (for example). Then take the readings and divide them. See an example code below:

set_ADC_channel(0);
delay_us(10);
a=read_adc();


set_ADC_channel(1);
delay_us(10);
b=read_adc();

c=a/b;


This is a part of the program, you have to identify the variables a,b and c are long numbers.
WHAT PROGRAMMING SOFTWARE DO YOU USE FOR PIC?
is it PIC basic?
 

AlexR

Joined Jan 16, 2008
732
If your inputs are varying voltages then the simple answer is it can't be done with the PIC16/18 chips. They only have a single AtoD converter (lots of AtoD ports but only one converter) and can only convert one waveform at any one time. Also the conversion process takes a fairly long time so unless you are working at fairly low frequencies and a low resolutions you won't see the detail in the waveform.

If however the inputs are DC levels then you can connect each to a separate AtoD port and convert them one at a time. Take a look at this site for tips on how to do the actual division using fixed a decimal point.
 
Last edited:

AlexR

Joined Jan 16, 2008
732
Since the signal is not a DC level you can't process it with a single AtoD converter. Probably your best bet would be to do the division of the two signals in analogue hardware (use something like a AD633 four quadrant multiplier to do the division) and then feed the divided signal to the PIC.

Another option is to go for a device with 2 AtoD converters. Some of the dsPIC33F family have 2 AtoD converters.

A third option is to feed the signals to a sample/hold circuit, sample both waveforms at the same time then process them sequentially. I have a feeling that the processing will take too much time to produce meaningful results but since you are working with low frequencies it just might work.
 

Thread Starter

pravvish

Joined Aug 12, 2008
8
ok ... i use an rms to dc converter to convert the ac to dc before feeding to pic ..

so now can i do that ??
 
Last edited:

mik3

Joined Feb 4, 2008
4,843
WHAT PROGRAMMING SOFTWARE DO YOU USE FOR PIC?
is it PIC basic?
No, my code is in C. I use MPLAB IDE to compile the code and then i use WinTop to load the code on my PIC. I use WinTop to load the code on my PIC because i have the TOP2049 programmer, you can use any other software and programmer to load it.
 

mik3

Joined Feb 4, 2008
4,843
do you have any code or any sample program based on my problem??
I gave you an example on post #3. This is a part of the whole code. With this code, you read an analog input each time but because it happens too fast (if the uC has not to execute a long before it repeats the analog readings again) and your frequency is low the accuracy will be accurate. Now, if you want to show the result on a display you have to do more alone. I have never used an LCD yet. Be careful your voltage on the analog inputs varies between 0 and 5 volts as not to destroy the uC.
 

Thread Starter

pravvish

Joined Aug 12, 2008
8
I gave you an example on post #3. This is a part of the whole code. With this code, you read an analog input each time but because it happens too fast (if the uC has not to execute a long before it repeats the analog readings again) and your frequency is low the accuracy will be accurate. Now, if you want to show the result on a display you have to do more alone. I have never used an LCD yet. Be careful your voltage on the analog inputs varies between 0 and 5 volts as not to destroy the uC.
i saw the code ...


i dont know c based programming thats why ...
 
Last edited:
Top