Shop OBEX P1 Docs P2 Docs Learn Events
LED Segment Multiplex, Help Please? — Parallax Forums

LED Segment Multiplex, Help Please?

DroneDrone Posts: 433
edited 2007-07-06 02:41 in Propeller 1
Hi All...

New to Prop/Spin. I need to multiplex segments (not digits) on an LED display (yes have already successfully used the nice seven segment driver from Object Exchange).

Problem is (see attached .spin code), when I bitwise AND (&) with outa to scan segments with a variable that shifts left, prior segments remain lit, I want the segments to blank in-turn as I step through them.

Perhaps a better solution would be to repeat FROM TO and STEP in 2^n increments (1,2,4,8,...) but I can't figure out how to do this either.

Any suggestions most appreciated.

(BTW in the attached code there are seemingly unnecessary variable assignments and longs instead of bytes, but this is because eventually this will be called as a driver in a separate cog, and longs allow more segments, which would draw more current per output pin group, hence my moving to segment plus digit/character multiplexing, as in an LED alphanumeric display).

Regards, Dave

Comments

  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-07-04 21:32
    I think you can do this simpler with just a simple integer count in the repeat. And simple binary %0000001 that you shift one bit with each interation of the loovp.
    In your code:
    repeat segPos FROM %00000001 TO %10000000 'Repeat through segments

    I think the bit count will include all the values from %1 to %10000000.
  • DroneDrone Posts: 433
    edited 2007-07-05 09:35
    Thank you Fred for the reply. I think what you're saying is that all the counts from %1 to $10000000 will be included in the repeat? Even if that were so, if the bit-wise AND (&) were working in the outa statement, only one segment should be lit at any given time. This isn't happening, once a segment is lit, it remains lit until the inner repeat starts over. This is what's puzzling me. The bit-wise AND should ask as a "mask" that allows only one segment to be lit at any given time via the outa. I'm sure I'm missing something simple.

    Regards,

    Dave
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-07-05 10:01
    doing %00000001 to %1000000

    Will do segPos = 1 to 128 with no gaps, that's 1, 2, 3 .... or

    00000001
    00000010
    00000011
    etc etc

    You are probably really screwing this up with the shift.

    Try

    segPos := 1
    repeat 8
       outa[noparse][[/noparse]shPin..slPin] := %01111111 & segPos
       segPos := segPos << 1                             
       waitcnt (clkfreq / 2 + cnt)
    
    
    



    segpos will be 1, then 2 then 4 etc.

    Graham
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-07-05 10:05
    Well for one thing your loop counter, segPos, is reset in the third line:

    repeat segPos FROM %00000001 TO %10000000 'Repeat through segments
    outa[noparse][[/noparse]shPin..slPin] := %01111111 & segPos 'Scan segments for the character 8 (not working?)
    segPos := segPos << 1 'Shift-left segment to display (not working?)
    waitcnt (clkfreq / 2 + cnt) 'Pause 1/2 sec. between segments for debug

    And since its counting 1 to 128
    1st instance %1 shifted %10
    2nd instance %11 (I'm guessing here, loop ought to keep incrementing) shifted %110
    3rd instance %100, shifted %1000
    4th instance %101, shifted %1010
    5th instance %1011, shifted %10110
    6th instance %10111, shifted %101110
    and so on...

    The other thing that bothers me is that %01111111 mask ought to pass everything except the eighth bit.

    But I haven't run this program so I'm still guessing....
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-07-05 10:09
    Graham, great minds think alike [noparse]:)[/noparse]
    You're quicker and you have that nifty code in a box trick. (which escapes me) Guess I'll read the manual.
  • DroneDrone Posts: 433
    edited 2007-07-05 13:44
    Thanks Fred & Graham...

    Graham's code pasted-in and worked right off the bat. But I made one small change: The inner loop iterates 7 times, not eight (once per segment, I'm not using the decimal point at the moment). This works nicely for a single digit displaying 8:

      repeat
      segPos := 1
        repeat 7
          outa[noparse][[/noparse]shPin..slPin] := %01111111 & segPos
          segPos := segPos << 1
    
    
    



    Best Regards,

    David
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-07-05 17:04
    Fred, Open a square bracket write the word code and then close the bracket, write the code and then do the same again but write \code in the brackets.

    David, I thought it might be 7 but I didn't have time to do the mental run through I had to go to a meeting, I'd forgotten about the decimal anyway. Glad it works OK.

    Graham
  • DroneDrone Posts: 433
    edited 2007-07-05 22:48
    Oh yes Fred - I forgot to mention about the code box tags...

    In addition to typing code tags as Graham mentions, in the post edit page above the text box there's a button labed CODE. Hover your mouse over this button and it will give you a dialog on usage.

    Push the CODE button once and it auto-inserts the opening code tag, then type some text and hit the CODE button once again and it intelligenly auto-inserts the ending /code tag.

    Something I don't like about the CODE button is that it defaults to putting the opening code tag at the end of the last line in your post. So if you want to insert a code box in between lines of already written text, then using the CODE button to enter the code tags will see you cutting and pasting in the end.

    So, like Graham, I usually find it easier to just type the code tags manually. Remember to add square brackets around code and /code.

    Regards,

    David
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-07-06 02:39
    [noparse][[/noparse]quote] test no name quote function
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-07-06 02:41
    [noparse][[/noparse]quote] test no name function 
    

    doesn't work (in quick reply at least).

    Code does.

    Thanks David, Graham for the quick help.

    when in doubt, read the manual
    
Sign In or Register to comment.