Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Multiplexing ? Newbie help

Status
Not open for further replies.

Lighty

New Member
Hi all

I've recently bought a PICKit 2 programmer and I am still learning the basics.

I have managed to program a couple of flashing patterns to the 18f690 on the dev board using GCBasicIDE. I'm a novice so please take it easy on me as I don't a grate deal on knowledge, I do how ever understand electronics to a degree.

So this brings me to my questions.

Multiplexing? This is where you would use a "group" of "share" output with individual Commons. Like when using 7 segment LED, you can use several segments all saring the same inputs but using individual grounds, the grounds are triggered in sync with the relivent segment signals....?

Ok so heres my problem, I busy with a project that has over 30 LEDs, 20x 2 way switches (with off in the middle), 7x 5 position rotory switches and 7x 7segment LEDs.......


My idea thought


Basically, the rotary switches are for controlling the speed of some motors via the PWM outputs, there is one 7seg per rotary switch, showing its position, Eg 1,2,3,4,5,0. I though of using a analog input per switch using the method I've seen on a 4x4 botton keypad, using resistors across the switch outputs to create a different voltage per position, changing the code to change the PWM output.... can this be done?

The next big user of I/O pins will be the 20 switches (on-off-on) for the "auto" (where the MCU will do the controlling), off, and "manual" where the output will be activated (override). Normally you would just push your signal from the MCU through the one pole of the switch to the divice and use the other pole to drive directly -thereby choosing the Auto or Man input - hope that make sence? - but there are 2 status LED for each switch, 1 shows Auto mode and other Man. mode.

So the only way I can think of doing this is multiplexing the LEDs so to use only 14 (10x4) pins and not 40.....?

I have not yet decided on the PIC chip, any ideas?, but would have to be at least a 40 pin PIC? could I not use 2 DIP PICs apposed to a TQFP mount as this is a home made DIY project................

Please help with any advise.:confused:
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Check my tutorials - one of which multiplexes two 7 segment displays on a single port, and one 64 LED's on two 8 bit ports.

For 40 LED's, 4x10 (14 pins) would be a poor choice, 5x8 would only use 13 pins, and is more convenient for programming, as it only requires a port width, and not a port width plus 2.

There's also one for multiplexing a hex keypad - 16 keys (4x4).
 
Last edited:

Magen

New Member
Hi Lighty,
You could also look at using shift registers to increase the number of inputs/outputs. Nigel's tutorials will also help you with sending/receiving data serially.
 
Last edited:
Can't help but think that the seven 5 pole switches are going to be expensive. Why not just look at it from a digital solution? It would simplify the project a lot, and get rid of unnecessary indicator leds.

If I have this right you are trying to control 7 motors? The 16f690 could do the job. So at a minimum there would need to be:

10 outputs:
7 for software PWM's
3 for the seven chained 74HCT595's (i.e. one for each 7 seg display)

7 inputs:
7 one each for the motor control (resistor divider for each fixed speed/button)

Arguably buying the seven 595's would put you in the range of a 40 pin PIC, so another interesting solution would be two 40 pin 18f4331's. You would then have 8 total hardware PWM's, and your 40 leds to boot (as long as you don't go over the max package current).

Here is a GCBasic example of using two 595's to light up some leds. To use for 7 segment displays, a select case scenario would be required for each digit.

Code:
'A program to flash 16 LEDs with two HC595's
'pins - OE tied low, Reset tied high
 
'Chip model 
#chip 16f88, 20

#define Data PortB.0
#define Latch PortB.1
#define Clock PortB.2

dir PortB.0 out
dir PortB.1 out
dir PortB.2 out

dim loop as word

Start:
For loop = 1 to 65535
	Shiftout Loop
	wait 1 ms
Next
goto Start  

'--------------------------------------------------
Sub Shiftout (Dataout as word) #NR

Latch = 0				'Start output data latch
	For Clocks = 1 to 16
	  Clock = 0			'Shift register clocked
	  Data = Dataout.0
	  Clock = 1
	  Rotate Dataout Right Simple
	Next Clocks
Latch = 1								
					
End Sub
'--------------------------------------------------
 

Lighty

New Member
Can't help but think that the seven 5 pole switches are going to be expensive. Why not just look at it from a digital solution? It would simplify the project a lot, and get rid of unnecessary indicator leds.

I got the "control Panel" to fitted with most hardware already:D I'm not 100% but think they are Break Before Make, if not would this be a problem?


If I have this right you are trying to control 7 motors?

No, Only 2 motors

The 16f690 could do the job. So at a minimum there would need to be:

10 outputs:
7 for software PWM's
3 for the seven chained 74HCT595's (i.e. one for each 7 seg display)

7 inputs:
7 one each for the motor control (resistor divider for each fixed speed/button)

Arguably buying the seven 595's would put you in the range of a 40 pin PIC, so another interesting solution would be two 40 pin 18f4331's. You would then have 8 total hardware PWM's, and your 40 leds to boot (as long as you don't go over the max package current).

Here is a GCBasic example of using two 595's to light up some leds. To use for 7 segment displays, a select case scenario would be required for each digit.

Code:
'A program to flash 16 LEDs with two HC595's
'pins - OE tied low, Reset tied high
 
'Chip model 
#chip 16f88, 20

#define Data PortB.0
#define Latch PortB.1
#define Clock PortB.2

dir PortB.0 out
dir PortB.1 out
dir PortB.2 out

dim loop as word

Start:
For loop = 1 to 65535
	Shiftout Loop
	wait 1 ms
Next
goto Start  

'--------------------------------------------------
Sub Shiftout (Dataout as word) #NR

Latch = 0				'Start output data latch
	For Clocks = 1 to 16
	  Clock = 0			'Shift register clocked
	  Data = Dataout.0
	  Clock = 1
	  Rotate Dataout Right Simple
	Next Clocks
Latch = 1								
					
End Sub
'--------------------------------------------------

Thx Nickelflippr but I'm :confused::confused::confused:
 
Thx Nickelflippr but I'm :confused::confused::confused:
Well, the example given shows how to light 16 leds (or two seven segment displays with modification) with just three outputs and two 74HC595's. There are tons of examples on the net, take a look, and read the data sheet. Is there confusion about that?

Using the 595's give you full led brightness, and uses less microcontroller pins. If you multiplex the leds, or the seven segment displays, the brightness will be diminished. GCBasic has a seven segment library that will multiplex 4 displays in a common cathode configuration. This would require one port plus 4 address pins (and transistors) to enable/disable each display. If you need code for common anode configuration let me know.

Since you have most of the parts, here is experiment you can try right now.
The GCBasic code for two multiplexed seven segment displays, can expand up to four displays:
Code:
#chip 18f4620,20
#config MCLRE = On
'This program will show "Hello" on a LED display
'The display should be connected to PORTB

#define DisplayPortA PORTB
#define DisplayPortB PORTB
#define DispSelectA nop  
#define DispSelectB nop  
#define Display1 PortA.0
#define Display2 PortA.1
#define waitDisplay wait 12 ms
#define CommonAnode  'extra code required in library!!!!
dir PortB out
dir PortA.0 out
dir PortA.1 out 

main:
DIM Message(10)
Message() = "HelloYou"
For counter = 1 to 8 
	For seeDisplay = 1 to 25
		Set Display2 Off:Set Display1 On
		DisplayChar 1, Message(counter)
		waitDisplay
		Set Display1 Off:Set Display2 On
		DisplayChar 2, Message(counter)
		waitDisplay
	next
next

for Counter = 0 to 99
	Seg2 = Counter/10
	Seg1 = Counter % 10
	For seedisp = 1 to 7
		Set Display2 Off:Set Display1 On
		DisplayValue 1, SEG1
		waitDisplay
		Set Display1 Off:Set Display2 On
		DisplayValue 2, SEG2
		waitDisplay
	next
next
goto main
 

Lighty

New Member
Thanks Nickelflippr,

If I understand correct, when you multiplex using the "ports" all the anodes for each segment is connected in parallel, and use another bit per segment to trigger the cathode, in other words, the bits will change in sync with the triggering of each segments common cathode....(sorry, I'm bad in trying to explain) but basically segment 1 will light then turn of, the seg 2 will light then turn off and so one, so quickly it looks like it stays on? but if too many segments are added, the time delay between "refreshing" is too long and would cause the segment to look dim?

And using the 74h595, it would stay light until its refreshed with something different? how many segments can you "chain up" together?
 
Yes, I think you have it.

Don't know how many cmos chips you can chain together. My guess is plenty, not in the device data sheet, maybe some analog person knows that one?
 

Lighty

New Member
but if they all linked, what makes them chain one after the other and not all the same time? would they have different ID or something?
 

Lighty

New Member
Ok, so I need to control plenty single LEDs and a couple 7 Segments, could this be done off the same "String" of 74HC595's? or would this cause a problem?

Could I run to seperate "strings" of 74HC595" or can only 1 set of pins be setup as the Latch, Data and Clock?
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top