Shop OBEX P1 Docs P2 Docs Learn Events
5v SPI ADC interface — Parallax Forums

5v SPI ADC interface

BasilBasil Posts: 380
edited 2007-05-09 20:55 in Propeller 1
Hi All,

Im trying to interface the prop with the MCP3208, SPI interface·ADC.
I will be using 5v for Vdd and VRef.

Vref must be 5v for my circuit, and Vdd can't be less than Vref from what I see.

I have read the interfacing 5v sticky and understand I could use a 1k-10k resistor on each of the data lines to interface to the prop.

This is ok for Vout, CS and CLK as they are all coming from the·ADC to the prop and need the reduction in voltage.

Is a resistor required·for the Din data line from the·Prop to the ADC?
The ADC 'High' voltage for Din is (0.7 * Vdd), so 3.5V in my case, and low is (0.3 * Vdd), so 1.5V.

3.5V for Vhi is above what the prop can output, so im not sure if it will work anyway (can someone confirm this?) and wouldn't adding a resistor lessen its chance even more?

Thanks for the help on this one! My brain is·melting... blush.gif

Alec
·
«1

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-15 02:06
    There are several things you can do, you could run the Propeller at 3.6V. The other simple option is to use a CMOS buffer operated at 5V that will accept the Propeller's output and translate into a voltage the ADC will accept. As you are aware you'll only need a resistor for the signals going from the ADC to the Propeller.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • BasilBasil Posts: 380
    edited 2007-04-15 02:12
    Oops, made a mistake in my orignal post. DOut only needs resistor, Din, CS and CLK don't [noparse]:)[/noparse] got it round the wrong way.

    Thanks Paul. The Prop will be operating at 3.3V I may look at a CMOS buffer, though ive never heard of one :P

    Any you would recommend?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-15 02:27
    The CD4010BE is a quad non-inverting buffer that can do translation from 3.3V logic levels to 5V logic levels. It's made by several manufacturers including Texas Instruments.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-15 02:30
    You can also use two inverters in series to achieve the same thing, a 74HC04 could be used.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • BasilBasil Posts: 380
    edited 2007-04-15 02:46
    Hmmmm thanks for that. Ill try figure out the one which will be most effective [noparse]:)[/noparse]
  • Bill HenningBill Henning Posts: 6,445
    edited 2007-04-15 08:06
    Hmm...

    What about a weak pullup to 5V? say 10k? And maybe protect the propeller's pin with a 3k3 resistor - something like this:

    +5V
    |
    Z 10k
    |
    5V INPUT PIN
    3k3
    PROP 3.3V OUT PIN

    When prop outputs a high, it gets pulled up to +5V

    When prop outpus a low, it pulls down the 5V input below its H treshold, while limiting the current thru the propeller to 1ma

    Mind you, my analog is weak, but I think this should work...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com - a new blog about microcontrollers
  • BasilBasil Posts: 380
    edited 2007-04-15 20:38
    Hi Bill,

    Yeah, I saw something like that on the sticky.
    Considering my board space, it may be the way to go.

    On the input pin, I need to drop from 5v to 3v, would 3k3 do the trick here also?

    Also, I have a situation where a high input to the prop ranges from 2.09v to 4.28v.
    I would like to put a 3k3 resistor in series with this one too, but am affraid it will drop the 2.09v below the Prop's Vil threshold (which from what I see is 0.6*Vdd=0.6*3.3=1.98V)
  • mirrormirror Posts: 322
    edited 2007-04-15 22:14
    I took a different approach to the same problem.

    I power the MCP3208 at 3V3 with a 3V3 reference and fed the analogs in through a resistor divider to set the range. The resistors on the input are part of the transient protection in any case. Also, by doing it this way I've got the option of having different input scaling by using different resistors.
  • BasilBasil Posts: 380
    edited 2007-04-15 22:28
    Interesting. That would work quite well for my situation as I have a mix of inputs

    1x 0 -> 5V Accelerometer (its really 0.25-4.75V but anyway)
    1x 0 -> 5V Barometer
    3x OPamps to measure voltage drop across an electric match. They have a 9V source and am still learning how to use op-amps so the range is not yet defined.

    This suggestion may give me more fliexibility with the op-amp circuit...hmmmm

    Would you use the same 3K3 & 10K resistors on the input side?
  • mirrormirror Posts: 322
    edited 2007-04-15 22:42
    Basil said...
    Interesting. That would work quite well for my situation as I have a mix of inputs

    1x 0 -> 5V Accelerometer (its really 0.25-4.75V but anyway)
    1x 0 -> 5V Barometer
    3x OPamps to measure voltage drop across an electric match. They have a 9V source and am still learning how to use op-amps so the range is not yet defined.

    This suggestion may give me more fliexibility with the op-amp circuit...hmmmm

    Would you use the same 3K3 & 10K resistors on the input side?
    There aren't any digitals on the input side of the MCP3208, so you don't need any resistors. The circuit I use it actually a bit more complicated that I stated previously. The Analog input comes in through some transient protection and a resistor divider, but is then fed into a MCP604 (a quad opamp) which is configured as a unity gain buffer. The MCP604 is powered from 5V, as the highest voltage it will produce at unity gain is 1.2V below the supply voltage. The reason for the voltage buffer is twofold:
    1) If any nasties get that far, then it becomes the next piece of sacrificial componentry,
    2) You need to watch·the source impedence for the MCP3208, and the buffer·makes sure that it's always going to be good.
    ·
  • BasilBasil Posts: 380
    edited 2007-04-15 22:58
    Oh ok. Attached is the OP-amp circuit I will be using for the 3 circuits, this should do the trick do you think? (Resistor values to be confirmed)

    I don't need the full 0-5v range for these inputs. Their function is to test continuity across the terminals and also, depending on voltage drop, can tell me if there is carbon build up on the terminals themselves.

    The Accelerometer and Barometer inputs are happy the way they are [noparse]:)[/noparse]

    I think in that case I will go with the 3K3/10K divider on the MCU side of the ADC [noparse]:)[/noparse]

    Thanks for the input though, this is all very interesting!

    EDIT: Attached the file...

    Post Edited (Basil) : 4/15/2007 11:28:30 PM GMT
    586 x 737 - 110K
  • BasilBasil Posts: 380
    edited 2007-04-16 04:28
    Hi All,

    Ok so from what you guys have told me, the attached interfaces should do the trick?

    I need to drop from 5V interface to 3V interface for the output on the ADC
    Also, 3.3V up to 5V for the 3 inputs to the ADC.

    I hope I got the resistor values correct!
    286 x 368 - 16K
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-16 04:42
    Since you said space is a premium, drop the resistor tied to ground in the lower diagram. The Propeller has diodes that are to protect against ESD, but also serve as a safe conduit of higher voltage if the current is limited. The 1kΩ resistor serves this purpose.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • BasilBasil Posts: 380
    edited 2007-04-16 04:50
    Ok good idea.

    Will 1K in series be enough to drop the 4.1V 'high' from the ADC to a safe High voltage for the prop?
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-16 04:55
    The 4.1V is the guarenteed minimum, you should use 5V when making your calculations. 5 - 3.3 = 1.7 V difference, by ohms law thats 1.7 mA current draw, its an ok value but you may want to increase it to 1.5kΩ to reduce the current a bit.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Bill HenningBill Henning Posts: 6,445
    edited 2007-04-16 06:32
    That looks good, but as Paul said, on the bottom circuit, drop the pull-down resistor, and up the series resistor to 1.5K

    Basil said...
    Hi All,

    Ok so from what you guys have told me, the attached interfaces should do the trick?

    I need to drop from 5V interface to 3V interface for the output on the ADC
    Also, 3.3V up to 5V for the 3 inputs to the ADC.

    I hope I got the resistor values correct!
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com - a new blog about microcontrollers
  • IanMIanM Posts: 40
    edited 2007-04-16 07:55
    Could you also leave out the pull-down resistor in the output circuit? To output a high, switch the pin to high impedance (ie input). Output a low as usual. You might be able to leave zero in the output register and just change the data direction register. Set it to input to output a high and set it to output to output a low.

    Cheers, Ian

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ian Mitchell
    www.research.utas.edu.au
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-16 08:41
    Yes the series resistor in the top circuit could be left out if you operated the output as an open collector output. For those unfamiliar with this method of operation, you set the output value to 0, then set the line's value via the direction register. A 1 in the direction makes the line a low value, a 0 in the direction register makes the line high. This can be a source of confusion to the novice programmer however, first the state is changed via a different method, and the value written to the direction register is the inverse of it's value seen on the line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • BasilBasil Posts: 380
    edited 2007-04-16 20:51
    Interesting.

    So in the input, I would just have a 1K5 series resistor.
    In the output, just a 10K to 5V pull-up resistor, keep the prop pin as an input and inverse the 1's and 0's to those 3 pins when communicating?

    Would this work with SPI communication at around 2MHz?
    I haven't had a good look at the object yet (if there is one) so can't think if how to modify/create it.

    The data from the ADC is quite critical, will this have any effect on the incoming data? (Noise etc)
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-16 21:05
    The prop pin would alternate between input and output, the value for the pin is fixed at 0. Essentially what you are doing is you set the bit in OUTA to zero. When you want the output to be low you set the bit in DIRA to 1, this makes it output and it pulls the line to ground. When you want the line high you make the pin input by setting the bit in DIRA to 0, this makes it a high impedance node where little current is flowing and the 10kΩ resitor pulls the line high.

    The only issue is how long your line is and it's associated capacitance because the 10kΩ resistor and the parasitic capacitance forms an RC circuit which takes some amount of time to pull the line to high. Depending on the speed of the serial communication and the length of your line connecting the ADC to the propeller this may or may not be an issue. If it is, you can lower the value of the 10kΩ resistor to speed up the charge rate.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • BasilBasil Posts: 380
    edited 2007-04-16 21:13
    Ahhh got it.

    The track to the ADC is, at most, about the width of the prop (LQFP package) away and is 12mil, 1oz.

    Does it matter that the track is running right beside the crystal? It doesn't run underneath it, just near one of its pins.

    EDIT: Forgot to mention, the quickest rise/fall time in the data sheet shows 50ns...

    Post Edited (Basil) : 4/16/2007 9:39:37 PM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-16 21:41
    That shouldn't be an issue.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • BasilBasil Posts: 380
    edited 2007-04-16 21:45
    Great thanks [noparse]:)[/noparse]

    Thats a simple fix and saves alot of board space!
  • mynet43mynet43 Posts: 644
    edited 2007-05-04 14:51
    I'm also working on this circuit. I'm using 3.3V for both VDD and VREF.

    I noticed that you have a separate circuit for the DIN and DOUT pins on the MCP3208.

    If you look at the code to support this chip, it requires that a single propeller pin (dpin) be connected to BOTH DIN and DOUT on the MCP3208. The code switches back and forth between input and output on dpin to service both lines.

    Therefore, I would guess that a single 10K pull-up would be all that is required.

    Let me know what you think.

    Jim
  • BasilBasil Posts: 380
    edited 2007-05-04 21:24
    Yeah, thats how i'd do it with 3.3V, however I must use 5V as VRef and VDD as the sensors I have attached to it are 5V too [noparse]:([/noparse]

    With 5V VRef, DIN is coming from the Prop @ 3.3V to the ADC @ 5V and so needs to be pulled up to 5V, whereas DOUT is visa versa (5V down to 3.3V and so needs a limiting resistor, so i cant really join them.
  • mynet43mynet43 Posts: 644
    edited 2007-05-05 13:19
    Something similar to this was mentioned above.

    It seems like you can set VDD and Vref to 3.3V. Then power your sensors with 5V as needed and use a simple voltage divider on the ADC inputs to convert from 0-5V range to the 0-3.3V range needed by the MCP3208.

    With this you can use the existing code, tie DIN and DOUT together and get the results you want.

    Am I missing something?

    Jim
  • BasilBasil Posts: 380
    edited 2007-05-05 23:31
    So there was!

    I forgot about that.

    I don't really understand all that stuff about the unity gain buffer, but if a simple voltage divider on the input side will work then I may chose to go down that path [noparse]:)[/noparse]

    EDIT: Sorry, had to run so here's the rest of this post blush.gif

    COuld I do what mirror suggested and NOT use the untiy gain buffer bit? Just the voltage divider from 5V sensors to 3.3V?

    The pull up resistors are nasty to route on the PCB, and changing the code is a pain smile.gif
    Overall, I think mirror's suggestion would be the easiest ot do.

    Post Edited (Basil) : 5/6/2007 1:31:02 AM GMT
  • BasilBasil Posts: 380
    edited 2007-05-06 02:30
    Just thought of something else.

    With the voltage divider, using 1K3 and 3K resistors, 5V drops to 3.030 volts for open circuit.
    WOuld the ADC be considered an open circuit?
  • mynet43mynet43 Posts: 644
    edited 2007-05-06 05:02
    The ADC input has a very high input impedance, so it shouldn't affect the voltage divider.

    Since you're only measuring voltage, you can probably go to higher resistance values.

    Maybe try 33K and 18K.

    I should have my 3208 by Tuesday, so I'll try it on my Propeller Proto board.

    Have fun.
  • BasilBasil Posts: 380
    edited 2007-05-06 05:33
    Ok thanks for the tip [noparse]:)[/noparse]

    The voltage I am measuring needs to be very accurate since I am using it to calculate altitude, speed and acceleration in a rocket.

    With those values, the output voltage range ends at 3.235v. This would reduce the accuracy of the ADC would it not?
Sign In or Register to comment.