Shop OBEX P1 Docs P2 Docs Learn Events
Interface BS2 with an independently powered DC Circuit — Parallax Forums

Interface BS2 with an independently powered DC Circuit

AndyMenonAndyMenon Posts: 26
edited 2015-04-27 07:02 in BASIC Stamp
Hi folks,

First of all, I'm creating this new thread after having consulted another forum post on "using BS2 to connect to a rain gauge powered by a 12V independent circuit". Whatever I have done thus far is based on that thread.

What needs to happen:
Please see the attached diagram. I want the BS2 chip to read the 3.3V signal at P3 and based on that, I want it to perform a series of actions. I will expand on this idea as this discussion progresses as I want to solve the problem one step at a time.

What has been completed already:
I have my output voltage divided down to 3.3V. I can read it with my multi-meter. The circuit is shown in the attachment.

Symptoms of the Problem:
When the wire is connected to the (-)Vss, the program reads 0 at IN3.
But when I pull out the connection to (-) Vss, I see my program reads 1,1,0,0,1,1,1,0 .... in short, a stream of inconsistent 1s and 0s.

Question 1: Is the circuit that connects to the BS2 Homework board as shown in the sketch correct?
Question 2: Why am I getting inconsistent reads at IN3 when I pull out the connection to (-)Vss? Do I need a capacitor to stabilize the voltage at IN3?

Once I manage to resolve this issue, and reliably read the input at IN3, I should be able to code the rest of the actions.

Thanks for your help!
Andy

Comments

  • SapphireSapphire Posts: 496
    edited 2015-04-22 21:15
    The BS2 threshold for a high is 1.4 volts, so when the 3.3v is connected it will show a 1. The reason you see random 1s and 0s when the wire is not connected is because the input "floats" and the stamp interprets it as 1 or 0 as the voltage is not defined. An input can only be read when the wire is connected (either to Vss, or Vdd or your 3.3v divider). But unconnected is not valid. If you want a certain value when the wire is disconnected, put a pull-up or pull-down resistor to Vss or Vdd to force the input to the desired state. 10k to 100k would be fine generally. A capacitor would only help if the lines from the rain gauge are long and subject to noise.
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-23 02:36
    Hi sapphire,

    Let me try to piece together all of this in parts:
    A. To your point on 3.3V, I guess I'm ok here as long as the voltage is between 1.4V and 5.0V which the BS2 can take safely.
    B. I guess I will have to revisit my fundamentals on BS2 which BTW is dated by a couple of years or so and will research the pull-up / pull-down resistors.
    C. About the capacitor - I will have considerable noise as this system will be mounted on a car that has a beefy and noisy 230hp truck engine.

    I do want both wires from the incoming 3.3V to be in constant connection with the stamp.But if I did connect it to Vdd, how would I read that input in code and take decisive action to trigger another circuit?
    When the 3.3V cuts off, I will need the stamp to trigger a relay to shut down a circuit on the car.

    Thanks
    Andy
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2015-04-23 09:08
    The circuit should work as shown in your diagram. With those values for the resistors you'll be drawing ~6 mA from the 9V battery just for the divider. For this reason I would use much higher values.

    If I understand your question #2, when you pull the lead to Vss your BASIC Stamp no longer has a ground reference for the voltage level on P3. Between two independent circuits you must have a common ground in order to know the voltage on the signal wire.
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-23 10:51
    Given that the only other ground is the 9V battery of the BS2, i guess the divider circuit ground wire will need to be run to the ground of the 9V supply on the BS2 side? Or is there a more elegant way of doing this without having to accidently destroy the BS2?

    What happens when I replace this prototype with the actual application? The divider side will have 12V supply whilst the stamp is 9V? How would common ground exist?

    Thanks
    Andy
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2015-04-23 13:20
    There needs to be a common ground between two circuits. Your diagram already shows this. The negative side of the battery on the divider connects to the VSS/GND on the HomeWork Board. The negative side of the 9V battery on that board is the same node as VSS, so there's no need to do anything different there. Or did I misunderstand your question?
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-23 14:13
    I think we are on the same page :-) Subsequent to your first response, I revisited the BS2 document on the (-)Vss.

    Ok, to summarize:

    I have both circuits leading to a common ground (physically wired to the board)
    As per my diagram, this should work
    Except that when I wire the circuit the way its in the diagram, it does not :-(


    Theoretically I'm on board , but in reality I'm not sure where that leaves me
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2015-04-23 15:11
    Okay, that's where I am confused, since you said when the wire was connected it worked, but when the VSS was disconnected, it does not. Do you have a photo of your wiring? I'm just wondering if it matches the schematic you posted as that should work assuming that R2 is adjusted for 3.3V at the junction of the divider. This would be approximately 560 ohms (closest standard value).

    So when everything is connected, you should see a high or 1 on P3, assuming there is power on the 9V to the left of the divider. If you remove the 9V from the left side of the divider then you should get a low or 0 at P3.
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-23 17:36
    Yep! I'm zapped too!
    Ground wire connected - zilch! Does not work.
    Disconnect the ground wire, and I see erratic 1s and 0s.
    I will wire the breadboard and post a picture at the earliest!
    Thanks for your patience with this.
    Andy
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2015-04-24 09:29
    Andy,

    One thing we need to clarify is that when you say with the ground wire disconnected you get random data and that's a clear symptom and expected. However you say when the ground wire is connected that it doesn't work, but that doesn't say what you mean. How doesn't it work? What do you get? What voltage do you measure at P3 when the ground wire is connected?
  • PublisonPublison Posts: 12,366
    edited 2015-04-24 09:39
    It would be good to see the code you are using. Maybe the code associated with IN3 is incorrect.
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-24 14:41
    Hi Publison,

    The code is super basic at the moment. Here's how it looks:

    DO
    DEBUG ? IN3
    PAUSE 1000
    LOOP
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-24 14:43
    Hi Chris,

    Given parallax has limitations on file sizes, I have uploaded pictures to my OneDrive and created public links listed in a logical order below:

    The circuit with everything plugged in as shown in the diagram in my earlier posts:
    http://1drv.ms/1PwtDSn

    The divided voltage (3.3V) across resistance R2 as measured by a multi-meter:
    http://1drv.ms/1PwtYV9

    Ground wire from 3.3V circuit is disconnected from (-)Vss on the BS2 side:
    http://1drv.ms/1PwuimJ

    BS2 Reads erratic 1s and 0s on the IN3 as seen in this console output:
    http://1drv.ms/1DloJPh

    Now Ground wire from 3.3V circuit is plugged back into (-)Vss on the BS2 side
    http://1drv.ms/1DloMug

    This time I get a constant reading of 1 at the IN3 Pin on the BS2 side (******This is unlike last time! Only change was that I ripped the wiring out and redid it for the sake of this photo-shoot!********)
    http://1drv.ms/1DloWSu

    Additional Observations:

    If I have to get BS2 to read constant 0s at IN3, I have to completely disconnect the battery on the 3.3V circuit. Simply disconnecting the wire from P3 on the BS2 won't cut it.
    (***picture not taken***)
    This is the intended behavior I want from my final application. As soon as the BS2 detects a constant stream of 0s for a certain period of time, I want it to trigger a relay to cut off the target circuit.

    But is this how this circuit is designed to behave?

    Thanks,
    Andy
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-24 15:53
    Ok, so what is it that I'm really trying to do here (sorry about the detail, but I guess we have a very understanding crowd here :-D ) :

    I have a 1923 Model T Street Rod. It runs an electric water pump that I have to manually turn on when I start the engine and off when I turn off the engine.

    So what's the big deal?

    Life would be uber simple if I remember to turn the water pump ON or OFF . But the problem is that I have managed to goof it up more than once!
    I have forgotten to turn on the pump and driven down the road, and almost a gallon of coolant boiled out of the engine - I'm glad that my motor didn't seize up!
    Conversely, I have forgotten to shut down the pump when I parked my car - the pump simply kept running sucking the life out of the battery!

    This is my solution to the problem:
    > The left side of my circuit is actually going to read the output from the engine vacuum pressure switch. When it's ON it means that the engine is running.
    > Because I'm reading from the 12V circuit, my voltage divider is going to divvy the voltage down to 3.3V, and send it to P3 on the stamp.
    > The output side of the BS2 will be wired to a relay module that will power the fused 12V Electric Water Pump
    > When I turn on the engine (**and forget to turn ON the pump**), BS2 will detect a stream of 1s , and when the stream lasts about 10 seconds, it triggers the relay to turn on the water pump
    > With the pump turned ON, BS2 ignores the 1s and now waits for a stream of 0s.
    > When I turn off the engine (**and maybe forget to turn off the pump!!!***), BS2 will detect a stream of 0s (because the vacuum switch shuts down), and when it detects the stream for about 10 seconds, it cuts off the relay thus shutting down the pump.
    > With the pump turned OFF, it ignores the 0s and now waits for a stream of 1s.

    So, what if the BS2 chip misbehaves due to all the vibration and noise, battery running out, etc?

    I already have a switch inline - Should BS2 decide to misbehave or run out of battery, I can always turn the pump ON or OFF manually.
    To overcome dead batteries, I have to plan to keep the BS2 powered up constantly - I may have to plug it to the cars 12V system with a 9V adapter of some kind.

    Thoughts?
  • Hal AlbachHal Albach Posts: 747
    edited 2015-04-24 16:22
    Unless there is a future feature that you wish to add to this that would require a microcontroller , for the life of me I do not understand why you would not use a simple automotive relay controlled by the ignition switch to run the pump.
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-24 17:22
    Bang on the money you are!
    The ultimate goal is to put in additional features.
    This basic functionality I'm trying to implement using the "basic version of" a micro-controller is sort of a stepping stone.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2015-04-24 22:48
    Okay, unless I am misunderstanding your post above with the photos it works as it should now. Correct?

    The reason it doesn't work right when you remove the wire from P3 is because that pin is floating now and subject to EMI/RFI noise causing random states. It should only work when removing the battery as this still leaves your divider connected to P3 which ensures it is pulled down when no voltage is present.

    That said, there are much more elegant ways to handle this, but for now I think it's important that you get it working the way you planned so you can see how the circuit you're having problems with works.
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-25 18:05
    Yep, It works!
    Your explanation makes sense. Following my last post, I broke down the wiring, and rewired the circuit again, and in the process did a couple of tests to confirm this fact.

    Talking about more elegant ways, can you point me to other posts? In the meantime, I will test my circuit on the actual application.

    Thanks all for your help!
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-27 06:11
    Folks,

    I searched the FAQs, and I did not find anything to let me mark the status of this post as "Solved".

    Can you please let me know how?

    thanks,
    Andy
  • PublisonPublison Posts: 12,366
    edited 2015-04-27 06:28
    Andy,

    Go back and edit your first post and select "Advanced". You should see a drop down menu with solved in it.
  • AndyMenonAndyMenon Posts: 26
    edited 2015-04-27 07:02
    Done!

    Thanks,
    Andy
Sign In or Register to comment.