LED Segment Multiplex, Help Please?
Drone
Posts: 433
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
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
spin
2K
Comments
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.
Regards,
Dave
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 will be 1, then 2 then 4 etc.
Graham
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....
You're quicker and you have that nifty code in a box trick. (which escapes me) Guess I'll read the manual.
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:
Best Regards,
David
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
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
doesn't work (in quick reply at least).
Code does.
Thanks David, Graham for the quick help.