How to read analog signals?


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Here's an example of reading an analog voltage with a 12F683. I'll let you figure out the LED part...;}
    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    
        DEFINE OSC 8            ' Internal 8MHz 
        DEFINE DEBUG_REG GPIO   ' Define DEBUG port
        DEFINE DEBUG_BIT 1      ' Set GPIO.1 as DEBUG serial output pin
        DEFINE DEBUG_BAUD 9600  ' DEBUG baud rate = 9600 bps
        DEFINE DEBUG_MODE 1     ' 1 = inverted, 0 = true
        
        DEFINE  ADC_BITS 10     ' 10-bit resolution
        DEFINE  ADC_CLOCK 5     ' Set clock source to Frc/16
        DEFINE  ADC_SAMPLEUS 50 ' Sample time in uS before A/D conversion is started
        Quanta  CON 1251        ' For 10-bit A/D +Vref = 5V : 5V/1023*256=1.251=Quanta
    
    ' PIN# NAME     USE & CONNECTION
    '  1   Vdd      +5VDC power supply
    '  2   GPIO.5   N/C (N/C = NO CONNECTION)
    '  3   GPIO.4   N/C
    '  4   GPIO.3   N/C
    '  5   GPIO.2   N/C
    '  6   GPIO.1   Serial output pin to PC serial port RX pin
    '  7   GPIO.0   A/D input pin
    '  8   Vss      Power supply ground (also connect to DB-9 pin #5)
    '-------------------------------------------------------------------------
    
        CMCON0 = 7          ' Disable comparator
        ANSEL = %00000001   ' Set GPIO.0 to A/D
        ADCON0.7 = 1        ' Right justify for 10-bit
        TRISIO = %00000001  ' GP.1 = serial out, GPIO.0 = A/D in, rest outputs
        OSCCON = %01110000  ' Internal 8MHz osc
        ADval  VAR WORD	' A/D conversion result
    
    MAIN:
        ADCIN 0, ADval      ' Read A/D
        ADval = ADval */ Quanta
        DEBUG DEC ADval DIG 3,".",DEC3 ADval,"~"
        PAUSE 200
        GOTO MAIN
    
        END
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Dec 2008
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Hey bruce thanks a lot Bielive it or not i learned a lot form that small little part I as wondering if You can read the analog and pulse low on the same pin?

  3. #3
    Join Date
    Dec 2008
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    I did a little bit more research on this But its pretty hard what i wanted to do is read a analog voltage off a circiut board andif that reading is true I want it to pulse low through the same pin reading the voltage will this be possible?


    edit: bruce can you help me explain what ever line means it will give me a betetr understanding of how to see if i can use the if then statment to flash the led
    Last edited by thm ov3rkill; - 23rd February 2009 at 03:39.

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by thm ov3rkill View Post
    I did a little bit more research on this But its pretty hard what i wanted to do is read a analog voltage off a circiut board andif that reading is true I want it to pulse low through the same pin reading the voltage will this be possible?


    edit: bruce can you help me explain what ever line means it will give me a betetr understanding of how to see if i can use the if then statment to flash the led
    Here is the hangup in your question:In English, True / False statements are digital statements, so when you say, "and if that reading is true ". . . we are not sure what you want "true" to represent. Please explain further . . . Does " true" represent a specific voltage, or just any voltage? Are you trying to test for a specific voltage? Bruce gave you the code above to receive the value of the voltage, so what do you want to do with that information?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Dec 2008
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    well joe thanks for replying what I want to do is... I want to be able to test a analog voltage peroid. And if that analog volatge is in fat true then I want it to pulse low out of the same pin testing that voltage.

    edit i dont want to see how much the voltage is i want to see when it read analog
    Last edited by thm ov3rkill; - 23rd February 2009 at 23:31.

  6. #6
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Possible translation

    edit i dont want to see how much the voltage is i want to see when it read analog
    I'm taking a stab at this. I believe when you say "true" you are wanting to say "through", meaning "complete" or "done", is this correct?
    And if that is the case, then it can be done but your circuit will have to be made to monitor your analog signal and have an LED at the same pin.
    It would be simpler to use one pin for the analog signal input then turn ON an LED on another pin (setup as an output) when the A/D is completed or "through".
    Louie

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by thm ov3rkill View Post
    I want to be able to test a analog voltage peroid.
    Ok you want to test an analog voltage, what are you testing for? Do you mean any value greater than zero ?
    And if that analog volatge is in fat true then I want it to pulse low out of the same pin testing that voltage.

    edit i dont want to see how much the voltage is i want to see when it read analog
    So if I understand correctly . . .
    Code:
     
    If voltage is > 0 then
    PortA.0 = 0 'set port latch to low status before enabling tris
    TRISA.0 = 0 ' Turn input into output enabling port to pull low.
    else
    TrisA.0 = 1 ' Keep port in high impedance input status
    endif
    Where PortA.0 in this example is your analog input / output port
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8
    Join Date
    Dec 2008
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Hey joe Well this is the thing I want to setup a little project . You may remmeber me from the xbox 360 thread. But i didint get a chance on that. So i wanted to seeif i can acually get to read the trigger press and pulse out.


    Also I wanted this to be done on a pic 12f683

    Well The reason i want it on the same pin because I dont think i can kill 2 birds with one stone meaning as There is only on spot to read and fire of the controller which is called the wiper. I have seen this done before. So lets say i pull the trigger the pic reads the analog then it pulses low.

Similar Threads

  1. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  2. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  3. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  4. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  5. analog read
    By swordman in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 12th August 2004, 19:37

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