PDA

View Full Version : 2 LEDs used Bi-directionally



Demon
- 12th January 2014, 00:38
I'm building a matrix using this idea:
http://www.picbasic.co.uk/forum/showthread.php?t=14439

7193

Pseudo-code:


GP0 TRIS 1 ' Input
GP1 TRIS 0 ' Output
GP1 = 1 ' Yellow ON

GP0 TRIS 0 ' Output
GP1 TRIS 1 ' Input
GP0 = 1 ' Red ON

Is that right?

And how do you turn them both off? Both output LOW?

Robert

rsocor01
- 12th January 2014, 03:03
Check this thread out. You might get some hints...

http://www.picbasic.co.uk/forum/showthread.php?t=13481&p=91692#post91692

Demon
- 12th January 2014, 03:26
I had read that thread already, but they were going PIN to VDD/VSS. I'm going PIN to PIN so I have to play with TRIS more. Rereading it did show me TRISx = 1 will turn off LEDs though.

Setting up the breadboard to test what I have so far. I better change for an old PIC, just in case of magic.
:)

rsocor01
- 12th January 2014, 03:44
TRISx = 1 is used to read an analog input, ex: A/D input. It turns the port into a high impedance input. So, if you want the port to sink in current just make that port low with TRISx = 0 like in the example in that thread.

Demon
- 12th January 2014, 05:00
I feel like a retard. So...

PIN --- DUAL LEDs --- RESISTOR --- 5VDC

PIN defined as output:

HIGH will source, turn on outgoing LED (like we always do)
LOW will sink, turn on incoming LED


I don't get how I'm to set ports/TRIS at both ends so neither LED will turn on. I've gone through that thread and a few others all evening but I can't see the forest through the trees apparently.



TRISx = 1 is used to read an analog input, ex: A/D input. ...

Even if my ports are defined as digital?

Robert

Demon
- 12th January 2014, 05:09
Found my answer to sinking the incoming LED.


Do I set it as an output then set it's low state?


YUP.

Think of it like this. LED connected anode to positive rail. To make it light with the cathode connected to a PIC pin you would output LOW. (LED has a drop down resistor)
...

http://www.picbasic.co.uk/forum/showthread.php?t=7638


PIN --- DUAL LEDs --- RESISTOR --- PIN

Is it a simple matter of leaving both pins output LOW? That would mean both are connected to ground; no chance of leaking current.

Robert

Heckler
- 12th January 2014, 05:52
Robert,

In your schematic at the top of the thread... the highlighted (green) LED's will be dark when GP 1&2 are BOTH High OR LOW. But the trick is to keep track of that interaction with the other LED's that are also tied to either of those two pins.

If GP1 is high and GP2 is low then the Yellow LED will be lit, and vice/versa for the Red one.

Seems like to me it's time to draw up a good ol'e fashioned truth table.

With 5 bits (pins) in use it will have 2 exp 5 = 32 possibilities. The truth table will also help you develop your code.

Is this what they call Charlieplexing?? I've never done one of those, but that is how it seems to my feeble mind.:)

good luck

Archangel
- 12th January 2014, 09:04
Hi Robert,
This is what Microchip did on their PICKIT1 demo board.

rsocor01
- 12th January 2014, 12:19
If GP1 is high and GP2 is low then the Yellow LED will be lit, and vice/versa for the Red one.

Seems like to me it's time to draw up a good ol'e fashioned truth table.

Yes, it seems like you are going to have more lit LEDs that what you want at any given time. More than one LED is going to light up for any given combination.

rsocor01
- 12th January 2014, 12:25
Even if my ports are defined as digital?



TRISx = 1 'Sets the port as analog
TRISx = 0 'Sets the port as digital

When TRISx = 1 the port is set to a high impedance input mode, meaning no current in or out for the LEDs. In other word it turns the port off for the LEDs.

Demon
- 12th January 2014, 14:26
TRISx = 1 'Sets the port as analog
TRISx = 0 'Sets the port as digital

When TRISx = 1 the port is set to a high impedance input mode, meaning no current in or out for the LEDs. In other word it turns the port off for the LEDs.

It seems I'm getting denser every year.

"high impedance input mode" means nothing to me.

"meaning no current in or out for the LEDs" <--- this I understand


You only have to explain things once to me, but repeat yourself 12 times, post 3 sample programs, add 6 pictures, include 4 schematics, and I'm good to go.

I really appreciate the patience you guys have.

Robert

AvionicsMaster1
- 12th January 2014, 17:19
In regard to the site mentioned in post #1:

Just to let you know I found the value of the current limiting resistors for the LEDs to be important. Set incorrectly they'd give me ghosting.

You also have to repeatedly set the TRISIO and the GPIO to get the specific LED or LEDs you want lit. Usually once wasn't good enough.

If you're in need of more than 20mA per pin I successfully used opto-isolators instead of the LEDs. I don't remember the specific part number but I think I posted that link somewhere. If needed I'll find it and reference it here.

I'd also suggest you put a switch in the ICSP clock and data lines to isolate the PIC for programming. It will save you alot of time and effort.

As always good luck and please post program here when finished.

Demon
- 12th January 2014, 19:38
In regard to the site mentioned in post #1:

Just to let you know I found the value of the current limiting resistors for the LEDs to be important. Set incorrectly they'd give me ghosting...

I'm using Darrel's interrupts to control blinking; both on and off duration. Ghosting is not a problem.



...You also have to repeatedly set the TRISIO and the GPIO to get the specific LED or LEDs you want lit. Usually once wasn't good enough...

I'm testing activating LEDs in bi-directionnal manner now. It's taking me a while 'cause I'm setting it up so the bytes RX from Master will line up with pin order. I'm also learning bit masking; never did that really.



...If you're in need of more than 20mA per pin I successfully used opto-isolators instead of the LEDs. I don't remember the specific part number but I think I posted that link somewhere. If needed I'll find it and reference it here...

I have MCT6 opto-isolators for now if needed. I don't know if I'll need faster, testing will show.



...I'd also suggest you put a switch in the ICSP clock and data lines to isolate the PIC for programming. It will save you alot of time and effort...

I simplified matters and dedicate MCLR, PGD, PGC, RX1 and TX1 pins.


Now I just have to figure my bits:



Port has: 10001001
Mask is: 10001111
Desired: 10000110 (bits 7-4 untouched, bits 3-0 reversed)

I made a truth table using an LCD to show how bitwise operators work. It's just setting up this particular syntax.

Robert


UPDATE: Have my bit masking working exsactly like I want it. Thanks everyone.

Demon
- 14th January 2014, 00:16
I'm building a matrix using this idea:
http://www.picbasic.co.uk/forum/showthread.php?t=14439
...

For those of you that are visual and like working with rows and columns like me, I came up with this design:

7194

You can have a lot more LEDs by using pins across ROWs and COLUMNs, but that adds more complexity than I can handle, and this is good enough for me.

By using a maximum of 8 pins per side in this configuration, you can use BYTEs and LOOPs to control lighting.

Robert

Demon
- 14th January 2014, 01:01
And this is how I plan to turn the LEDs ON-OFF 1 column at a time:

7195

(in theory, I still have to finish my breadboard)