Shop OBEX P1 Docs P2 Docs Learn Events
Adc0838 — Parallax Forums

Adc0838

msh5686msh5686 Posts: 70
edited 2012-03-07 09:51 in BASIC Stamp
Hi All!

I'm using an ADC0838 to convert an analog voltage to a signal I can read into the BS2. I can't tell if my problem is with a the program (attached) or with my connections. When I debug the output from the chip, all I get is a full byte in decimal form (255). Something isn't right because I am varying the voltage going into the chip while debugging the output from the ADC, but it never changes. Using a DVM I have checked to make sure the voltage going into the channel I am reading is varying, but still just getting the decimal value of a byte out. Can anyone please give my program a once over? It seems simple enough, but I'm at a loss here. Thanks for the help!
«1

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-03-02 09:45
    Well the code works...so my first question is are you varying voltage to channel 0 or 1? The code is set up for channel 1, which is actually pin 2 of the ADC0838. Other than that it could be the wiring.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-02 09:53
    If you post a picture of your setup we could make sure you have the wiring correct.

    The ADC0838 is pretty easy to use (with other people's code:smile:), but I sure got it wrong when I first tried to use it.
  • msh5686msh5686 Posts: 70
    edited 2012-03-02 17:27
    Yes, I am trying to read channel 1. Guess that leaves a wiring issue.... Thanks for helping narrow it down.
  • msh5686msh5686 Posts: 70
    edited 2012-03-05 09:10
    Ok, by changing the connections to configuration in the attached image, I have gotten the stamp to start debugging some sort of varying voltage. The Issue making sense of the number that is debugged. It seems to just vary randomly... do I need to scale this in some sort of way? Or are my connections wrong? Thanks for the help!


    ADC0838.jpg
    1024 x 515 - 32K
  • LeonLeon Posts: 7,620
    edited 2012-03-05 09:18
    What is your input coming from? I always use a pot across the supply for initial testing of an ADC.
  • msh5686msh5686 Posts: 70
    edited 2012-03-05 09:23
    I'm using a pot... I know how much voltage is going in, but just can't seem to make sense of the output.
  • FranklinFranklin Posts: 4,747
    edited 2012-03-05 10:35
    I know how much voltage is going in, but just can't seem to make sense of the output.
    And that output would be? (as related to the input)
  • msh5686msh5686 Posts: 70
    edited 2012-03-05 12:50
    I am putting 3.5 V into the ADC. Here is a shot of the debug window. I don't know why the reading is changing constantly even though I am not varying the voltage.
    Screen Shot 2012-03-05 at 2.47.31 PM.png
  • LeonLeon Posts: 7,620
    edited 2012-03-05 14:02
    They are all over the place. Double-check your wiring.

    You need to decouple the ADC supply pin. Use a 10 uF capacitor as mentioned in the data sheet.
  • msh5686msh5686 Posts: 70
    edited 2012-03-05 17:20
    Thanks Leon. Do you mean the 10uF between the Vcc pin and ground shown in some of the diagrams?
  • LeonLeon Posts: 7,620
    edited 2012-03-05 17:44
    Yes. However, it probably won't fix your problem; the values would be a lot closer if that was all that was wrong.
  • msh5686msh5686 Posts: 70
    edited 2012-03-05 17:48
    Thanks again. I will put the capacitor in place and check my wiring. Does the diagram I posted earlier have any flaws you can see?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-03-05 20:38
    Your wiring diagram shows you connected to channel 0 of the ADC, however the code is reading channel 1. That would definitely explain random values.
  • msh5686msh5686 Posts: 70
    edited 2012-03-06 05:25
    Thanks, Chris. Sorry, I neglected to change my wiring diagram after I switched to channel 1. I am connected to channel one and reading that channel in the program. On another note, I switched my variable size from a byte to a word and the variations in the debug terminal have decreased considerably in their range. I admit it, changing the variable size was a blind shot in the dark and I'm not really sure why it is having the effect it is.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-03-06 09:05
    The code you originally posted worked fine. I do see two more issues with your wiring diagram, assuming this is how you have things connected. Disconnected V+ and connect SE to ground, then see what you get.

    Basically your code is expecting data MSB first, however your wiring has it set for LSB first, IIRC. I am pretty sure grounding /SE wil correct that part.
  • msh5686msh5686 Posts: 70
    edited 2012-03-06 09:16
    Chris, I disconnected the V+ and set the SE to ground, but still have the wandering values. I am going to pick up the capacitor Leon recommended I place between Vcc and ground to see if that's the missing piece. Thanks for the help!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-03-06 09:25
    One other thing comes to mind...what is the source of you variable voltage. It must have a common ground reference with the ADC. You mentioned a pot, but how is it connected and to where?
  • msh5686msh5686 Posts: 70
    edited 2012-03-06 09:26
    I'm using an external supply, but I do have it's ground on a common ground with everything else on my board.
  • msh5686msh5686 Posts: 70
    edited 2012-03-06 11:33
    Ok, I've tried the capacitor between Vcc and ground as was suggested in addition to disconnecting V+ and pulling SE to ground. Still have wandering debug values. Anyone have any ideas?
  • LeonLeon Posts: 7,620
    edited 2012-03-06 11:48
    I didn't think it would sort out the main problem, but it might help you get stable results when you get the circuit working, although 8-bit ADCs aren't usually troublesome.

    How is the circuit constructed? I don't trust solderless breadboards and build things like that on home-made PCBs. I have very few problems.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-03-06 11:48
    msh5686 wrote: »
    I'm using an external supply, but I do have it's ground on a common ground with everything else on my board.

    That could be your problem...try using a pot with the outside leads connected to VDD and GND and the wiper connected to the channel input.
  • msh5686msh5686 Posts: 70
    edited 2012-03-06 12:19
    Here is a current schematic of the ADC connections along with the debug window.

    ADC0838.jpg
    Screen Shot 2012-03-06 at 2.06.05 PM.png


    Also, I am really using a photocell as my variable voltage. It's output is very small so I am boosting it with an op amp. This gives me the 3.5 V I described earlier. The output from the op amp (3.5 V) is what I am sending into the ADC I am just using the variable supply to give my op amp (TCA0372) enough power to work. I do have one line on the breadboard dedicated to being a common ground between all these supplies, ie. negatives from the power supply, Vss on the stamp board, and the photocell all on one line. The unit is functioning to some degree in that when I cover part of the photocell, I see a voltage drop on the debug window. When covering as much as possible, I see the voltage drop close to zero. Does this make sense? The only part that is throwing me is how the values fluctuate when I am not changing anything to the photocell (DVM confirms steady voltage). Also, it does seem like there is some sort of pattern to the fluctuations in the debug window.... or maybe I'm just going crazy from looking at it for too long! Thanks for the help guys!
    1024 x 498 - 34K
  • msh5686msh5686 Posts: 70
    edited 2012-03-06 12:38
    UPDATE

    I have removed the external power supply from the equation that was being used to power the op amp. Now I have the same configuration as just stated, but the op amp is powered by the Vdd on the stamp board.
  • LeonLeon Posts: 7,620
    edited 2012-03-06 12:40
    They don't look random values to me.
  • msh5686msh5686 Posts: 70
    edited 2012-03-06 12:44
    That's what I thought, but can't make sense of where an artifact like that is coming from.
  • msh5686msh5686 Posts: 70
    edited 2012-03-06 18:32
    I am going to start from scratch on the wiring side of things in the morning. Until then, do any of you see what in the code could be causing these wandering output values?
  • msh5686msh5686 Posts: 70
    edited 2012-03-07 07:50
    Ok, I started over and rewired the ADC to this current configuration shown below. The input supply to Channel 1 comes from a pot. When doing this, the ADC is giving me consistent, stable readings (yay!). Then I added my op amp that ups the voltage supplied by my photocell and test it by itself. It supplies a steady voltage of about 3.5 V and my DVM shows a decreasing voltage when I cover some of the cell up (as to be expected). Then, only changing the input wire to channel 1 from being the voltage from the pot to the voltage coming out of the op amp, I come back to having the same issues with wandering values. Interestingly, every once in a while the debug window comes up with the exact value being sent out of the op amp, but then wanders for a while before striking it again. Is there some sort of other element I need to put in place between the op amp and the ADC? It's very strange to me that it does read the correct value periodically, this makes me think I need to adjust something with the timing of the shifting in and out of the data. Does anyone know if that is the case? Thanks!

    ADC0838.jpg
    1024 x 467 - 34K
  • LeonLeon Posts: 7,620
    edited 2012-03-07 08:56
    You seem to be getting there!

    Let's see the op amp circuit. I could simulate it if necessary.
  • msh5686msh5686 Posts: 70
    edited 2012-03-07 09:44
    Here is the full schematic. Thanks for the help!

    ADC0838.jpg
    1024 x 873 - 58K
  • LeonLeon Posts: 7,620
    edited 2012-03-07 09:48
    Why are you using a 1A power op amp? It isn't suitable for that application.
Sign In or Register to comment.