ADC question


Closed Thread
Results 1 to 3 of 3

Thread: ADC question

  1. #1
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    70

    Default ADC question

    I am trying to read a voltage using the 16F88. The signal I am reading is a 180Hz PWM signal that is TTL level. No matter what I set my sample time to, I either get the voltage as 0 or 1024. I have tried adjusting the sample time at 50, 1111, and 5555 all with the same results. My thinking was 180 Hz would be about 5.5 ms. 5555 would be 5.5 ms. I even tried using an array to pull in 10 samples and take an average which didn't work either. Here is a couple programs I tried. Any suggestion would be appreciated. thanks.

    Here was the array attempt:
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 1111 ' Set sampling time in uS
    DEFINE OSC 4 ' 4MHz crystal
    INCLUDE "modedefs.bas"
    TRISA = %11111111 ' Set register A as input
    ADCON1 = %10000010 ' Set up register output
    fuel VAR WORD[10]
    x VAR BYTE
    average VAR WORD
    average=0

    loop:
    average = 0
    For x=1 TO 10
    ADCIN 0,fuel[x] ' Read channel 0 to fuel
    Next x

    For x=1 TO 10
    average=average+fuel[x]
    Next x
    average=average/10


    SerOut PORTB.2,n9600,[1,#average" "]
    GoTo loop

    Here was not using the array:
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 1111 ' Set sampling time in uS
    DEFINE OSC 4 ' 4MHz crystal
    INCLUDE "modedefs.bas"
    TRISA = %11111111 ' Set register A as input
    ADCON1 = %10000010 ' Set up register output
    fuel VAR WORD

    loop:
    ADCIN 0,fuel ' Read channel 0 to fuel


    SerOut PORTB.2,n9600,[1,#average," "]
    Pause 200
    GoTo loop

  2. #2
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    A raw PWM signal is either ON or OFF for varying amounts of time so therefore with a 5v source you will read either 0V or 5v depending on where you sample the signal.

    To read an anlogue voltage the PWM signal would need to filtered with a resistor and capacitor to smooth it to an analogue voltage.
    Keith

    www.diyha.co.uk
    www.kat5.tv

  3. #3
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    That was kind of what I was thinking, but it has been 5 years since college now and I have forgotten how to do all that. I actually found a better way. I am using the pulsin command to measure the on time. Seems a lot more accurate and quicker. Thanks for the advice.

Similar Threads

  1. PIC16F690 ADC question
    By matador29b in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd October 2009, 23:03
  2. Newbie HPWM / ADC question
    By Johan in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 25th June 2007, 12:52
  3. ADC question
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 8th June 2007, 09:52
  4. A question about ADC (using Pic16f876)
    By mimmmis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd April 2007, 16:26
  5. strange adc question
    By maus in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th November 2006, 10:57

Members who have read this thread : 1

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