Shop OBEX P1 Docs P2 Docs Learn Events
Help - Vacuum Sensing with ADC0831 — Parallax Forums

Help - Vacuum Sensing with ADC0831

idbruceidbruce Posts: 6,197
edited 2009-11-12 11:30 in Propeller 1
Hello folks

I am looking for a couple gurus to look over my SPIN code for mistakes.· I am having a sporadic problem with the ADC0831.· The ADC0831 tracks the output voltage of a GM MAP Sensor which monitors absolute pressure available within a reservoir.

Thanks·in advance for any input you may provide.· I need to solve this problem.· The SPIN attachment is well documented to aid in your assistance.

Thanks Bruce

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2009-11-08 11:33
    Hello Bruce,

    as a quick guess increase the stackspace to 200 and try again.

    It would be very helpful if you could describe IN DETAIL what your sporadic problem is.
    And as you are sending the vacuum-values to the PC attach a logfile with all the values

    best regards

    Stefan
  • idbruceidbruce Posts: 6,197
    edited 2009-11-08 12:45
    Hello StefanL38

    Thanks for a timely reply.· I thought the problem was defined clear and concise, but perhaps I am wrong.· The sporadic problem is that it either works perfectly or it doesn't work at all.·

    When it works perfectly, tank pressure is 0 inches of mercury and the value output of ADC0831 is 255 which activates the vacuum pump and creates vacuum within the tank, and as more air is removed the value of the ADC0831 continues to drop until maximum pressure is reached which is 20 inches of mercury (equivalent to a value of 61 by ADC0831), at which time the vacuum pump shuts down.··When pressure decreases and reaches the established minimum·of 15 inches of mercury (equivalent to a value of 110 by ADC0831) the vacuum pump activates once again until maximum pressure is reached.
    Start up ADC0831 value 255 - Tank pressure is 0 Inches of Mercury(Vacuum Pump activated)

    Pressure increases and ADC Value drops
    255·ADC0831 value
    230 ADC0831 value
    200 ADC0831 value
    150 ADC0831 value
    110 ADC0831 value
    80 ADC0831 value
    61 ADC0831 value (Maximum pressure 20 inches of mercury and vacuum pump deactivated)

    While pressure declines ADC values climb until minimum pressure is reached

    65 ADC0831 value
    80 ADC0831 value
    110 ADC0831 value (Minimum pressure 15 inches of mercury and vacuum pump activated)

    Runs until maximum pressure is reached

    110 ADC0831 value
    80 ADC0831 value
    61 ADC0831 value (Maximum pressure 20 inches of mercury and vacuum pump deactivated)

    (endless loop always monitoring pressure)


    When it doesn't work at all, it does not matter what the tank pressure is, the ADC always·outputs a value of 255 as follows:

    255·ADC0831 value
    255·ADC0831 value
    255·ADC0831 value
    255·ADC0831 value
    255·ADC0831 value
    255·ADC0831 value
    255·ADC0831 value
    255·ADC0831 value
    255·ADC0831 value
    255·ADC0831 value
    255·ADC0831 value
    255·ADC0831 value

    (Even if the tank is at·maximum pressure,·20 Inches of Mercury, the ADC is still putting out a value of 255, but should be putting out a 61 value.· Resulting in·unnecessary and unwanted operation of the vacuum pump)

    I changed the stack to 200 but it did not help.
  • idbruceidbruce Posts: 6,197
    edited 2009-11-08 12:48
    Hello all

    I guess I should say the problem is well defined in the source code
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2009-11-08 23:15
    It is not really enough code for a diagnosis.

    My suggestion is to break down your problem into little bits. You need to create a voltage divider circuit that feeds your adc , or somehow have a multimeter attached so that you can be certain that your reading is not correct. Then start commenting out, or in, your code until the problem starts/ goes away. You also should debug every pertinent variable in use (Oh for a true debugger here!) by sending it out the serial port, and seeing if they are what you think they are.
  • idbruceidbruce Posts: 6,197
    edited 2009-11-08 23:24
    Erik

    Thanks for the reply, however, I have done all that.· The spin attachment clearly states what I have attempted.· I have a tested everything that I can think of.· It is a very sneaky little bugger.· I just attempted·a·voltage divider 5 minutes prior to your post and that did not help.· It is still sporadic, but now the numbers are just going hay wire.· I am now leaning towards the 1000k resistors on pins 25, 26, and 27
  • idbruceidbruce Posts: 6,197
    edited 2009-11-09 11:47
    I should have included a more detailed description of my problem in the original posting, and I apologize for that.· However, the source code is fairly well documented if you want to download it.· To keep up with this thread, I highly recommend downloading new source code when it becomes available.· Eventually a new object, with good documentation will emerge.

    For those that might be interested in the ADC0831, I intend to get to the bottom of the·problem that I am having, and I will continue to update this thread until it is resolved.· Even though there are several Basic Stamp examples, and a few·propeller objects available, these examples and objects do not resolve complex problems like the one I am having.· The ADC0831 is not·documented very well.· Believe me I have done some serious in depth research.

    I am not an electrical genius, but do to the lack of good documentation, I had not choice but to go back to the datasheet and study that for a while.· Note 10 of the AC Characteristics on the datasheet provides important information on the timing and delays of the clock cycle.· After reading this, I realize that·my timing of the clock and delays of the clock could be way off course, especially since my input voltage into the ADC0831 is constantly changing while the vacuum pump is running.· So I intend to alter·and play with some new values in the source code.

    I'll be back!
  • idbruceidbruce Posts: 6,197
    edited 2009-11-09 12:13
    Hey Eric

    I misinterpreted the first comment of your post.· I have to disagree with that comment.· It may or may not be enough code for diagnosis of my problem, but it is·enough code for a simple review.· The primary purpose of my post was to seek a review by a couple gurus, to check my electrical connections to the propeller and ADC0831, and to review my acquistion of the input voltage through the source code, to see if it was correct.· I do believe the problem can be diagnosed and resolved by reviewing the source code and electrical connections that I provided in my initial post.· However, I did not mention that the input voltage changes rapidly, which I should have included.· But in my defense, a true guru would realize that some voltages, especially input voltages, can and do change very rapidly.· The proof is in the pudding!· For example, by looking at the provided source code and Note 10 on the datasheet for the ADC0831, a guru could see potential problems in my source code.· [noparse]:)[/noparse]
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-11-09 17:06
    So if you know that a guru can see it
    you seem to be a guru yourself. So why the questions ?

    To get maximum support you should provide as much information as possible.

    This means for example the datasheet that you are using as a attachment. Or even pictures out of the datasheet to point directly to
    the right page

    A quick test could be to change the code that it does all the bitbanging continously in its own cog and nothing else
    so one cog doing nothing else but

    your delay-value 100 results in a frequency of about 10kHz. Which is on the edge of the minimum-rating
    I would set the value of the delay to 400 which results in a frequency of 16,9 kHz (measured with my old DSO)

        ADC_Delay := 400
      
        repeat  'nested repeats to keep it going all the time
          repeat 8              
          outa[noparse][[/noparse]ADC_CLK]~~             'cycle the clock high then low
    
          waitcnt(ADC_Delay + cnt)
                
          outa[noparse][[/noparse]ADC_CLK]~
          
          waitcnt(ADC_Delay + cnt)
                        
          CurrentVacuum += INA[noparse][[/noparse]ADC_DO]         ' Add bit to value
          CurrentVacuum <<= 1
    
    



    best regards

    Stefan

    Post Edited (StefanL38) : 11/9/2009 6:09:14 PM GMT
  • Tired2Tired2 Posts: 29
    edited 2009-11-09 17:39
    idbruce,

    I have had some similar problems, they can be hard to track down.

    From your source, it looks like you have tried a lot of troubleshooting...

    I'm not Guru, but my suggestion would be to ditch your program entirely (temporarily), and start with this object:

    http://obex.parallax.com/objects/459/

    I have had good luck with it... Try out the demo, debug the values to the screen, and see if it functions properly with various voltage ranges. You might also consider leaving out the MAP sensor at first, and just use a voltage divider circuit to (and volt meter) to make sure you are giving the ADC the voltages you think you are. As sampling rates increase, impedance becomes more important, so make sure you do not sample "as fast" as you can, just sample as fast as you need to do get the intended results.

    Also, check this out with another propeller chip, or different Digital I/O / clk pins. I have seen intermittent program response on a brand new chip, then swapping to a different chip fixed the issue...

    Good luck, sounds like you are on the right track, but when i have strange problems like this, I isolate the program to only the part that is going wrong, and see if it fixes it.
  • idbruceidbruce Posts: 6,197
    edited 2009-11-09 20:13
    Tired2

    You claim not to be a guru, but you and I think alike.··I tried the object that you mentioned, but ditched it days ago.· The code has been changed many times, with different delays, no delays, etc..., but as·it stands now, the current code is very close to Jean-Marc Lugrin's ADC_0831_DEMO.spin with a few changes here and there.

    http://obex.parallax.com/objects/248/

    This happens to be the closest code to what I think is really required.

    I built a voltage divider in the input voltage circuitry yesterday, which I do believe was unnnecessary, however it does exist and it gives me the opportunity to just disconnect the sensor cable, add a jumper block to a couple·connector pins, and test a stable voltage, which would be VCC / 2.· If it reads correctly, than I will throw in a rheostat and test again.· If all goes well then the problem·will be·defined as reading the sensor incorrectly.·

    As for trying other pins, well the·only other pins available for hard wire are 28,29,30,and 31, and I need 30 and 31 for FullDuplexSerial just so I can debug.· My options are very cramped.· When I post a few photos, you will understand.· I am building a CNC machine and I am trying to get it all working with just one prop board.

    Thanks for your input
  • idbruceidbruce Posts: 6,197
    edited 2009-11-09 20:54
    Hello StefanL38

    Let me apologize...· I can be very hard headed, but I do appreciate all worthy input into this thread.· I am in fact a bit of a programming guru with an electrical background, but I don't know it all.· I am just living and learning like the rest of us.· This is my first project using the spin programming language, and it is a doozy, especially since I don't know or understand the ins and outs of it yet.· I just wish I had a better electrical background so that I could understand these datasheets, timing diagrams, and such things.· And I really need to study clock cycles and frequencies, because I can clearly see that·they are very important to proper component operation and logic.

    The original posted code looked like this:
    outa[noparse][[/noparse]ADC_CS]~
      waitcnt(ADC_Delay + cnt)
      CurrentVacuum := 0
      outa[noparse][[/noparse]ADC_CLK]~~
      waitcnt(ADC_Delay + cnt)
       
      outa[noparse][[/noparse]ADC_CLK]~
      waitcnt(ADC_Delay + cnt)
      repeat 8
        CurrentVacuum <<= 1
        outa[noparse][[/noparse]ADC_CLK]~~
        waitcnt(ADC_Delay + cnt)     
        outa[noparse][[/noparse]ADC_CLK]~
        waitcnt(ADC_Delay + cnt)              
        CurrentVacuum += INA[noparse][[/noparse]ADC_DO]
                   
      outa[noparse][[/noparse]ADC_CS]~~
    

    And it now looks like this, which·is probably way off course:
    outa[noparse][[/noparse]ADC_CS]~
      waitcnt((((clkfreq / 1_000) / 1_000) * 250) + cnt)  '250 ns
      CurrentVacuum := 0
      outa[noparse][[/noparse]ADC_CLK]~~
       
      outa[noparse][[/noparse]ADC_CLK]~
      repeat 8
        outa[noparse][[/noparse]ADC_CLK]~~
        outa[noparse][[/noparse]ADC_CLK]~
        
        waitcnt((((clkfreq / 1_000) / 1_000) * 90) + cnt)  '90 ns
        CurrentVacuum <<= 1        
        CurrentVacuum |= INA[noparse][[/noparse]ADC_DO]
                   
      outa[noparse][[/noparse]ADC_CS]~~
    
    

    ·And you posted:
    ADC_Delay := 400
      
        repeat  'nested repeats to keep it going all the time
          repeat 8              
          outa[noparse][[/noparse]ADC_CLK]~~             'cycle the clock high then low
    
          waitcnt(ADC_Delay + cnt)
                
          outa[noparse][[/noparse]ADC_CLK]~
          
          waitcnt(ADC_Delay + cnt)
                        
          CurrentVacuum += INA[noparse][[/noparse]ADC_DO]         ' Add bit to value
          CurrentVacuum <<= 1
    
    

    You add the bit and then shift, and my current code·shifts and then OR's the bit.· I got the shift and OR sequence from two other·spin objects.· Are both of these methods correct in accomplishing the same task?

    Please don't misunderstand, I do appreciate your input

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2009-11-09 22:15
    Hello All

    As promised, here is a photo of the machine and a closeup of the circuitry.· I swear there is a Propeller Proto Board and an ADC0831 in that mess somewhere [noparse]:)[/noparse]
  • idbruceidbruce Posts: 6,197
    edited 2009-11-09 23:56
    To All

    For those that care and·lack knowledge like myself, I performed several tests of moving bits to perform desired results

    Adding a·bit to a variable and then·shifting will give you an incorrect result, such as:
    Value += 1
    Value <<= 1

    nono.gif

    First shift then add the bit, such as:
    Value <<= 1
    Value += 1

    yeah.gif

    or you can shift then bitwise OR the bit, such as:
    Value <<= 1·······
    Value |= 1
    turn.gif

    Both of the latter methods provided satisfactory results upon test completion
  • idbruceidbruce Posts: 6,197
    edited 2009-11-10 02:00
    And the winner is Tired2jumpin.gif

    After many hours of troubleshooting, research and·revisions of code, I have located·a definite and intermittent problem with ADC_DO·(PIN 25), and this is the pin responsible for·holding the data that I need for proper operation.· I will be having a discussion with Parallax tommorrow morning about possible repair and/or replacement.

    This thread will have to wait until I get a new·Propeller Proto Board.· I will then complete my promise of providing a new ADC0831 spin object.

    I would like to thank all of those who offered their input.
  • idbruceidbruce Posts: 6,197
    edited 2009-11-10 14:55
    Update

    I managed to squeeze another I/O Pin out of the resource bucket.· Instead of waiting to get a new Proto Board or having the old one repair, I am back to the troubleshooting stage.· I am hoping that by the end of the day to·have my machine working properly and·a new Spin object which I will kindly share.· I have some fresh ideas that I intend to try and I think they should resolve all my problems, as well as any other problems that others may be having trying to interface the ADC0831 with the propeller chip.

    I will keep you posted

    eyes.gif·
  • Tired2Tired2 Posts: 29
    edited 2009-11-12 04:46
    Wow, nice machine. What does it do? Fold your laundry?

    Looks like it is well built.
  • idbruceidbruce Posts: 6,197
    edited 2009-11-12 11:30
    Tired2

    Thanks for the compliment.· LOL· No it does not fold laundry, but you are close, it folds (bends) spring wire into a useful shape.· I have a patent pending and this is the machine that will manufacture and package my product.· When it was working properly, it would produce 4000 units, and perhaps with a little creativity, I might get it to 8000.· However, I have come to the conclusion that more then one pin has been damaged and now I have to replace the Propeller Proto Board.· sad.gif·· One of the boards had a relay, and the diode that was my protection against voltage spikes from field collapse shorted out.· I believe that is what happened to cause all my problems.· However, I could be wrong.· I have been going in circles for about two weeks now, and as far as I can determine, the I/O pins are toggling incorrectly.· I should have arrived at this conclusion much sooner, because there was a very brief period where the machine and the ADC was working perfectly.

    I think a new proto board and some optic isolation should solve all the problems that I am currently having.

    Bruce
Sign In or Register to comment.