Shop OBEX P1 Docs P2 Docs Learn Events
Pin useage theory — Parallax Forums

Pin useage theory

AImanAIman Posts: 531
edited 2006-11-08 20:40 in Learn with BlocklyProp
I am working on a new project that requires use of specific pins at specific times but it must relate to an incoming command to function. The programming isn't a concern right now so much as the theory, any input would be appreciated.

High level overview.

The BS2 is being used to control several different compents, two solenoids, one servo, 6 sonar and a lights and siren setup (I got bored with no sound).

So for Pins 1 and 2 they are directly relation to pin 3

When pin 1 is high pin 2 is low. When pin 2 is high pin 3 can be used but may not need to be. When pine 3 is used pin 1 must be low and pin 2 must be high.

First question -· Can a if statment say that if Pin 1 is low pin 2 is high and vise versa? I have not yet been able to figure that out from my materials and haven't been able to get that programming to work. I have this -

if pin 1 high then pin 2 low
If pin 2 high then pin 1 low
if pin 3 high then pin 2 high and pin one low

Is that about right?


Second question - Can I run a if statment to say that if pin 3 is needed pin 2 must be high? This relates to number one directly but am not sure if the theory on question one is correct

Third question - can an if statment be used so that if pin 3 is required it forces pin 2 high and pin 1 low? This also relates to question one and needs a·theory check.

Pin 4 runs the servo which can be used at any time and typically is used most of the time

if pin 4 high and pin 2 high or pin 1 high then
·· (insert code here)
end if

The rest of the pins run as follows.

Pin·5 through 11 run sonar and cycle through these non stop until the program is terminated. The data is always feed out of PIN 16.

Pin 12, 13 and 14 are for the lights and siren and pin 16 for host hook up

Pin 16 is the I/O for communicating with the host.

Question four - can I run all three items off one pin without having gaps in light and sound?· Right now I am keeping pin 12 high all the time by using

do while pin 16 <> stop··· ' Pin 16 I/O with Host
·· pin 12 high
loop

Given this work load would these things over load a BS2?
Would a BS2p be a better choice?
·

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-10-19 16:16
    1. You first must define (in your own mind, first) if a pin is an input or an output. "If Pin1 is high then HIGH Pin2" will work IF pin2 is an output. If Pin2 is REALLY an input, then "HIGH Pin2" will connect two drivers together (your BS2 pin driver and the 'external' driver, whatever that is.) You MUST have a 220 ohm resistor between the two if this CAN happen, or the BS2 pin driver may be destroyed.

    2. "Pin 16" is a pseudo-pin, which indicates to a SERIN or SEROUT statement to use the 'progamming port'. That's a very important use, but I don't think you can use it for INPUT or OUTPUT statements.

    3. The BS2 is a single tasking chip. It CAN hold a signal HIGH or LOW while doing something else. It CAN'T do a SERIN on two pins at the same time.

    4. The BS2 has no "is needed" concept. I don't know what you mean by "is needed", or "is required". The BS2 knows HIGH and LOW, 0 or 1. Only you can define the mapping between your "is needed" and "is pin3 = 1". It's not clear from your post what you intended.

    5.· If "pin 4 runs the servo", then pin 4 is an output.· This means "IF Pin4 = 1" is a non-sensical statement, because it tries to use Pin4 as an input.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-19 16:52
    It may be useful to imagine the BS2 as a little robot with 16 slots in front of it. It can look out a slot to see what's going on there or it can poke a stick through the slot pushing it all the way in or just plugging up the hole. If the stick is in the slot, it can't look out. The robot only has one arm and one eye, so it can change only one slot at a time (not quite true with the BS2, but mostly true) and only look out one slot at any given instant.
  • AImanAIman Posts: 531
    edited 2006-10-19 19:20
    In other words I have to cycle through all the pins as fast as possible?
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-10-19 19:32
    In other words, what you've told us so far is so confusing we can't help. Ask one question at a time, and tell us why you want to know, what you want to use it for.

    "So for Pins 1 and 2 they are directly relation to pin 3" is a very ambiguous statement, and poor grammar.

    We want to help, really we do.
  • AImanAIman Posts: 531
    edited 2006-11-08 19:51
    Mike,

    In otherwords I can't have two pins high? I can only go one at a time regardless of the code?
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-11-08 20:05
    Yes, you can have two pins high at the same time

    HIGH 1
    HIGH 2

    ' this will make both pin 1 and 2 high at the same time.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-11-08 20:40
    Allan,
    ·
    ·· Actually, that will make P1 HIGH and then P2 HIGH.· To make them both HIGH at the same time you could do something like:

    OUTA = %0110
    

    Of course, the direction registers for these pins must be set to outputs first.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.