Shop OBEX P1 Docs P2 Docs Learn Events
How do I use an ADC with the BS1? — Parallax Forums

How do I use an ADC with the BS1?

ghost13ghost13 Posts: 133
edited 2007-06-01 07:14 in BASIC Stamp
Hi,
I got a BS1 and I'm trying to make my own altimeter. I got this ADC:
focus.ti.com/docs/prod/folders/print/tlc3545.html
it is item 3545.

Using my BS1, how do I hook this up (from what pin on the ADC to what BS1 pin)?

Also, what code do I use to get the number value (not the individual bits - I want the bits put together into a number)?

I know it seems like I'm asking for people to do this for me, but I'm not. I'm just seeking guidance/resources/code.

Also, I already have this code (I just need the "waitForSample()" method):
while(1) {
    sample = wait_for_sample();
    sample = iir(sample);
    do_something(sample);
}
unsigned int filter = 0;

unsigned int iir( unsigned int val ) 
{
    filter -= filter >> 4;
    filter += val;
    return filter >> 4;
}





Thanks for your help!!! tongue.gif [noparse]:)[/noparse] tongue.gif

PS: what's the best way to mount the BS1 to a standard circuit board (I want to be able to remove it easily)?

Post Edited (ghost13) : 5/24/2007 3:39:27 AM GMT

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-24 03:39
    The code you’ve listed isn’t for a BS1. That looks like C or JAVA code to me.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • ghost13ghost13 Posts: 133
    edited 2007-05-24 03:41
    It is C. My bad. Please ignore that code.

    Anyway, what code should I use to get the number from my sensor through the ADC?
    I hooked it up exactly like it said in the manual, but the code confuses me. Which variable is the final number? What code do I need to keep calling to constantly get a new reading? All of it? Or just some of it?

    thanks! smilewinkgrin.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-24 04:41
    The BS1 doesn't have builtin commands to read from an SPI device (like the 3545). There's some similarity to the LTC1298 which is a 12-bit ADC with an SPI interface. There's an Appnote (www.parallax.com/dl/docs/prod/appkit/ltc1298.pdf) that includes sample code for a BS1. Your device is not identical since it's a 14-bit ADC, but the code should be easily modifiable. There's another set of Appnotes for the BS1 that provides an example using a different ADC: www.parallax.com/dl/appnt/stamps/bs1Appnotes.pdf.

    Post Edited (Mike Green) : 5/24/2007 4:47:58 AM GMT
  • ghost13ghost13 Posts: 133
    edited 2007-05-24 05:14
    Hmm... I also have this ADC:
    www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1335&dDocName=en010533

    Will it work? Even though mine has 14 pins, should I simply connect it like the LTC1298 is connected?

    And why doesn't the 14 bit one work? It uses the same pins. Is it simply a matter of converting the output? So is it a software program?

    Thanks!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-24 05:26
    The SPI interface uses 3 I/O pins (Chip Select, Data Out, Clock). All of these ADCs use the SPI interface. The exact details vary from ADC to ADC and the way the various pins are used will vary as well. You will have to study the datasheet for the specific device you want to use. All of them give diagrams showing the way the bits are transferred. You will have to modify the code given in the examples or use the devices used in the examples from Parallax for the BS1.
  • ghost13ghost13 Posts: 133
    edited 2007-05-24 22:55
    Ok. I ordered the LTC1298. I have a question about hooking it up like they did in the manual you linked to. My sensor only lets out a V+. I assume that should go into Ch0 and GND (from my 9V battery) can go to Ch1. Correct? Therefore, Ch1 and GND on the chip both go to the same wire. Also, is the 10uF tantalum cap a filter?

    And also, now they I can get the input in number form turn.gif, how do I convert that to barometric pressure. I'm using a barometric pressure sensor. Is there a simple formula for all barometric sensors? Or is there something unique in the datasheet? The datasheet link is below.
    www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPX4115&fsrch=1

    Thanks!

    Post Edited (ghost13) : 5/24/2007 11:25:42 PM GMT
  • ghost13ghost13 Posts: 133
    edited 2007-05-24 23:30
    I found this equation:
    Vout = VS x (0.009 x P – 0.095)
    VS = 5.1 ± 0.25 Vdc
    



    But Vout, I assume, is the sensor's output. Not the ADC. So how do I get the ADC output into pressure? Can I turn the ADC output back into a voltage, and then apply this equation?

    Also, I'd be comparing it to ground, which I would make 5V

    Post Edited (ghost13) : 5/24/2007 11:48:52 PM GMT
  • ghost13ghost13 Posts: 133
    edited 2007-05-25 03:20
    OK... all my other questions I figured out [noparse]:)[/noparse]

    So here is the only one that remains:
    I ordered the LTC1298. I have a question about hooking it up like they did in the manual you linked to. My sensor only lets out a V+. I assume that should go into Ch0 and GND (from my 9V battery but use resistors to make the GND -5V?) can go to Ch1. Correct? Therefore, Ch1 and GND on the chip both go to the same wire.

    Thanks!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-25 03:35
    Sensors do not have only a positive or only a negative terminal. They simply do not. The V+ is relative to some other terminal, usually a ground connection. Looking at page 3 of the datasheet, you have a +5V, ground, and Vout terminal. I would suggest strongly that you follow the manufacturer's recommendation about bypass and filtering capacitors and mount them close to the sensor (within an inch or two max.) The ground of the sensor circuit should be the same as the ground of the LTC1298 and the ground of the BS1.

    Similarly, use the circuit given in the Parallax AppNote for the LTC1298 including the bypass capacitor (again, within an inch of the LTC1298). The LTC1298 is a TWO channel ADC. In the AppNote, they show two 0-5V signals, one for each channel and these are relative to ground. In your case, you only need to use Ch0 (or Ch1).
  • ghost13ghost13 Posts: 133
    edited 2007-05-25 03:49
    OK. I added all of that and attached the schematics? Would you mind looking at them? Are they correct (you only need to check the LTC1298 and the connections to the BS1)?

    THANKS!!! smile.gifsmile.gifsmile.gifsmile.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-25 04:02
    I see several problems in a quick glance

    1) The sensor is not hooked up anything like what's in the manufacturer's datasheet. Please look again carefully, particularly how the capacitors are connected. The symbol that looks like an upside down triangle is one of the symbols for ground.

    2) There are no current limiting resistors for the LEDs. Please look at the "What's a Microcontroller?" tutorial from Parallax (here: www.parallax.com/dl/docs/books/edu/Wamv2_2.pdf) for examples.

    3) Your schematic is very messy with things all jumbled up together ... very hard to follow. Keep the sensor stuff together, then the ADC stuff together, then the BS1 stuff (usually left to right). Look at examples from other people.
  • ghost13ghost13 Posts: 133
    edited 2007-05-25 04:16
    Thanks for your help. Is this better?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-25 04:32
    It's somewhat better:

    1) The resistor in the ground lead to the sensor and LTC1298 shouldn't be there. Those "ground" pins really need to be directly connected to the circuit ground.

    2) The little square connected to the BS1 I/O pin 7 ... Is that supposed to be a relay? If so, you need a reverse connected diode across the coil to protect the BS1 from "reverse EMF". The "What's a Microcontroller?" tutorial gives an example of this.

    3) You didn't give a value for the LED resistors. Do you know how to pick that? Most LEDs use a current between 5ma and 20ma. 5ma usually will light it up and 20ma will give a bright light, but use a bit of current. The LED will use 1.7V of the approximately 4.7V available (with the Stamp using the last 0.3V). That leaves 3V to drop across the resistor. At 5ma, that requires 3/0.005 ohms or roughly 600 ohms. I'd use a 330 ohm or 470 ohm value for a bit more current and these are standard values.

    Post Edited (Mike Green) : 5/25/2007 4:39:46 AM GMT
  • ghost13ghost13 Posts: 133
    edited 2007-05-25 04:44
    Thanks for helping me. I never understood how to pick the correct resistors (I understood I needed to lower it 3V, but I don't know how to calculate that in ohms).

    Also, the thing you thought was a relay (the one to the left of "to nichrome") is actually meant to be a transistor. When current is applied, the transistor switch should close, applying a full 9V to the nichrome. Then, after about a second, the nichrome will automatically break itself (it melts itself).

    Anyway, how's this third version look? THANKS!!!!!!!!!!!!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-25 04:56
    Well, it looks better. Please draw transistors using the proper symbol so a reader can tell how they're connected. You will need a series resistor in the transistor's base lead. The value will depend on the gain of the transistor and the amount of current you'll need to have flow through the nichrome wire (and the resistance of the wire). Figure on 20ma which is about the maximum you should have from any one Stamp pin. The resistor will have to drop about 4V (5V - (Stamp drop = 0.3V) - (Transistor base drop = 0.6V)), so 4V/0.02A = 200 ohm. Use 220 ohm for a standard value.
  • ghost13ghost13 Posts: 133
    edited 2007-05-25 05:14
    OK... I changed that... I think.

    I also have another transistor that passes 9V through it. Do I need a resistor there?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-25 05:19
    Your transistor switches won't work the way you've done them. They're NPN transistors wired backwards and, even if they were PNP transistors, the BS1 couldn't switch them (you need what's called a "high side switch"). There are ways to do this, but I'm going to bed. Maybe someone in some other timezone will chime in or it'll wait until another time.
  • ghost13ghost13 Posts: 133
    edited 2007-05-25 06:48
    Hmm... maybe I'll keep the first transistor (the 9V one) and swap the other transistor for a relay...

    Also, what is the best way to mount the BS1? I know the pins are all on one side facing out, not bent over. I don't really want to solder it, because then I can't easily remove it. Other solutions???
  • RDL2004RDL2004 Posts: 2,554
    edited 2007-05-25 10:46
    Use a socket made for ICs and cut off just one side and use that. Machine pin contact type is the best and only cost a bit more. You can also get what's called a in-line socket, SIP socket, or sometimes is called a female header, but you probably won't find these at Radio Shack. Here are couple of examples.

    www.mouser.com/search/ProductDetail.aspx?R=929850-01-14-10virtualkey51750000virtualkey517-850-01-14
    www.mouser.com/search/ProductDetail.aspx?R=315-43-164-41-001000virtualkey57510000virtualkey575-31543164

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • ghost13ghost13 Posts: 133
    edited 2007-06-01 00:09
    OK... I got all the parts and hooked it up. Now, I'm a bit confused on how to get the output (code is attached). I'm using the LTC1298 (www.parallax.com/dl/docs/prod/appkit/ltc1298.pdf) as my ADC. My sensor is a pressure sensor.

    What variable (using the appnote's code) is the ADC output? Is it AD? If so, why (when I run my code) is the same thing always displayed (379). Even when I blow or suck on the sensor's air pressure input, nothing changes. The schematics are also attached.

    Because the ADC can utilize 2 sensors, am I on programming it incorrectly?

    Thanks!

    PS:I'm using the BS1
  • ghost13ghost13 Posts: 133
    edited 2007-06-01 07:14
    Should I maybe change this:
    SYMBOL sglDif = 1            ' Single-ended, two-channel mode.
    




    to this:
    SYMBOL sglDif = 2            ' Single-ended, two-channel mode.
    




    or this:
    SYMBOL sglDif = 0            ' Single-ended, two-channel mode.
    



    Thanks!
Sign In or Register to comment.