Help with pressure sensor.


Closed Thread
Results 1 to 27 of 27
  1. #1
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113

    Default Help with pressure sensor.

    Well I have to be about the dumbest person and why this eluding me on how to correct this is beyond me. Anyway I am working with a 16f877 and I've got a pressure sensor thats range is .5vdc to 4.5vdc and I am trying to get the full range of the AD but I am stuck. It works perfectly when I hook it up my AD output reads .47v which is perfect since there is some degree of percission. I don't know why they don't make these to read 0v to whatever but they don't So my quesiton is how to programatically drop that first .5v and still take advantage of the entire 1-1024 range of the AD converter or is there a better way?


    Thank you.
    David

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113


    Did you find this post helpful? Yes | No

    Default It helps tremendously a few more mental blocks though....

    Quote Originally Posted by mackrackit View Post
    Mack, That does help allot thank you. I am an amateur at best and not a good one, but I try. I am starting to understand the math. I do read the datasheets, I don't always understand them but I read them and try none the less. The part I am having difficulty is with the settings of ADCON0 and ADCON1 and setting of VREF. I am getting readings and it seems that proportinatly it goes up as the PSI goes up. I've incorporated your suggested math into my program thanks. The problem I think I am having is the VREF is and one or more of the bits I have set in ADCON? is not correct. At a dead stop with 0 psi I get a reading and that most likely is proportinate to the
    .47 vdc the voltmeter is telling me the sensor is putting out and being presented to RA0. Ok now the dumb questions: Do I need to actually present a +V and -V on RA3 and RA2 or as I understand it setting ADCON1.0 through .3 to 0000 sets it up to use the Vdd and Vss the pic is using itself?
    I thought the range would be 0 to 1024 not 0 to 256 why did I think that?
    I thank you for your help.
    David

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Lets go with small steps and we will come back to the 10 bit resolution~1024.

    And lets not worry about the VREF for now. That will take extra hardware to setup the reference voltage. When we get there all you will need for your application is V+.

    Read through these two links, Bruce makes very nice tutorials.
    This one is using your chip but does not use the ADCIN command. I like this way and it will help you to understand how the ADC works.
    http://rentron.com/PICX2.htm

    This one is using ADCIN and a different PIC, but will help with your understanding.
    http://rentron.com/serial.htm

    Get some of the above working and post the code you have. Then we will go for the 10 bit stuff.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113


    Did you find this post helpful? Yes | No

    Default Baby steps gotcha.. here goes.

    Mack, I acutally started my project with this example from Bruce good call. I did not completely understand it but I did in fact hook up a 5k pot to my board to see how the ADC worked.

    This time I pretty much did this line for line with my pressure sensor attached to see how it would react. I am getting a reading. My volt meter is reading .47vdc from the sensor. The serout is bouncing back and fourth between 24 and 25. I would assume that the way Bruce's program is set its 0-255 analog output I would then assume that if my sensor was .5 to 4.5 then the full range of the output would be 4/255 or .0156 volts per increment of the 255 this 24*.0156 = .3744. I think my math is correct there from your previous example but since I can see/know that my sensor is putting out .47 I either did something slighlty wrong or... I've got a mistake in my program.

    P.S. Thanks for the help.
    David

    INCLUDE "modedefs.bas"
    ' Hardware specific settings
    @ DEVICE pic16F877, XT_OSC ' System Clock Options
    @ DEVICE pic16F877, WDT_ON ' Watchdog Timer
    @ DEVICE pic16F877, PWRT_ON ' Power-On Timer
    @ DEVICE pic16F877, BOD_ON ' Brown-Out Detect
    @ DEVICE pic16F877, LVP_ON ' Low-Voltage Programming
    @ DEVICE pic16F877, CPD_OFF ' Data Memory Code Protect
    @ DEVICE pic16F877, WRT_ON ' Flash Memory Word Enable
    TRISA = %00000001
    ' Allocate variables
    x var byte
    SO VAR PORTC.6
    BAUD CON 32
    DEFINE OSC 10
    ADCON1 = 0 ' Set PortA 0 to A/D inputs
    Pause 100 ' Wait for LCD to start
    SerOut2 SO,baud,[12,"Hello World AD Test",10,13]
    pause 1000
    Serout2 so,baud,[12,27,"[1;1H","Reading: "]
    Goto mainloop ' Skip subroutines
    ' Subroutine to read a/d converter
    getad:
    Pauseus 50 ' Wait for channel to setup
    ADCON0.2 = 1 ' Start conversion
    Pauseus 50 ' Wait for conversion
    Return
    ' Subroutine to get pot x value
    getx:
    ADCON0 = $41 ' Set A/D to Fosc/8, Channel 0, On
    Gosub getad
    x = ADRESH
    Return
    mainloop:
    Gosub getx ' Get x value
    Serout2 so,baud,[27,"[1;11H", dec3 x]
    Pause 100 ' Do it about 10 times a second
    Goto mainloop ' Do it forever
    End

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


    Did you find this post helpful? Yes | No

    Default

    Your reading is 24 or 25...

    Try calculating 24/255*5v = 0.470v...

    That's equivallent to ADCVoltage=ADCCount/ADCMaxScale*VRef

    Close enough for you?

    BTW... you can't use the above math in PBP as you have to scale it up a little to maintain INTEGER integrity, but I'm sure you can figure how to do that.

    And in answer to a previous point you made right at the start, the reason 0-5v Sensors don't actually go 0-5v, is that by going say 0.5v-4.5v you can tell if they go open or short circuit or otherwise go defective as their output will be out of range by being too low or too high. If it actually started at 0v and somebody pulled the plug on the Sensor on your Hospitals Life Support machine, you'd never know - and just might wreck your day.

  7. #7
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    Your reading is 24 or 25...

    Try calculating 24/255*5v = 0.470v...

    Close enough for you?

    BTW... you can't use the above math in PBP as you have to scale it up a little to maintain INTEGER integrity, but I'm sure you can figure how to do that.
    Yes, Not sure why I am getting this math all assbackwards. I think I've spent to many years as a mumps programmer. I think I get this part so far. My range of .5 to 4.5 isn't relivant... yet. the 24/25 reading is going off a REF of 5v which as you pointed out makes complete sense to me. I keep frogetting to take that into account but I am learining and willing to learn. I jsut can't seem to get past that part I think I need to programatically figure out how to factor in my range is only going to be .5 to 4.5 or 0 to 4 or I must have to give the pic a VREF. If you can point me in the right direction I would appreciate it.

    With in mind and I believe I get it so far I will post the program that I have been working on with some success. I think I am close.
    Here is my program and my logic/math

    So if my scale is 0-1024 with an internal ref of 5v and using an earlier example form Mack I would conclude give my sensor range of 0-150psi with an proportinate output voltage of .5 to 4.5v then...

    (150-0) / (4.5-.5) = 37.5 psi per volt
    150/1024 at a 5v ref range is .1464 psi per reading

    That part I understand completely. The next part is were I am lost.
    Converting the .5 -> 4.5v with an offset somehow so that works out to
    0 -> 4 then calculating out that voltage to PSI which would be easy would it not be my vdc * 37.5?

    0-1024 with a 5v ref gives me .0048 volts per incrment or 204.8 increments per volt. If I leave the 5v ref as it is then I think my offset would be -102.4 so to get the PSI reading I would take:

    Given ADVal = reading from the ad result

    ( ADVal - 102.4 ) * .1464

    Let's say I know the PSI is 75 then the calc should work... Half of 1024 would be 512 so ( 512 - 102.4 ) * .1464 = 59.96
    but... my reading would not be 512 for 75 psi it would be 512+102.4 right? arghhhhhhhh I'l be back I have to sweep up the last of my hair!

    Thanks for your help. I am trying.
    P.S. It's a beautiful day here in Pennsylvania

    David

    INCLUDE "modedefs.bas"
    ' Hardware specific settings
    @ DEVICE pic16F877, XT_OSC ' System Clock Options
    @ DEVICE pic16F877, WDT_ON ' Watchdog Timer
    @ DEVICE pic16F877, PWRT_ON ' Power-On Timer
    @ DEVICE pic16F877, BOD_ON ' Brown-Out Detect
    @ DEVICE pic16F877, LVP_ON ' Low-Voltage Programming
    @ DEVICE pic16F877, CPD_OFF ' Data Memory Code Protect
    @ DEVICE pic16F877, WRT_ON ' Flash Memory Word Enable
    ' ADC definitions 16F877 - (8) 10bit channels
    '*****************************
    DEFINE ADC_BITS 10 ' (8) 10 Bit channels
    DEFINE ADC_CLOCK 3 ' tell the us per osc clock tick?
    DEFINE ADC_SAMPLEUS 50 ' how long to sample the pin
    DEFINE OSC 10
    DEFINE LOADER_USED 1
    'INIT ADC
    ADCON1 = %10001110 ' Just one analog input needed see page 112 of 16f877 spec
    ADCON0 = %11000001 ' Analog converter Fosc/32, ADC module is ON
    'ADCON0.7 = 1 I DID THAT ABOVE RIGHT?

    'Varibles

    SO VAR PORTC.6
    ADval VAR word ' Storage for A/D result
    PRESSURE VAR word
    PRESS VAR word
    ADavg VAR WORD[2]
    READING var byte
    Value VAR WORD

    'CONSTANTS
    AvgCount CON 64 ' = Number of samples to average
    FAspread CON 25 ' = Fast Average threshold +/-
    BAUD CON 32
    '**************************************
    '****START OF PROGRAM*****
    '**************************************
    BEGIN:
    SerOut2 SO,baud,[12,"Hello World AD Test",10,13]
    pause 2000
    Serout2 so,baud,[12,27,"[1;1H","Pressure: "]
    MAINLOOP:
    ADCIN 0,adval ' Read A/D channel 0 to adval variable
    Serout2 so,baud,[27,"[3;11H",DEC5 adval]
    'average out press first before calcuating true pressure
    READING = 1
    value = adval
    gosub average
    press = value
    Serout2 so,baud,[27,"[2;11H",DEC5 PRESS]

    'PRESSURE = ( 58 * PRESS - 58 ) / 100
    pressure = ( 1464 * press - 1464 ) / 10
    value = pressure
    READING = 2
    GOSUB AVERAGE
    PRESSURE = VALUE
    Serout2 so,baud,[27,"[1;11H",DEC5 PRESSURE]
    Pause 200 ' Wait period between updates
    GOTO MAINLOOP
    END

    ' -=-=-=-=-=-= Average Analog values -=-=-=-=-=-=-=-=-=-=
    ' compliments of Darryl Taylor
    AVERAGE:
    IF Value = ADavg[READING] Then NoChange
    IF ABS (Value - ADavg[reading]) > FAspread OR Value < AvgCount Then FastAvg
    IF ABS (Value - ADavg[reading]) < AvgCount Then RealClose
    ADavg[reading] = ADavg[reading] - (ADavg[reading]/AvgCount)
    ADavg[reading] = ADavg[reading] + (Value/AvgCount)
    GoTo AVGok
    FastAvg:
    ADavg[reading] = Value
    GoTo AVGok
    RealClose:
    ADavg[reading] = ADavg[reading] - (ADavg[reading]/(AvgCount/4))
    ADavg[reading] = ADavg[reading] + (Value/(AvgCount/4))
    AVGok:
    Value = ADavg[reading] ' Put Average back into Value
    NoChange:
    Return

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Do not mix up the ADCIN defines and the bit banging from Bruce's example.
    Some more reading..
    http://www.picbasic.co.uk/forum/showthread.php?t=2188

    And a snippet for 10 bit banging..
    Code:
    ADCON1.7 = 1
    
    	gosub getAD
    
    
    
    	press.highbyte = ADRESH
    
    	press.lowbyte = ADRESL
    
    	return
    Do a search for 10 bit ADC also..
    http://www.picbasic.co.uk/forum/showthread.php?t=4751
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Do not mix up the ADCIN defines and the bit banging from Bruce's example.
    Some more reading..
    http://www.picbasic.co.uk/forum/showthread.php?t=2188

    And a snippet for 10 bit banging..
    Code:
    ADCON1.7 = 1
    
    	gosub getAD
    
    
    
    	press.highbyte = ADRESH
    
    	press.lowbyte = ADRESL
    
    	return
    Do a search for 10 bit ADC also..
    http://www.picbasic.co.uk/forum/showthread.php?t=4751

    Mack, Malanie Ok so let me step backwards and make this simple. Let's go back to Bruce's example first and get that working first as you suggested I got ahead of myself.

    Per Melanie and Bruce's example the pic is right on. My reading of 24
    24/255*5v = 0.470v

    So let me work on that. That would mean that for every bascially .5 volt I would see my count add 24 (I realize it's .47 but for the sake of argument we'll say .5) So for 1 volt it would be 48 then 1.5 volt 72 etc to 4.5 volt top out on my sensor at 216 reading.

    If I got from 24 = 0 PSI to 216 = 150 PSI that would be 216-24 for 192 increments at a max of 150psi = .78125 PSI per incrment. So the calculation would be
    ( adval - 24 ) * .78125
    ( 24 - 24 ) * .78125 = 0
    (120 - 24 ) * .78125 = 75
    ( 216 - 24 ) * .78125 = 150

    Right half way between 216 and 24 would be 96 + the offset of 24 I would get a reading of 120 so 120 - 24 = 96 * .78125 = 75

    I think I got this so far.

    I don't know why I am struggling with this so much but I think this is right so far. This looks correct to me so far let me hook this up to my compressor and take a look

    David

  10. #10
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113


    Did you find this post helpful? Yes | No

    Default arghhhhhhh

    I know that math is right but I can't get calculation. This is a stupid question I know and I really should know but I don't. What do I have to do to get this to multipl the decimal.

    ( 216 - 24 ) * .78125 = 150

  11. #11
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DavyJones View Post
    I know that math is right but I can't get calculation. This is a stupid question I know and I really should know but I don't. What do I have to do to get this to multipl the decimal.

    ( 216 - 24 ) * .78125 = 150

    woohoo I think I got it. Were X is my value read from the AD. I get a nice looking number. What do you think?

    x = x - 24
    res = x * 7812
    res = div32 1000

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    By George I think he has it
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113


    Did you find this post helpful? Yes | No

    Default I'll take a bow... Can you check one thing for me.

    Quote Originally Posted by mackrackit View Post
    By George I think he has it
    Mack,
    Thank you for your help today. I can't believe I had so much trouble with that. I wrote a program in mumps a few years ago that converted a number to base 36 for this wacky interface checksum I had to write and I don't think I struggled that hard.

    I was able to use my knew found logic and incoporate that same philosphy into my 10 bit program I originally started to work on but stepped back from to get the 8bit to work and understand this a little better. I know you pointed out a couple things about the high and low bits. I won't try to kid you I am not sure what you were trying to tell me there. I put this program together from bits and pieces by looking at others and their examples.

    I can run this side by side with the 8 bit program and I get the same results. Is there any advatage of reading the analog value using ADCIN vs. Bruces example? Any disadvatages?

    Thanks again today.
    David

    INCLUDE "modedefs.bas"
    ' Hardware specific settings
    @ DEVICE pic16F877, XT_OSC ' System Clock Options
    @ DEVICE pic16F877, WDT_ON ' Watchdog Timer
    @ DEVICE pic16F877, PWRT_ON ' Power-On Timer
    @ DEVICE pic16F877, BOD_ON ' Brown-Out Detect
    @ DEVICE pic16F877, LVP_ON ' Low-Voltage Programming
    @ DEVICE pic16F877, CPD_OFF ' Data Memory Code Protect
    @ DEVICE pic16F877, WRT_ON ' Flash Memory Word Enable
    ' ADC definitions 16F877 - (8) 10bit channels
    '*****************************
    DEFINE ADC_BITS 10 ' (8) 10 Bit channels
    DEFINE ADC_CLOCK 3 ' tell the us per osc clock tick?
    DEFINE ADC_SAMPLEUS 50 ' how long to sample the pin
    DEFINE OSC 10
    DEFINE LOADER_USED 1
    'INIT ADC
    ADCON1 = %10001110 ' Just one analog input needed see page 112 of 16f877 spec
    ADCON0 = %11000001 ' Analog converter Fosc/32, ADC module is ON
    ADCON0.7 = 1 'I DID THAT ABOVE RIGHT DO I NEED TO RESET THIS OR
    'DID MISS SOMETHING ABOUT SETTING VALUES THIS WAY?

    'Varibles

    SO VAR PORTC.6
    ADval VAR word ' Storage for A/D result
    PRESSURE VAR word
    PRESS VAR word
    ADavg VAR WORD[2]
    READING var byte
    Value VAR WORD
    RES var word

    'CONSTANTS
    AvgCount CON 64 ' = Number of samples to average
    FAspread CON 25 ' = Fast Average threshold +/-
    BAUD CON 32
    '**************************************
    '****START OF PROGRAM*****
    '**************************************
    BEGIN:
    SerOut2 SO,baud,[12,"Hello World 10 bit AD Test",10,13]
    pause 2000
    Serout2 so,baud,[27,"[2;1H","Pressure: "]
    MAINLOOP:
    ADCIN 0,adval ' Read A/D channel 0 to adval variable
    adval = adval - 96
    res = adval * 1953
    adval = div32 1000
    'average out press first before calcuating true pressure
    READING = 1
    value = adval
    gosub average
    press = value
    Serout2 so,baud,[27,"[2;11H",DEC5 PRESS]

    'PRESSURE = ( 58 * PRESS - 58 ) / 100
    'pressure = ( 1464 * press - 1464 ) / 10
    'value = pressure
    'READING = 2
    'GOSUB AVERAGE
    'PRESSURE = VALUE
    'Serout2 so,baud,[27,"[1;11H",DEC5 PRESSURE]
    Pause 200 ' Wait period between updates
    GOTO MAINLOOP
    END

    ' -=-=-=-=-=-= Average Analog values -=-=-=-=-=-=-=-=-=-=
    ' compliments of Darryl Taylor
    AVERAGE:
    IF Value = ADavg[READING] Then NoChange
    IF ABS (Value - ADavg[reading]) > FAspread OR Value < AvgCount Then FastAvg
    IF ABS (Value - ADavg[reading]) < AvgCount Then RealClose
    ADavg[reading] = ADavg[reading] - (ADavg[reading]/AvgCount)
    ADavg[reading] = ADavg[reading] + (Value/AvgCount)
    GoTo AVGok
    FastAvg:
    ADavg[reading] = Value
    GoTo AVGok
    RealClose:
    ADavg[reading] = ADavg[reading] - (ADavg[reading]/(AvgCount/4))
    ADavg[reading] = ADavg[reading] + (Value/(AvgCount/4))
    AVGok:
    Value = ADavg[reading] ' Put Average back into Value
    NoChange:
    Return

  14. #14
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Is there any advatage of reading the analog value using ADCIN vs. Bruces example? Any disadvatages?
    I like Bruce's example because I feel it allows more control.
    Example:
    I can when reading multiple channels, or one channel for that matter, switch from 8 or 10 bit with
    ADCON1.7 = 1
    or
    ADCON1.7 = 0

    I have not checked to see if one way is faster or uses less code space.
    Dave
    Always wear safety glasses while programming.

  15. #15
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I like Bruce's example because I feel it allows more control.
    Example:
    I can when reading multiple channels, or one channel for that matter, switch from 8 or 10 bit with
    ADCON1.7 = 1
    or
    ADCON1.7 = 0

    I have not checked to see if one way is faster or uses less code space.
    Mack,
    Gotcha that would make sense. If you don't mind can we discuss the 8 bit vs. 10bit and let me rant a little about some observations. With regards to the ADC isn't just the obvious difference between reading 8 bit vs. 10 bit just precision? There is nothing else to consider is there? I can either get a return value from 0 -> 255 or 0 -> 1024. One thing I noticed given the 8 bit response it tends to not bounce around as much as the 10 bit. The 10 bit response raw data when I am at 0psi bounces all over the place from 92 to 100. I have to run that through Darryl's average routine to get that stablized. That helps but doesn't stop it completely which brings me to a question is there any way to get that to settle down? The other question is whats the proper term for a signle interval on the ADC read? Is it tick or interval, increment?

    My other observation/question based on your statment about switching back and fourth between 10 bit and 8 bit. From my observations and looking at many examples of code there is always more then one way to accomplish something in the coding. I didn't miss anything here right I mean:

    ADCON1 = %10000000
    'ADCON1.7 = 1 'I DID THAT ABOVE RIGHT?

    Setting ADCON1.7 = 1 is essentially the same thing as my example correct? You're just setting the individual bit right?

    After this experience and reviewing what you taught me and looking at Bruce's example more closely that you could accomplish the 8 bit using the ADCIN by just setting ADC_BITS=8 in the beginning and the read on ADCIN basically puts both the ADRESH and ADRESL together for you in your variable. If you choose to use Bruce's method and wanted to do the 10 bit you've got to put those two result registers together right? Setting ADC_BITS is a one time thing at the beginning?

    It's tough even with the datasheet until someone get's you pointed in the right direction. I think I am intellegent and I should be able to figure this stuff out but thats not always so. Now that you've given me direction it's much clearer I appreciate the help I get from this forum.

    Good morning

    David

  16. #16
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DavyJones View Post
    Mack,
    Gotcha that would make sense. If you don't mind can we discuss the 8 bit vs. 10bit and let me rant a little about some observations. With regards to the ADC isn't just the obvious difference between reading 8 bit vs. 10 bit just precision? There is nothing else to consider is there? I can either get a return value from 0 -> 255 or 0 -> 1024. One thing I noticed given the 8 bit response it tends to not bounce around as much as the 10 bit. The 10 bit response raw data when I am at 0psi bounces all over the place from 92 to 100. I have to run that through Darryl's average routine to get that stablized. That helps but doesn't stop it completely which brings me to a question is there any way to get that to settle down? The other question is whats the proper term for a signle interval on the ADC read? Is it tick or interval, increment?
    Just a precision thing. With more precision you can can expect more "bouncing" sometimes noise will cause this or the sensor it's self. A lot of sensors a pretty sensitive Sometimes a capacitor from the ADC pin to zero will help smooth thing out, This may even be needed with some 8 bit applications.
    My other observation/question based on your statment about switching back and fourth between 10 bit and 8 bit. From my observations and looking at many examples of code there is always more then one way to accomplish something in the coding. I didn't miss anything here right I mean:
    Yep there is always more than one way do do anything. I coding we call this a style.
    ADCON1 = %10000000
    'ADCON1.7 = 1 'I DID THAT ABOVE RIGHT?

    Setting ADCON1.7 = 1 is essentially the same thing as my example correct? You're just setting the individual bit right?
    For your chip
    ADCON1 = %10000000
    makes all of th ADC pins analog, left justified, VREF+ at VDD and VREF- at VSS.
    If you want some of the ADC pins digital or change the VREFs then you will run into a problem.
    ADCON1.7 = 1 or 0 is just changing that particular bit.
    After this experience and reviewing what you taught me and looking at Bruce's example more closely that you could accomplish the 8 bit using the ADCIN by just setting ADC_BITS=8 in the beginning and the read on ADCIN basically puts both the ADRESH and ADRESL together for you in your variable. If you choose to use Bruce's method and wanted to do the 10 bit you've got to put those two result registers together right? Setting ADC_BITS is a one time thing at the beginning?
    Not quite... In the data sheet I have for this chip take a look at section 11.4.1.
    The register containing ADRESH and ADRESL is really 16 bits wide. ADRESH and ADRESL are 8 bits each.
    It's tough even with the datasheet until someone get's you pointed in the right direction. I think I am intellegent and I should be able to figure this stuff out but thats not always so. Now that you've given me direction it's much clearer I appreciate the help I get from this forum.
    This all can be quite confusing, if this forum was not here I would not have a clue either.
    Dave
    Always wear safety glasses while programming.

  17. #17
    Join Date
    Jul 2007
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    I have a similar problem, I got everything to work, except translating the math.

    My lowest ADVAL is 0 and it's also the HIGHEST pressure.

    I saw how the math worked out for him, but I am lost.

  18. #18
    Join Date
    Jul 2007
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    AD Res 1024

    Lowest voltage = .085v = 100psi = ADVal 18

    Highest voltage = .999v = 10psi = ADVal 205

    In order to switch everything around all I did differently was subtract my highest voltage (1volt) from lowest voltage (.085volt) and went from there!

  19. #19
    Join Date
    Jul 2007
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    So then I thought it out a little more, and instead of converting to voltage etc.. ADVal represents that value...

    SO

    highest ADVal = 205

    205 - whatever the adval is at for the input from the sender = x

    x * .5347 = pressure

    on my 187 resolution scale here.

  20. #20
    Join Date
    Jul 2007
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    didnt work very well... lost again

  21. #21
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by erice1984 View Post
    AD Res 1024

    Lowest voltage = .085v = 100psi = ADVal 18

    Highest voltage = .999v = 10psi = ADVal 205

    In order to switch everything around all I did differently was subtract my highest voltage (1volt) from lowest voltage (.085volt) and went from there!
    Can you give the make and model or data sheet for the sensor?

    Maybe show your code too.

    If that voltage range is correct I would go with 8 bit resolution and a reference voltage. Are you really getting a lower reading with a higher pressure?
    Dave
    Always wear safety glasses while programming.

  22. #22
    Join Date
    Jul 2007
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    yes, its an autometer 2242 pressure sender unit. its really annoying.

    all I have is
    15 ohms = 100psi
    175 ohms = 10psi


    What I am doing right now is using regulated current. ~5mA

  23. #23
    Join Date
    Jul 2007
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    reason why I am not using the 8bit adc is because I would have to use a lot more current to get it up out of the 19mV range, and not really wanting to do that since it seems to vary more, its probably my hardware tho, LM317T current reg.

  24. #24
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I think I see the problem.

    The ADC is for measuing a voltage.

    Use the sensor for R1 of a voltage divider and a fixed resistor for R2. The feed that output to the PIC.

    http://en.wikipedia.org/wiki/Voltage_divider
    Dave
    Always wear safety glasses while programming.

  25. #25
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink simple maths

    Quote Originally Posted by DavyJones View Post
    woohoo I think I got it. Were X is my value read from the AD. I get a nice looking number. What do you think?

    x = x - 24
    res = x * 7812
    res = div32 1000
    Hi, Davy

    I think you could have got it better !!!

    .78125 = ... exactly 25/32 !!!

    so, res = ( x * 25 ) >> 5


    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  26. #26
    Join Date
    Jul 2007
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    What if I switched the VRef+ and Vref- to

    Vref+ = 0v
    Vref- = 5v

    Would that work?

  27. #27
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by erice1984 View Post
    What if I switched the VRef+ and Vref- to

    Vref+ = 0v
    Vref- = 5v

    Would that work?
    Not sure.
    From what I found out about that sensor it has a variable resistance output. So to use it with an ADC I think you are going to need to change it to a variable voltage with a voltage divider.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Need a cheap touch sensor idea.. here it is
    By mister_e in forum Code Examples
    Replies: 20
    Last Post: - 16th April 2016, 22:42
  2. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  3. PICBASIC PRO-coding for wireless sensor node
    By syazila in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2009, 00:05
  4. Replies: 6
    Last Post: - 18th January 2008, 08:17
  5. 1-Wire Pressure Sensor
    By Mith in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th August 2005, 00:32

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