Question about outa
jim N8RHQ
Posts: 85
Could someone help me understand the difference between sequences
outa[leftLED..rightLED] := %001
and
outa[leftLED..rightLED] := %000
outa[leftLED..rightLED] := %001
or
outa[leftLED..rightLED]~
outa[leftLED..rightLED] := %001
well, I mean besides the obvious of explicity setting leftLED..rightLED to 000 before setting rightLED high?
I thought the first line would clear any previous settings of leftLED..rightLED in favor of the new value. I've
had to add one or the other extra lines to make this work on my MSR1 and I dont understand why. I do
have a seperate cog running and have dira[leftLED..rightLED]~~ and outa[leftLED..rightLED]~ as the first
two lines, which from reading the manual I didnt think was necessary, but seems to be.
outa[leftLED..rightLED] := %001
and
outa[leftLED..rightLED] := %000
outa[leftLED..rightLED] := %001
or
outa[leftLED..rightLED]~
outa[leftLED..rightLED] := %001
well, I mean besides the obvious of explicity setting leftLED..rightLED to 000 before setting rightLED high?
I thought the first line would clear any previous settings of leftLED..rightLED in favor of the new value. I've
had to add one or the other extra lines to make this work on my MSR1 and I dont understand why. I do
have a seperate cog running and have dira[leftLED..rightLED]~~ and outa[leftLED..rightLED]~ as the first
two lines, which from reading the manual I didnt think was necessary, but seems to be.
Comments
I read the manual the same way, but if I take the outa[leftLED..rightLED]~ out of the seperate cog, or any where else for that matter, I end up with led's lit that shouldnt be. dira[leftLED..rightLED]~~ and outa[leftLED..rightLED]~ are the only
two references in the cog.
Yeah, your problem is that you are reversing the bit order. Since Right is 5 and Left is 3, you need to enumerate Right..Left for the literal value to match the order of the array reference.
A simpler way to do this, without error, is OUTA[LeftLED]~ or OUTA[RightLED]~
I've been very consistant with my bit order, but ordering from highest pin to lowest pin to match MSB I was not aware of. Thank you!
I have reversed the bit order as you suggested, and removed the extra outa[rightLED..leftLED]~ lines, and I'm back to having more than one led on at a time.
I understand your simpler way, but outa[rightLED..leftLED] := 001 or 010 or 100 helps me visualize which LEDs I'm turning on and trying to turn off a little better.
new code attached
You can use either order. For example, both of these turn on the left LED:
-Phil
Thanks, Phil. Turning on seems to work great, but it's the turning off that's not working so great
Are you certain that more than one LED is on at a time? Or could they be alternating so fast that they just look like they're on simultaneously?
-Phil
Please try this program by itself, and report what happens:
-Phil
-Phil
(PS: like already posted by PhiPi in the meanwhile;o)
What can happen is, that you change the LEDs to fast which would be recognized as having two LEDs on at the same time but in reality the LEDs are never on at the same time! So, in your program this means that several if-cases are true at the same time or at least to fast to see the different LED-states on their own.
What puzzles me for example is your ping-function! If I want to compare r and l, I'd make sure that both values have been measured at points in time as close together as possible! So, I would do all 3 measurements straight after another and then wait for 10ms. Otherwise in case your motors are on, you would compare values which do not really belong together.
As you measure 3 values it would also be good to write all 3 bytes in one instruction from local storage to the global variables and then from global variables back to some other local variables in your main-program. Otherwise you'll have the same problem - comparing a set of values which do not belong together.
Also, don't forget: any methods in external objects called from that cog use the same stack.
-Phil
red on blue off green off
red on blue on green dim
red on blue dim green on
red on blue dim green dim
red on blue on green dim
red on blue dim green on
red on blue dim green dim
red dim blue on green dim
red dim blue dim green on
red on blue dim green dim
red off blue on green dim
red dim blue dim green on etc.
Anticipating the question, P3 is wired 330 ohm to red led to ground , P4 is wired to blue led to 470 ohm to ground, P5 is wired to 470 ohm to green led to ground.
You didn't specify it: which program shows that behavior? Yours or mine?
-Phil
yours
-Phil
I'm on the 5v side, I've made no changes to the board.
Have you looked at the datasheet for the TXB0108 level shifters used on the MSR1 board? Based on my reading of it, I have to conclude that they are neither designed for, nor capable of, driving LEDs directly. I would recommend adding either transistor drivers or a logic buffer between the level translator and the LEDs to isolate their current requirements from the translator. I can't say for sure that this is the root of the behavior you're seeing. But I can say that it has nothing to do with the software. It's definitely a hardware issue.
-Phil
I must admit I have not read the datasheet for the TXB0108. I'm not real sure I got the idea I could drive an led. I will see about wiring up some transistors. I've been planning to do that anyway because I want to drive some ir leds as bright as possible.
Thank you for your help.
I really wanted to solve this before moving on with more enhancements and I just couldnt understand or accept that I had to add the extra lines to make it work. How can I move forward if I dont understand outa? It was driving me just a little nuts.
I'm not type A, I'm not type A, I might be OCD, but I'm not type A :-)
It will take me a day or two to scare up some transistors and suitable resistors, I'll post back then. Thanks again!
Merry Christmas
jim
I tried driving some transistors with the level shifters. It works great now.
LEDs now turn off when they should, and now even brighter with the increased current.
Big big thanks for the help.
RTFM, what a concept!
I'm glad you got it working! Bidirectional level shifters are some of the most misunderstood ICs out there -- including by those who design them into a circuit. They're certainly not the panacea that they might appear to be at first blush and, IMO, they seldom meet their design objectives without severe compromise.
-Phil