Shop OBEX P1 Docs P2 Docs Learn Events
Puzzling behavior of the INS register. — Parallax Forums

Puzzling behavior of the INS register.

Tom_WTom_W Posts: 4
edited 2012-03-14 18:28 in BASIC Stamp
' {$STAMP BS2}
' {$PBASIC 2.5}

DO
  DEBUG HOME
  DEBUG "PIN #         1111119876543210",CR
  DEBUG "              5432100000000000",CR
  DEBUG "INS         = ",BIN16 INS,CR
  DEBUG "OUTS        = ",BIN16 OUTS,CR
  DEBUG "DIRS        = ",BIN16 DIRS,CR
  DEBUG "IN7         =         ",BIN IN7,CR
  DEBUG "INL         =         ",BIN8 INL,CR
  DEBUG "INS.LOWBYTE =         ",BIN8 INS.LOWBYTE,CR
  DEBUG "INS.BYTE0   =         ",BIN8 INS.BYTE0,CR
  PAUSE 500
LOOP

I ran the code above while sticking some jumper wires into the I/O pins and noticed what I think is odd. The jumper wire wasn't connected to anything on the other end, neither Vdd nor Vss, just sticking straight up. The bits in the INS register would switch between 1 and 0 somewhat randomly. When I inserted the jumper wire in and out of several I/O pins fast enough I could get several INS bits turn to 1. After 30 seconds or so they will eventually all go back to 0s. Touching the wire, even on the plastic casing makes the bits jump between 1 and 0. This makes me think that it's probably static that the Stamp chip is reading. Is that what it is?

Furthermore, when one bit jumps between 1 and 0, the values often differ between what's displayed by IN7 and bit 7 of INS, INL, INS.LOWBYTE and INS.BYTE0. There is nothing special about pin 7. It's just there for testing. If IN7 and bit 7 of INS, INL, INS.LOWBYTE and INS.BYTE0 are all supposed to refer to the same bit in memory/register, why do they show different values, even if for a brief time?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-03-13 16:44
    The key is "brief time". I/O pins in input mode are high impedance. They're very sensitive to environmental voltages like static fields. Moving your hand close to the I/O pin or to wires connected the the I/O pin will change the voltage. There's a voltage threshold. If the I/O pin is at a voltage above this threshold, it appears as a 1. If this voltage is less than the threshold, it appears as a 0. This can change rapidly, so the I/O pin can fluctuate between 0 and 1.

    Ideally, any I/O pin that is in input mode should be connected to something. Typically, this is a pull-up or pull-down resistor. This is often a 10K to 100K resistor tied to ground or the power supply. You can also set the I/O pin to output mode during the program's initialization routine if it's not connected to anything or you can just ignore the bit in INS. A "floating" input I/O pin takes a bit more power than an input pin connected to something definite. It's probably not important if you're powering your circuit from an AC supply, but is important if you have a battery powered device and you want the battery to last a long time (like a clock).
  • Tom_WTom_W Posts: 4
    edited 2012-03-14 18:28
    Thank you Mike.

    I think, in addition to static, the long delay between the successive DEBUG statements caused differences between INS.LOWBYTE and INS.BYTE0. In another example I ran that had IN7, INL and the rest first assigned to separate variables and then output with DEBUG the differences were not as long lasting. They still showed up, because sometimes the INS pins would switch right in the middle of successive assignment statements, but not as much. Touching one of the jumper wires to ground would immediately set an input pin that was set to 1 by static back to 0. Either way, this wasn't meant for anything specific. I was just experimenting reading the INS register.

    Mike, you mentioned setting I/O pins to output. The PBASIC Syntax Guide in Memory and Variables section right after the BS2 register table talks about a condition that can fry the chip. They say that if you set a pin to output (I suppose via DIRS or executing an instruction that sets the pin to output), then set it to 1 and connect it to ground, you can damage the chip. I'm fairly new to all of this. Is there a wiring diagram somewhere that shows this condition? I'd like to see it so I know what NOT TO DO. Does that mean that you only can't connect an out pin that was set to 1 directly to ground but it's ok as long as there is some load in between?
Sign In or Register to comment.