divide two signals in pic 16f877

Discussion in 'Embedded Systems and Microcontrollers' started by pravvish, Sep 4, 2008.

  1. pravvish

    Thread Starter New Member

    Aug 12, 2008
    8
    0
    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...
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    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.
     
  3. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    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.
     
  4. pravvish

    Thread Starter New Member

    Aug 12, 2008
    8
    0
    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??
     
  5. pravvish

    Thread Starter New Member

    Aug 12, 2008
    8
    0
    WHAT PROGRAMMING SOFTWARE DO YOU USE FOR PIC?
    is it PIC basic?
     
  6. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    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: Sep 6, 2008
  7. pravvish

    Thread Starter New Member

    Aug 12, 2008
    8
    0
    the signal is around 50hz to 60hz so frequency is not a problem...
     
  8. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    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.
     
  9. pravvish

    Thread Starter New Member

    Aug 12, 2008
    8
    0
    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: Mar 4, 2009
  10. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    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.
     
  11. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Your frequency is low enough so can do it with the built-in ADC if the PIC.
     
  12. pravvish

    Thread Starter New Member

    Aug 12, 2008
    8
    0
    do you have any code or any sample program based on my problem??
     
  13. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    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.
     
  14. pravvish

    Thread Starter New Member

    Aug 12, 2008
    8
    0
    i saw the code ...


    i dont know c based programming thats why ...
     
    Last edited: Mar 4, 2009
  15. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    a=b/c;

    this means b divided by c and the quotient stored to a.
     
Loading...