Shop OBEX P1 Docs P2 Docs Learn Events
BS2p 40 pin assignment problems. — Parallax Forums

BS2p 40 pin assignment problems.

the_0utsider1the_0utsider1 Posts: 13
edited 2013-08-22 20:51 in BASIC Stamp
Here is an abreviated copy of my code:

MAINIO
OUTPUT 0
solenoid con 0

AUXIO
OUTPUT 0
dev1 con 0
.
.
.

In troubleshooting i make the following changes:
start:
MAINIO
OUTPUT 0
solenoid con 0
high solenoid
pause 100
low solenoid
pause 100

AUXIO
OUTPUT 0
dev1 con 0
high dev1
pause 100
low dev1
pause 100
goto start

and the solenoid cycles on\off, dev1 doesnt.
if i move it to after DEV1 CON 0, neither cycle.

I thought i could define AUXIO to an alias instead of having to put AUXIO or MAINIO like 200 times in the code.
Am i wrong?

TIA

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-07-20 21:00
    Every time you need to change the state of an I/O pin in a different bank than the one currently selected, you have to select the necessary bank with MAINIO or AUXIO. If you're using an I/O pin for an input and the proper bank is not selected, you have to do that. There is no way to designate which bank is needed when you define an I/O pin (like with an alias). The reason for this is that the extra I/O pins were implemented without rewriting the compiler. Only the MAINIO and AUXIO statements were needed rather than changing everything to carry the I/O bank number along as part of an I/O pin's definition.
  • SapphireSapphire Posts: 496
    edited 2013-07-20 21:01
    AUXIO and MAINIO are commands, not variable, so you can't alias them. Your code should work, how do you know dev1 is not responding? The OUTPUT command is not even necessary, HIGH and LOW will set a pin to output. Also, try using PIN instead of CON to define pins, it makes the code more readable.

    When designing your circuit, you should try to put frequently used pins on either the Main or Aux I/O pins, so you don't need to put a lot MAINIO and AUXIO statements in your program. But whenever you need to switch between them, you will need one of these commands.
  • the_0utsider1the_0utsider1 Posts: 13
    edited 2013-07-25 13:18
    I was just testing with a voltmeter. i guess one bank of my chip is dead because when i go hi for the AUXIO, i get no voltage.
    Now to fix my amperage problem...

    Thanks.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-07-25 14:02
    Remember that there are two sets of DIRS registers as well as two sets of OUTS registers. You have to do an AUXIO then set the I/O pins you want to output mode as well as setting the state of the output pins to high or low. Using the HIGH or LOW statements does set output mode. You also have to do the same thing after a MAINIO
  • SapphireSapphire Posts: 496
    edited 2013-07-25 14:12
    Using the HIGH or LOW statements does set output mode.

    Mike is right! The reference manual states: "This pin will be placed into output mode."

    I've used HIGH and LOW without setting DIRS. You have to be in the correct bank (Main or Aux I/O) though.
  • the_0utsider1the_0utsider1 Posts: 13
    edited 2013-07-27 17:38
    so with
    MAINIO
    high 0

    AUXIO
    OUTPUT 0
    high 0
    .
    .

    so auxio pin 0 should be high, right? cuz on mine, there is no voltage. I get ~5v from mainio pin 0.

    Thx.

    PS. can u guys answer a trivial Q?
    I have another BS2p 24 pin
    I have wired a simple NO switch where output 1, output 2, output 3, input 4
    I want to use these where output 1 to a NO switch through a resistor back to input 4 to "tell the chip i pressed a button" (i have 3 switches) What size resistor do i use so as not to fry the chip? I try simple ohms law and use a 215ohm R and the dowhile loop is if input 4=1 exit. (In the dowhile loop the led blinks on and off..)
    but nothing happens and the led keeps blinking.

    TIA!!
  • SapphireSapphire Posts: 496
    edited 2013-07-27 19:10
    Your AUXIO pin 0 should be high with the code you show. Is there more to the program that might be causing the pin to go low? Did you try a different AUXIO pin to see if it works?

    The minimum recommended R for connecting input/output pins is 220 ohms, so your calculation is very close. But higher is better, and a 1k ohm resistor would also work. But when the switch is open, there is no connection to your input, so it floats and can report either a 1 or 0. Try adding a pull-down resistor on the input pin, say 10k ohms. Normally switches are wired to either Vdd or Vss, not between an input and output pin. You should post your entire code and a schematic in order to help figure out what is going on.
  • the_0utsider1the_0utsider1 Posts: 13
    edited 2013-08-08 06:44
    Thanks, i troubleshot this issue and discovered a few things:
    -i cannot use an output as a power supply, the input did nothing. I switched to powersupply as and bingo.
    -for code, i have
    INPUT 0
    dev1 con 0

    in code, if i have if dev1 = 1 then quit it doesn't work. if i have if in0 = 1 then quit this DOES work.
    -BUT-
    i can use dev1 when it comes to output like high dev1 pause 1000 low dev1 and the led blinks...

    Go figure...
  • davejamesdavejames Posts: 4,047
    edited 2013-08-08 09:01
    -i cannot use an output as a power supply, the input did nothing.


    :confused::confused::confused:

    ...pardon? What do you mean?
  • Mike GreenMike Green Posts: 23,101
    edited 2013-08-08 09:51
    A Stamp output can supply perhaps 20-25mA and there are limits on each group of 8 pins and on the total current drain for the whole device (all I/O ports). You'll have to check the datasheet for the processor chip used (SX) for the specifics. Trying to use more current than that can destroy the I/O pin circuitry. The built-in +5V regulator on the Stamp module is limited as well, mostly by the lack of a heatsink other than the thermal mass of the module itself.
  • the_0utsider1the_0utsider1 Posts: 13
    edited 2013-08-13 10:29
    it was wired Output pin to NO switch to Input pin. I had it this way because i have 3 switches and used 3 outputs so that i wont get a 1 from the wrong switch.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-08-13 11:46
    What's the voltage on the input pin when the switch is open? Answer: You don't know ... neither does the Stamp. You need a pullup (to Vdd) or pulldown (to Vss) resistor (about 10K to 100K) to define the unconnected state.
  • the_0utsider1the_0utsider1 Posts: 13
    edited 2013-08-22 20:51
    Thanks all. i finally got it working and have a fully assembled board to actually debug the sw on the gadget it will be running.
    I use 12V that also powers some motors to 80Ohm then pull down with a 100Ohm to ground and IT WORKS!!!

    THANKS GUYS!!!

    Maybe someday ill actually get down and dirty and start playing with more components....
Sign In or Register to comment.