Shop OBEX P1 Docs P2 Docs Learn Events
I/O Port speed difference? — Parallax Forums

I/O Port speed difference?

DaphylDaphyl Posts: 17
edited 2006-12-31 08:21 in BASIC Stamp
Does anyone know if there is any I/O port speed difference between the BS2 and the BS2p?· I know the processor is much faster, but I can't seem to find any data concerning the 16 I/O ports (if there is a technical site, I would appreciate the link).· Performing the calculations faster won't help me if it's going to bottleneck there.

David

Comments

  • FranklinFranklin Posts: 4,747
    edited 2006-12-28 21:39
    What is it you are trying to do and what timing limits are you looking to achieve?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2006-12-28 22:44
    The actual I/O ports are very fast (look at the PIC and SX datasheets for timings). The real delays are in the interpretation of the byte code instructions by the processor. Check out Tracy Allen's website www.emesystems.com for lots of information on using the Stamps. He does have some speed comparisons of the different Stamp models.
  • DaphylDaphyl Posts: 17
    edited 2006-12-29 07:50
    Thanks Mike. I'll have a look at it. I have a feeling that the problem is in my program though...

    David
  • DaphylDaphyl Posts: 17
    edited 2006-12-29 07:53
    ······························································ Back Ground
    ·
    ········ I have a perf board that is 16” long and 6” high.· Believe it or not, over the last year I have soldered and wired 336 individual red LED’s to this board.· They are configured in a matrix of 48 vertical rows of seven LED’s by seven horizontal columns of 48 LED’s (7 x 48 = 336).· All 48 LED’s in each of the seven horizontal columns has the anode wired to one of the seven high I/O ports (creating a common anode) through a 33 ohm resistor, and each of the seven LED’s in the 48 vertical rows are soldered to create a common cathode connected to the collector of a 2N2222 transistor.· The emitter of the 2N2222 is connected to ground.· The base of the 2N222 is wired to the output of a 74LS04 inverter chip through a 10 kilo ohm resistor.· The input side of each inverter chip is connected to one of the 16 outputs of a 74LS154 (4 to 16 demultiplexer chip).· I had to use the 04 chips because the selected output of the 74LS154 chip is always low (the 15 remaining outputs are held high).· Three 154 chips and each chip controls 16 rows, equals 48 rows.· (A small portion of this circuit is at the end of the dissertation.)
    · ····
    ···· ··All of this means that I’m using seven of the eight upper ports with each port driving one column of 48 LED’s.· However by selecting which of the 48 2N2222 transistors, and which of the three demultiplexers is active, only one of the rows of LED’s will be active at a time (meaning each port drives just one LED at any given time).
    ·
    ···· Four of the lower I/O ports are used as data selects for the 154 chips to select which one of the 16 outputs will be active. By changing the condition of these four ports and pulsing any of the seven high I/O ports, I can light up any or all of the LED’s in a given row.· And finally by using three more of the lower I/O ports I can also select which 74LS154 chip is active when the seven high I/O ports are pulsed.
    ·
    ·· ··The beauty of all this is that with just three variables, two sets of data (one data set to select which of the upper I/O ports to pull high, and one data set for the lower I/O ports), and a dozen lines of code; I can create scrolling messages across the 48 rows of LED’s.
    ·
    ·············································· ·······Now to the problem
    ·
    When I’d pulse the seven upper I/O ports to light the LED’s, for some reason they were all still very dim.· So instead I just pulled the selected ports high. ···
    Ex:
    READ leds + counter, result··
    OUTH result·· (If result is DEC 127 = BIN 01111111, all seven of the LED’s in the row would light up even though they would still be dim.)· By adding a 2 to 4 millisecond pause, the LED’s lite up beautifully.· But the pause (even 1 millisecond) caused the program to slow down so much that the rows of LED’s would flicker.· This made the letters seem to flash across the display in a wave like effect.· A pause beyond 10 milliseconds slows the program so much that one row of LED’s at a time would light up and then turn off before the next row of LED’s lights up.
    ·
    If the ports are fast enough as someone else stated, then the problem is in my program. Here is the program with the letter ‘H’ displayed about half way across the display (each number in control selects the appropriate 154 chip and also tells the chip which transistor to turn on so that the proper row of LED’s will light up:
    ·
    ·
    ·
    ·
    '{$STAMP BS2pe}
    '{$PBASIC 2.5}
    counter VAR Byte
    result VAR Byte
    values VAR Byte
    leds DATA 127, 8, 8, 8, 127
    control DATA 197, 181, 165, 149, 133
    DIRS = %1111111111111111
    ·
    main:
    FOR counter = 0 TO 4
    READ leds + counter, result
    READ control + counter, values
    OUTH = result
    OUTL = values
    PAUSE 2·· ‘ This is the problem line!
    NEXT
    GOTO main
    ····
    ·
    ·
    Anyone have any ideas?
    ·
    ·
    David
    · ····························································
    ·············································· To demultiplexer:
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-12-29 14:48
    I think you have a power problem. There's nothing in your program (that I could see) that would cause the LED's to "turn off" between letter segments.

    Another key symptom is that if you run it full-speed, the LED's look "Dim", but if you put a pause in there they look full brightness. This implies your power system is unable to handle the load when one row of LED's is 'turning off' while the next row is "turning on".

    Note that 48 LED's in one row, at 10 mA per LED, will be pulling 480 mA. You don't say how you're supplying that current, or how the BS2 is controlling that current, but is surely can't be through a BS2 I/O pin. Those are limited to 50 mA, not 500 mA each.
  • DaphylDaphyl Posts: 17
    edited 2006-12-29 16:11
    I don't think it's a power supply problem.· In the second paragraph I explain that even though·there are 48 LED's in each column (common anode), only one LED per colunm is actually drawing any current because the other 47 in each column are disabled by the 2N2222 transistors connected to the cathodes.· But in order to power the six 74LS04 and three 74LS154 chips·in the circuit, I used a separate power supply for everything but the LED's.

    David
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-12-29 17:36
    Hi David,
    Correct me if I'm wrong, but I don't see any latch in the hardware scheme. So, the light output from a 100 microsecond pulse to the LEDs will naturally look dimmer than a 1 millisecond pulse.

    One solution is to use brighter LEDs (higher current) for the shorter pulses. That may take a high side driver that can operate at a higher voltage. I don't know, there may be practical minimum for visual perception on the order of one millisecond.

    Another solution would be to latch the outputs so the LEDs stay lit until changed. That is quite a different hardware scheme from what you have now with the common anodes and cathodes. Or, a capacitor scheme like the candle effect, to charge a capacitor in parallel with each LED (336 of them!?) to stretch its ON time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • DaphylDaphyl Posts: 17
    edited 2006-12-29 19:44
    Sorry, I posted the wrong version of the program. The first version never turned any of the I/O ports off before reading the next set of data and enabling the next row of LED's (the result after the first row of correctly lite LED's was complete chaos!)

    '{$STAMP BS2pe}
    '{$PBASIC 2.5}
    counter VAR Byte
    result VAR Byte
    values VAR Byte
    leds DATA 254, 16, 16, 16, 254
    control DATA 197, 181, 165, 149, 133
    DIRS = %1111111111111111
    main:
    FOR counter = 0 TO 4
    READ leds + counter, result
    READ control + counter, values
    OUTH = result
    OUTL = values
    PAUSE 2
    GOSUB off
    NEXT
    GOTO main

    off:
    OUTH = %00000000 ' turns off all I/O ports to clear display before lighting next row of LED's
    RETURN


    Also, I had thought about using caps, I was just hoping for a way around another 672 solder connections!

    David
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-12-29 19:57
    Aha! I'd move the "GOSUB off" immediately before the "OUTH = Result". Or even, put an "OUTH = %00000000" just before the "OUTH = Result".

    The way you've done it, the LED's are off for quite some time -- a Next, the next FOR calc, and the two READ's from the eeprom (which can take some time, I believe). But the LED's only need to be off for a very short time.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-12-29 21:53
    I'm still unclear about the hardware. Is the high side driven directly from the Stamp pins, OUTH, without any buffer? That may be straining the output drive capabilty of the Stamp port pins and not deliver the current and brightness you are expecting. 33 ohms in series with an LED on a 5 volt supply is a current of around 100 milliamps, and the Stamp can't deliver that, and if all 7 leds in a row are lit at the same time, it would be a strain on the port. You could protect the Stamp and also get more brightness with PNP driver transistors on the high side.

    The program could run faster and avoid the chaotic results if the data is stored as words in one table instead of bytes in two tables, to wit:
    '{$STAMP BS2pe}
    '{$PBASIC 2.5}
    counter VAR Byte
    result VAR Word   ' <-- word and leds are words, too
    leds DATA Word $fec5, Word $10b5, Word $10a5, Word $1095, Word $fe85
    DIRS = %1111111111111111
    main:
    FOR counter = 0 TO 4
    READ leds + (counter*2), Word result
    OUTS = result
    NEXT
    GOTO main
    
    



    I think with all the ports being set at the same time, there should not be a problem with the timing skew that is created when the Low and High are done by separate instructions. However, like Alan pointed out, putting an OUTS=0 immediately before the OUTS=result would effect a complete break before make action.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • DaphylDaphyl Posts: 17
    edited 2006-12-30 10:17
    ···· Ok, let me try and explain it a little differently.· Imagine a row of seven vertical LED's.· All the cathodes are tied together and connected to ground via a 2N2222 transistor.· If the 2N2222 transistor is off, nothing can light up in this row.· Now connect the·anodes of each LED to a·different·upper I/O port.· Depending on which ports are high, and if the transistor is activated, only the LED's on the ports set to high will light up.· Then turn the transistor off and all the LED's turn off.· Now image 47 more rows side by side just like this (the only difference is that all 48 anodes in each horizontal column of LED's are connected together).· When·any of the·upper I/O ports·are set to high there is the potential for all 48 LED's in that column to light up (disaster!), but because only one 2N2222 transistor is active at a time only one row of LED's (remember that each LED is powered by a different I/O port) can light up.
    ···· The lower eight I/O ports specify which 154 chip is active and which one of the 16 output pins on the 154 demultiplexer chip will be set to high (actually it's set to low, but all the outputs go through inverter chips) to turn on a 2N2222 transistor.· By sequentially turning the transistors on and off and selectively setting the upper ports high, I can scroll a message across all 48 rows.
    ···· I·hope this helps explain it better.· I tried moving the gosub·as per Allen's suggestion and I was shocked at the difference it made!· The wave affect is gone and now the·LED's twinkle nicely!· His suggestions also made me wonder why I was continually forcing all the·high I/O ports low, when all I had to do was disable the active 154 chip.· So by removing the OUTH statement,·turning off one lower I/O port in the off subroutine, and moving the gosub off statement; I now have a beautiful bright display.· I really like the idea of one data statement and I'm going to try that tomorrow.· Right now the wife is giving me some really mean looks, so I guess I'd better go.
    ···· By the way, I won two hundred and fifty LED's in a drawing at one of the local electronics stores.· Next time I build one of these I'm going to use 5 x 7 LED·matrix blocks!

    Thanks to all for your help,
    David Milsop·
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-12-30 12:03
    David -

    This is just a debugging suggestion from someone more familiar with software than hardware, but I suspect it may have some real merit. I would propose that what you are going to eventually find as the source of your problem, is something you said earlier. You said, in part:

    "The input side of each inverter chip is connected to one of the 16 outputs of a 74LS154 (4 to 16 demultiplexer chip)."

    Check the propagation delay on those mux/de-mux chips, as well as the inverters, and you may find your culprit. It may be most easily seen "graphically" by probing the output(s) with a "silly scope". I highly doubt that you will find that the program (software) or PIC/SX output buffer (Stamp hardware) is hiolding you up.

    Regards,

    Bruce Bates

    Post Edited (Bruce Bates) : 12/30/2006 12:22:28 PM GMT
  • DaphylDaphyl Posts: 17
    edited 2006-12-30 22:25
    ···· The 74LS04 has an average propagation time of 12 nano seconds average, and 22 nano seconds max.· The 74LS154 is a lot higher, 46 nano seconds average and 69 nano seconds max.· So even at their worst they are still a lot faster then the 140 micro seconds for the BS2 (high to low) or 105 micro seconds for the BS2pe.· There really is a wealth of info at www.emesystems.com·

    ···· I think I am going to add some buffers/line drivers·to the I/O ports.· When I put my scope on the outputs, I noticed that the voltage on the ports where only getting up to about 2.95v before shutting off.· I'll have to change the 33 ohm resistors too because these open collector drivers pump out a lot more current.

    David
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-12-31 00:38
    Hi David,

    The 105 microseconds for the BS2pe is the time that the interpreter takes to execute the instruction. The actual transition at the output is very rapid, on the order of nanoseconds. Setting the outputs in two instructions like this:
    OUTH=result
    OUTL=values
    leaves a 105 microsecond skew where OUTL still has the old value while OUTH has the new value. With this syntax:
    OUTS=result ' a word value
    the time skew is only a few nanoseconds, due to the different propogation delays through the high side switches and the low side mux.

    The output drivers in the Stamp (SX48) are remarkably robust, but their output resistance is on the same order of magnitude as your 33 ohm resistors. Assuming the LED is dropping 1.5 volts, that leaves about 1.5 volts across the 33 ohm resistor, which means the current to the LED is about 45 milliamps. (The effective output resistance of the Stamp pin is (5 volts - 3 volts)/0.045 = 44 ohms and the Stamp is dissipating 90 milliwatts into heat as a result.)

    From the SX48 data sheet, the maximum source or sink current on each individual BS2pe pin is 45 milliamps, and the maximum allowable for each 8 bit port (such as OUTH) is 50 milliamps total. But if all 7 LEDs happen to be on at once, then the total current for the port would be 315 milliamps--way over limit! That would not be a problem if it were a 1:48 cycle, but if the whole sign lights up with most of the 336 LEDs lit at once, the total could be very hard on the BS2pe.

    I think your idea to add a source driver on the high side is wise. It will both protect the Stamp and also allow for brighter LEDs. For a choice of discrete transistor as a source driver, I really like the LP0701 P-channel mosfet, from Supertex (Mouser carries them). It is a TO92 package that can source up to 1.5 amps in full on, and the gate can be driven directly from a Stamp pin on 5 volt power, low on gate turns the mosfet on. I don't know the ratings of the LEDs you are using. Are they superbrights? It is usually safe to drive LEDs quite hard, when the duty cycle is 1/48. That is, up to a point which should be found on the LED data sheet.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • DaphylDaphyl Posts: 17
    edited 2006-12-31 08:21
    Well I have to thank Tracy Allen. His suggestion to combine the two read statements into one and use OUTS worked wonderfully! But now I'm going to have to install those line drivers. With all the help I've gotten here, the program is running really fast, and as has been stated, the LED's are drawing too much power and really heating up my poor processor! But it is a nice bright display!

    Thanks again,
    David Milsop
Sign In or Register to comment.