measuring input voltage


Closed Thread
Results 1 to 10 of 10
  1. #1
    thon's Avatar
    thon Guest

    Default measuring input voltage

    Hi everyone, I've downloaded a program that measures voltages from http://microengineeringlabs.com/resources/samples.htm (vmeterx.bas), to measure 0-5VDC with 10-bit ADC and display the voltage with 2 decimal places. Is this only applicable for ADC using 10-Bit because I am using only 8-bits. See code:

    ' Define ADCIN parameters
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50

    adval VAR WORD
    TRISA = %11111111
    ADCON1 = %10000010

    Pause 500

    loop: ADCIN 0, adval ' Read channel 0 to adval (0-1023)

    adval = (adval */ 500)>>2 ' equates to: (adval * 500)/1024
    LCDOut $fe, 1 ' Clear LCD
    LCDOut "DC Volts= ", DEC (adval/100),".", DEC2 adval ' Display the decimal value

    Pause 100 ' Wait .1 second
    GoTo loop ' Do it forever
    End


    Can someone help me, I want to measure that input voltage 0-5V using only 8-bits, the above code is only for 10-bits I guess, Is the code above applicable only for 10-bit? how do I measure voltage of inputs using 8-bits?

  2. #2
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi,

    Just remove the">>2" part.

    /Ingvar

  3. #3
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    DEFINE ADC_BITS 8

    this works !!!

  4. #4
    thon's Avatar
    thon Guest


    Did you find this post helpful? Yes | No

    Default

    Thank you guys for the response, they work fine...by the way I just have a question regarding LCD_bits. Im a little bit coonfused with:
    DEFINE LCD_BITS 8 vs. DEFINE LCD_BITS 4
    whats the difference between these two?

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    DEFINE LCD_BITS 8 vs. DEFINE LCD_BITS 4

    Determines if you want to have 8 or 4 wires going to your LCD (they are capable of either). Four bits saves on PIC-pins, interconnections, connectors etc but at the expense that each command or displayed byte is transferred 4 bits at a time therefore the event takes twice as long as with 8-bit transfer. Unless you have an application where writing to the LCD needs to be done at top speed (eg PIC version of Quake), 4-bits is adequate.

    Melanie

  6. #6
    winsthon's Avatar
    winsthon Guest


    Did you find this post helpful? Yes | No

    Talking

    Thank you guys for all the help...I appreciate it. I hope to ask again someday for my future projects...

  7. #7
    actionplus's Avatar
    actionplus Guest


    Did you find this post helpful? Yes | No

    Default Voltage

    Here a small problem I am facing with the same program from melabs.

    I have 1 PIC that measures the voltage right. When I program a different PIC16F877A, the voltage seems to move around, especially when I remove the battery. It does not go to 0 volts right away. It floats around for a few minutes then goes to 0 then elsewhere.

    I even tried reading of the PIC that work right and copying it to the new PIC and still does the same thing?

    Any solutions?

  8. #8
    G8RPI's Avatar
    G8RPI Guest


    Did you find this post helpful? Yes | No

    Default

    Hi,
    What circuit do you have connected to the PIC's ADC input?
    If it is just the test voltage (I guess you are using a 1.5V battery) then you will get strang results when you disconnect it. This is called a floating input. In the simplest terms the stary capacitances formed by the IC, PCB or protoboard etc. retain an indeterminate charge. This charge is altered by the leakage current of the IC. To get a true reading you need to provide a path to ground for this charge / current. If you have a potential divider at your input this will provide a discharge path for you. Otherwise add a resistor from the input to ground. The value depends on the PIC used and the application. I'd reccomend 10K as a resonable value. This also corresponds with the maximum input impedance specification for the ADC on 16F8xx PIC's. A 0.01uF across this capacitor will also help reduce noise etc.

    HTH,
    Robert G8RPI.

  9. #9
    actionplus's Avatar
    actionplus Guest


    Did you find this post helpful? Yes | No

    Default Floating input

    I just have a battery connected directly to it. 4.8V
    Then I just remove it and then the reading start to move around.
    I will try to terminate a 10k to the pin ans see what happens.

    Thanks

  10. #10
    actionplus's Avatar
    actionplus Guest


    Did you find this post helpful? Yes | No

    Default load voltage

    It seem to be a steady voltmater. can it test underload? Is there anyway to check the battery and then display that it will need recharge?

Similar Threads

  1. Temp readings and voltage input
    By ruijc in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 7th July 2008, 12:35
  2. Measuring voltage from a current transformer
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 5th May 2008, 21:19
  3. Help with final project
    By OvERKiLL in forum General
    Replies: 4
    Last Post: - 15th December 2006, 20:35
  4. Measuring Battery voltage
    By BobP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd December 2006, 23:07
  5. Measuring voltage
    By champion in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 16th November 2006, 13:24

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts