Digital Voltmeter

Discussion in 'Embedded Systems and Microcontrollers' started by mikecy, Apr 28, 2010.

  1. mikecy

    Thread Starter New Member

    Apr 28, 2010
    8
    0
    Hi to all.I have to build a project about a digital voltmeter and amper meter and send data to pc.I will have 3 volt input from -12v to 12v and 4 amper meter from -1A to 1A.From a quick research i did i decided to use the 16f877 pic.For the ampers i will use a current sensor.My questions are.How can i measure negative voltage? and what i need for rs232 communication with pc(max232)?
    p.s.I will use vb2008
    thanks
     
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    the MAX232 is a fine choice for RS232 communications.

    Be sure to use a highly rated resistor for your sensing resistor. On a little circuit I built, I used a 50W 1ohm 1% resistor. I think I paid $4us for it.

    You can build a voltmeter, then measure the voltage across the resistor to get the amperage. You can work this into the design fairly easily. Especially if you use a switch to select Volts and Amps.

    With the AMPs selection, you are addind the resistor to the mix, and still "reading" volts but displaying AMPS.
     
  3. mikecy

    Thread Starter New Member

    Apr 28, 2010
    8
    0
    thanks for the answer.but my main concern is how to read the negative volt for example -5 volts?
     
  4. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    You cant measure negative voltages directly with a PIC 877.

    You need to shift it to an area within your ADC.
     
  5. mikecy

    Thread Starter New Member

    Apr 28, 2010
    8
    0
    Do you know how can i do that?sorry for all the question but i didn't find anything.And the max232 is neccesary?because i saw a few circuits that connected the pic directly to rs232
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Without the max232 it might work on some PCs. If you are using the USART for communications, it's output is inverted because the MAX232 inverts the signals, so you would have to use a couple of transistors.
    May as well just get the MAX232, they are only cheap.
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I think it is wise to play safe and use a MAX232 type circuit. At least you will know that the signals levels are OK. RS232 can sometimes be quite pesky to debug, so it is wise to eliminate error sources. Also remember to read the data sheet even if you program the PIC in C. Not all RS232 transmission speeds can be achieved. This will depend on PIC osc speed
     
  8. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Use a precision rectifier to rectify the measured voltage and then feed it to the PIC. In this way, the voltage to the PIC will be always positive. Also, use a comparator to indicate the PIC if the voltage measured is positive or negative.
    It would be good to use an op amp buffer circuit at the front end of the measuring circuit as to minimize the input current of the measuring circuit and achieve measurements which are closer to the actual value. Also, the PIC ADC resolution is 10-bits which gives an accuracy of 4.88mV. If you want to measure voltages less than 4.88mV accurately then you need to use an external ADC chip with higher resolution and send the data to the PIC unless you can find a PIC with a higher resolution.

    If it is a school project, then the PIC is adequate because you just want to show it is working.
     
  9. mikecy

    Thread Starter New Member

    Apr 28, 2010
    8
    0
    thank you all.You have been very helpful.I will give it a try..
     
  10. mikecy

    Thread Starter New Member

    Apr 28, 2010
    8
    0
    Hi again.I finnaly made it.But the problems keeps going on.this is my code
    Code ( (Unknown Language)):
    1. #include <16F877.h>
    2. #fuses HS,NOWDT,NOPROTECT,NOLVP
    3. #use delay(clock=4000000)
    4. #use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
    5.  
    6. void main()
    7. {
    8. long int value;
    9. unsigned long int value1;
    10. int8 i;
    11.    setup_adc_ports(AN0);
    12.    setup_adc(ADC_CLOCK_INTERNAL);
    13.    setup_psp(PSP_DISABLED);
    14.    setup_spi(FALSE);
    15.    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
    16.    setup_timer_1(T1_DISABLED);
    17.    setup_timer_2(T2_DISABLED,0,1);
    18.  
    19.    // TODO: USER CODE!!
    20.   while(TRUE){
    21.  
    22. value1=read_adc();
    23. value=(value1/255)*(5);
    24. delay_ms(200);
    25. printf("value:%3lu, binVALUE:%3lu\r\n",value,value1);
    26. delay_ms(1000);
    27. }
    28. }
    29.  
    Now somethings wrong.First of all it doesn't show me the real value.it shows random values.why that?
     
    Last edited: May 7, 2010
Loading...