Can I do this with a uProcessor?

8 views
Skip to first unread message

tempus fugit

unread,
May 20, 2007, 11:22:14 PM5/20/07
to
Hi all;

I currently have a switching system that uses logic like latches and
inverters, along with lots of diodes. I'm thinking about changing some
things in it, and was wondering if I shouldn't just revamp the whole thing
and go to a PIC. Here's what I would like it to do:

I have 14 switches - when any one of them was switched to ground
(momentary), it would cause the PIC to:
1. clear any previous data in the PIC
2. latch a signal to the required output that would ramp up the control
voltage over a few ms.

I have a 15th switch that when switched causes the each switch to activate a
different set of devices (sort of like having 2 different banks). Could I
use a PIC to have the same function, kind of like having it latch that
switch in one position or another, and telling the PIC to execute the proper
instruction?

These switches control 6 different relays to switch in different effects or
effects combinations for my guitar pedalboard. Would I need many PICs to
accomplish this, or would it be possible to set things up with just one?

I suspect these are fairly newb questions, but I don't know what types of
things are possible with the instruction set available with a PIC. I have
downloaded a couple data sheets, but at about 200 or more pages each,
there's a lot to digest, and i don't quite understand it all yet.

Is it possible to do these things with a PIC?

Thanks

Spehro Pefhany

unread,
May 21, 2007, 8:08:12 AM5/21/07
to
On Sun, 20 May 2007 23:22:14 -0400, the renowned "tempus fugit"
<toc...@quitspammingme.ciaccess.com> wrote:

>Hi all;
>
>I currently have a switching system that uses logic like latches and
>inverters, along with lots of diodes. I'm thinking about changing some
>things in it, and was wondering if I shouldn't just revamp the whole thing
>and go to a PIC. Here's what I would like it to do:

PIC is a trade name for several ranges of microcontrollers from one
manufacturer. There are many others.

A microcontroller is essentially a microprocessor with
RAM/ROM/periperals on board (though definitions vary somewhat).

>I have 14 switches - when any one of them was switched to ground
>(momentary), it would cause the PIC to:
>1. clear any previous data in the PIC
>2. latch a signal to the required output that would ramp up the control
>voltage over a few ms.

The ramping up is perhaps best done with some analog circuitry. Since
the switches are manually actuated you could perhaps scan them at,
say, 500Hz rather than deal with them individually (much like your PC
keyboard)

>I have a 15th switch that when switched causes the each switch to activate a
>different set of devices (sort of like having 2 different banks). Could I
>use a PIC to have the same function, kind of like having it latch that
>switch in one position or another, and telling the PIC to execute the proper
>instruction?
>
>These switches control 6 different relays to switch in different effects or
>effects combinations for my guitar pedalboard. Would I need many PICs to
>accomplish this, or would it be possible to set things up with just one?

Probably just one. The main limit is how fast things have to happen,
if a few msec here or there is not important, then you can do some
very complex things with a micro running at a reasonable clock
frequency. The number of I/O may come into play, but there are ways of
expanding the I/O (scanning etc.) and there are lots of micros with
100, 200+ or more 'pins'.

>I suspect these are fairly newb questions, but I don't know what types of
>things are possible with the instruction set available with a PIC. I have
>downloaded a couple data sheets, but at about 200 or more pages each,
>there's a lot to digest, and i don't quite understand it all yet.
>
>Is it possible to do these things with a PIC?
>
>Thanks

From what you have said, most likely yes, however you will have a
learning curve to deal with. Start with something simple like blinking
an LED at a visible frequency and work from there. Be sure to check
out the reference manual for the product line you're looking at too.
It may seem like a lot, but the more detailed information rather than
the skinned down data sheet will be helpful.


Best regards,
Spehro Pefhany
--
"it's the network..." "The Journey is the reward"
sp...@interlog.com Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog Info for designers: http://www.speff.com

MooseFET

unread,
May 21, 2007, 9:27:17 AM5/21/07
to
On May 20, 8:22 pm, "tempus fugit"

<tocc...@quitspammingme.ciaccess.com> wrote:
> Hi all;
>
> I currently have a switching system that uses logic like latches and
> inverters, along with lots of diodes. I'm thinking about changing some
> things in it, and was wondering if I shouldn't just revamp the whole thing
> and go to a PIC. Here's what I would like it to do:

I suggest you say "micro" not "PIC" and consider other types. I'll
explain why as we go through the various requirements.


> I have 14 switches - when any one of them was switched to ground
> (momentary),

You want to have 14 port connections to do this with so we now know
one specification of the micro.

You didn't say how quickly it needs to react. Since a human is
pushing the switch, perhaps 20mS or so should be the required maximum
responce time.

> it would cause the PIC to:
> 1. clear any previous data in the PIC
> 2. latch a signal to the required output that would ramp up the control
> voltage over a few ms.

This sounds like you want a micro with a built in DAC or an external
DAC connected to the micro. How smoothly does it need to ramp and how
linear etc? How many output lines need to be ramped? Does only one
go high at a time?

You can use fairly simple analog circuits to make a ramp. You also
didn't speak about how the signals ever go low again. I assume they
do this also with a ramp.


> I have a 15th switch that when switched causes the each switch to activate a

Opps make the 15 port lines.

> different set of devices (sort of like having 2 different banks). Could I
> use a PIC to have the same function, kind of like having it latch that
> switch in one position or another, and telling the PIC to execute the proper
> instruction?

This is simple code.


> These switches control 6 different relays to switch in different effects or

Ok so now we have a total of 15+6=21 port connections.

> effects combinations for my guitar pedalboard. Would I need many PICs to
> accomplish this, or would it be possible to set things up with just one?
>
> I suspect these are fairly newb questions, but I don't know what types of
> things are possible with the instruction set available with a PIC. I have
> downloaded a couple data sheets, but at about 200 or more pages each,
> there's a lot to digest, and i don't quite understand it all yet.
>
> Is it possible to do these things with a PIC?

Now I'm going to suggest you reconsider the question of which micro.
You could look at the ones at www.cygnal.com as an example of a very
different one. There are lots and lots of chips that can do what you
want.


Eeyore

unread,
May 21, 2007, 9:39:59 AM5/21/07
to

tempus fugit wrote:

Very much so.

I'd code it as a finite state machine actually. The actual processor
instructions barely matter btw. For ease of programming most ppl would use
compilers for a high level language. PICBASIC is simple and only costs $99.95
http://www.melabs.com/products/pbc.htm

Graham

tempus fugit

unread,
May 21, 2007, 10:52:11 AM5/21/07
to
> You didn't say how quickly it needs to react. Since a human is
> pushing the switch, perhaps 20mS or so should be the required maximum
> responce time.
>

It needs to switch a relay quickly enough so that it seems like stomping the
switch instantly causes the effect to go on. I didn't even know that
respsonse time was something that needed consideration (told you I was a
newb).


> > it would cause the PIC to:
> > 1. clear any previous data in the PIC
> > 2. latch a signal to the required output that would ramp up the control
> > voltage over a few ms.
>
> This sounds like you want a micro with a built in DAC or an external
> DAC connected to the micro. How smoothly does it need to ramp and how
> linear etc?

I just want it to take a few ms to ramp up the relay driver before the relay
switches so that any capacitative clicks are avoided. I don't know if that
needs to be linear or smooth or what (help?)


How many output lines need to be ramped? Does only one
> go high at a time?

Well this depends on how many micros I need to do the job. All the outs
would need to be ramped, but if possible, I would like to have 6 outputs -
one to each relay - an probably a max of 4 on at a time.


>
> You can use fairly simple analog circuits to make a ramp. You also
> didn't speak about how the signals ever go low again. I assume they
> do this also with a ramp.

Hopefully yes. They will go low from requirement 1 - clear any previous data
in the PIC.


>
>
> > I have a 15th switch that when switched causes the each switch to
activate a
>
> Opps make the 15 port lines.
>
> > different set of devices (sort of like having 2 different banks). Could
I
> > use a PIC to have the same function, kind of like having it latch that
> > switch in one position or another, and telling the PIC to execute the
proper
> > instruction?
>
> This is simple code.
>

That's what i wanted to hear!

Thankjs for your help Moose - and i'll check out that other site. I'm glad
for any other advice as well.


Don Lancaster

unread,
May 21, 2007, 12:12:46 PM5/21/07
to
It is UNTHINKABLE to NOT use a PIC for this ap.


--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: d...@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com

Gary Tait

unread,
May 21, 2007, 2:39:25 PM5/21/07
to
Eeyore <rabbitsfriend...@hotmail.com> wrote in
news:4651A160...@hotmail.com:

> PICBASIC is simple and only costs $99.95
> http://www.melabs.com/products/pbc.htm
>


I'd use Bacom AVR, which is free for up to 2K code (or at least was last I
used it), and Atmel micros.

Or you get a Basic Stamp.

Gary Tait

unread,
May 21, 2007, 2:48:59 PM5/21/07
to
"tempus fugit" <toc...@quitspammingme.ciaccess.com> wrote in
news:e9837$46510fed$d1d89b9d$31...@PRIMUS.CA:

> Hi all;
>
> I currently have a switching system that uses logic like latches and
> inverters, along with lots of diodes. I'm thinking about changing some
> things in it, and was wondering if I shouldn't just revamp the whole
> thing and go to a PIC. Here's what I would like it to do:
>
> I have 14 switches - when any one of them was switched to ground
> (momentary), it would cause the PIC to:

Could the be muxed, or read with a diode binary convertor?

> 1. clear any previous data in the PIC
> 2. latch a signal to the required output that would ramp up the
> control voltage over a few ms.

You might be able to do the ramp in analog.



> I have a 15th switch that when switched causes the each switch to
> activate a different set of devices (sort of like having 2 different
> banks). Could I use a PIC to have the same function, kind of like
> having it latch that switch in one position or another, and telling
> the PIC to execute the proper instruction?

Simple.

> These switches control 6 different relays to switch in different
> effects or effects combinations for my guitar pedalboard. Would I need
> many PICs to accomplish this, or would it be possible to set things up
> with just one?

Just one.

>
> I suspect these are fairly newb questions, but I don't know what types
> of things are possible with the instruction set available with a PIC.
> I have downloaded a couple data sheets, but at about 200 or more pages
> each, there's a lot to digest, and i don't quite understand it all
> yet.

They are pretty dumb. Just I/Os you need to interface with code.
With the right tools, the code is pretty easy, especially for such a
simple task as yours.

I even have the code in my head (at the BASIC version of what it is).

With extra code, you can have it field programmable, and have a display
and/or indicators.

Eeyore

unread,
May 21, 2007, 2:58:32 PM5/21/07
to

Don Lancaster wrote:

> tempus fugit wrote:
> >
> > Is it possible to do these things with a PIC?
>

> It is UNTHINKABLE to NOT use a PIC for this ap.

You could use a Philips LPC ! That would be my choice in fact as I'm familiar with
the family.

Graham

tempus fugit

unread,
May 21, 2007, 5:57:42 PM5/21/07
to

"Don Lancaster" <d...@tinaja.com> wrote in message
news:5bduo0F...@mid.individual.net...


Do you mean an actual PIC, or any uProcessor?

at http://www.tinaja.com


tempus fugit

unread,
May 21, 2007, 5:59:37 PM5/21/07
to

>
> The ramping up is perhaps best done with some analog circuitry. Since
> the switches are manually actuated you could perhaps scan them at,
> say, 500Hz rather than deal with them individually (much like your PC
> keyboard)

I'm not familiar with this. What do you mean by scan them at 500Hz?

Thanks

Eeyore

unread,
May 21, 2007, 6:05:47 PM5/21/07
to

tempus fugit wrote:

He's thinking of a way of trying to eliminate the effect of switch bounce I
think.

Provided your switches only do 'X' when pressed rather than released, there's a
very simple way of avoiding the issue entirely in software though.

Graham

tempus fugit

unread,
May 21, 2007, 6:09:03 PM5/21/07
to

"Eeyore" <rabbitsfriend...@hotmail.com> wrote in message
news:465217D3...@hotmail.com...


I get it now.

Thanks Graham


tempus fugit

unread,
May 21, 2007, 6:12:47 PM5/21/07
to
> From what you have said, most likely yes, however you will have a
> learning curve to deal with. Start with something simple like blinking
> an LED at a visible frequency and work from there.

I had planned to do that; however, I would like to experiment with the
uProcessor I'll actually need to do the job if that's at all possible, thus
saving time and hopefully money. Is there a model # you'd suggest for this
task? Should I try to find 1 device with 21 port connections, or use a
couple and (if it's possible?) interface them somehow? Most of the tutorials
I've seen on the web are for 20 pin DIPs, which would be easy to experiment
with. I'm not sure how I'd go about trying to experiment with a surface
mount package.

Thanks

Eeyore

unread,
May 21, 2007, 6:13:06 PM5/21/07
to

tempus fugit wrote:

> "Eeyore" wrote:
> >
> > Provided your switches only do 'X' when pressed rather than released,
> > there's a very simple way of avoiding the issue entirely in software though.
>

> I get it now.
>
> Thanks Graham

You're welcome. It's cute isn't it ?

Graham


Eeyore

unread,
May 21, 2007, 6:14:08 PM5/21/07
to

tempus fugit wrote:

> > From what you have said, most likely yes, however you will have a
> > learning curve to deal with. Start with something simple like blinking
> > an LED at a visible frequency and work from there.
>
> I had planned to do that

I have a file here called "blinkled.p51".

It's a handy test.

Graham

Rich Grise

unread,
May 21, 2007, 7:20:49 PM5/21/07
to

That means that the uP is running a program that samples all of its inputs,
one at a time, 500 times per second (for the whole set). This is much
faster than is needed to give a response that looks immediate to the naked
eye, and probably fast enough to do debouncing in software (or firmware,
which is software in FLASH/PROM). 1/500 of a second comes out to 2
milliseconds per sample, which is time enough to take five samples within
10 milliseconds, which was the "bounce time" of some switch that I looked
up, and probably fairly typical.

Hope This Helps!
Rich

MooseFET

unread,
May 21, 2007, 9:52:20 PM5/21/07
to
On May 21, 7:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
[....]

> > This sounds like you want a micro with a built in DAC or an external
> > DAC connected to the micro. How smoothly does it need to ramp and how
> > linear etc?
>
> I just want it to take a few ms to ramp up the relay driver before the relay
> switches so that any capacitative clicks are avoided. I don't know if that
> needs to be linear or smooth or what (help?)

Ok, so maybe we can strike the DAC out of the specs. A very simple RC
low pass filter will likely do what you need. How high is "high" and
how low is "low"? I'm thinking in terms of using an op-amp if the
signal needs to be bigger than the natural swing of the port pins.


[...]


> Well this depends on how many micros I need to do the job. All the outs
> would need to be ramped, but if possible, I would like to have 6 outputs -
> one to each relay - an probably a max of 4 on at a time.

If you are using an op-amp, they come 4 to a chip. It makes sense to
go up to the next multiple of 4 lines. BTW: Unless I missed
something, we are only talking of one processor to do lets say 24
lines.

[...]


> Thankjs for your help Moose - and i'll check out that other site. I'm glad
> for any other advice as well.

Look up the following parts and look at the datasheets:

LM340
LT1499
LM324
2N2222
1N4004

I'm almost certain the design will have most of those parts in it. I
suggest the LT1499 for a reason I'm about to explain so that others
don't throw too many stones at me.

The LT1499 is the op-amp I could remember had a rail to rail input and
output and also has diodes across the inputs. Here's the circuit I'm
thinking of:

ASCII art:
----!!-----
! !
! V+ !
! ! !
PORT PIN -/\/\----+----!-\ !
! >---+--- RAMP
Vcc/2--------!+/
!
GND

It makes a nice linear ramp up and down.


tempus fugit

unread,
May 21, 2007, 10:38:49 PM5/21/07
to

As for voltages, I have 12, 9 and 5v available to me at present. Hi would be
+5 (to control the relay driver), and lo would be ground I think. If I cant
do it easily in software, I may just go with an RC circuit. The idea is to
rebuild what I currently have with the minimum of parts. What would be ultra
slick would be to use a 13 I/O port device and somehow use it for the 6 ins
and outs, since I only have to control 6 parameters. Some switches, though,
would turn on more than one thing at a time, and I haven't yet figured out a
way to connect the switches so that each switch would only switch what i
wanted it to. For instance, if I have a switch that switches A, and 1 that
switches B, and 1 that switches A and B, I can't figure out a way to wire
that to 3 in pins so that they don't all interact.

Thanks again


Eeyore

unread,
May 21, 2007, 10:51:36 PM5/21/07
to

Rich Grise wrote:

If you're only looking for a momentary make, you don't even need to debounce.

Graham

Eeyore

unread,
May 21, 2007, 10:56:43 PM5/21/07
to

MooseFET wrote:

> If you are using an op-amp, they come 4 to a chip.

Sometimes.

Graham

Spehro Pefhany

unread,
May 22, 2007, 8:36:48 AM5/22/07
to

Suppose you have 14 keys. You have a single 8 bit I/O port. We will
assume that only one key can be pressed at once, otherwise you'll have
a bit more complexity.

So you make half of the pins inputs and the other half outputs.

You drive one of the four outputs (say) low and float the others
(essentially make them inputs). Then read the four inputs at once.
That gives you the states of 4 keys. Repeat 3 more times with a
different output low and you have all 14 (or 16) key states.

VCC
+
|
.-.
| |
| |
'-'
|
input P0 --+---------------------------------
| | | |
VCC \ o \ o \ o \ o
+ \ \ \ \
| \. \. \. \.
.-. o o o o
| | | | | |
| |
'-' P4 P5 P6 P7
|
input P1 -+---------------------------------
| | | |
\ o \ o \ o \ o
\ \ \ \
\. \. \. \.
o o o o
| | | |

P4 P5 P6 P7


etc.

P0..P3 inputs only
P4..P7 are low or float

(For a real design for production we'd probably have some series
resistors on the port pins and the pullups might be built into the
chip)

Debouncing is another issue. It's not that difficult to do for all
cases in software (and get rid of glitches at the same time), but if
you only want the keys to start something you may not even need it.

Eeyore

unread,
May 22, 2007, 7:53:31 AM5/22/07
to

Spehro Pefhany wrote:

> the renowned "tempus fugit" wrote:
> >
> >I'm not familiar with this. What do you mean by scan them at 500Hz?
>
>

> Suppose you have 14 keys. You have a single 8 bit I/O port. We will
> assume that only one key can be pressed at once, otherwise you'll have
> a bit more complexity.
>
> So you make half of the pins inputs and the other half outputs.
>
> You drive one of the four outputs (say) low and float the others
> (essentially make them inputs). Then read the four inputs at once.
> That gives you the states of 4 keys. Repeat 3 more times with a
> different output low and you have all 14 (or 16) key states.

I would so NOT advise key scanning in a sensitive audio product !

It's a bitch trying to get rid of the noise form the scanning. A few more I/O
pins is so simple in comparison.

Graham

MooseFET

unread,
May 22, 2007, 9:18:05 AM5/22/07
to
On May 21, 7:38 pm, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
[....]
>

> > ASCII art:
> > ----!!-----
> > ! !
> > ! V+ !
> > ! ! !
> > PORT PIN -/\/\----+----!-\ !
> > ! >---+--- RAMP
> > Vcc/2--------!+/
> > !
> > GND
>
> > It makes a nice linear ramp up and down.
>
> As for voltages, I have 12, 9 and 5v available to me at present. Hi would be
> +5 (to control the relay driver), and lo would be ground I think. If I cant

A micro running on the 5V and RC filters on the port outputs may be
the best way to go. It certainly is one worth considering. You won't
be able to do much better on the parts count issue.


[....]


> and outs, since I only have to control 6 parameters. Some switches, though,
> would turn on more than one thing at a time, and I haven't yet figured out a
> way to connect the switches so that each switch

You have made an error in thinking here. The switch only informs the
micro that the switch is closed. The micro knows which group of
things to activate for a given switch. This makes the wiring very
simple.

Gary Tait

unread,
May 22, 2007, 11:07:01 AM5/22/07
to
"tempus fugit" <toc...@quitspammingme.ciaccess.com> wrote in
news:c4064$465218e5$d1d89b70$17...@PRIMUS.CA:

You don't need 21, just 5 for input (14 switches in binary, plus the
bank swap, which you could incorporate into the other switches, with
just 4 input lines. 6 for output. Optionally some sort of indicator
output.

mpm

unread,
May 22, 2007, 5:20:07 PM5/22/07
to
On May 21, 2:58?pm, Eeyore <rabbitsfriendsandrelati...@hotmail.com>
wrote:

I'd go with an 8051 before an LPC.
If an LPC, you have to do a kubookie dance to get 'em programmed.

I know I probably spelled that wrong, but you get the idea.
The flash programming documentation on the LPC series is the WORST I
HAVE EVER SEEN!
Plus, you have to keep switching pins in and out of the circuit to
program it. What a hassle!

TF, take a look at the Atmel 89S8253.
Cheap, and will do the job. It has (4) 8-bit bidirectional ports (32
in/out total).
And, you can program it free with the Atmel download software.
You will need a $25 adapter for your PC, but you can't get much
cheaper.

The 8051's are very well supported, so you will find free compilers
(Basic, Assembly, "C", etc..)

The only thing that might be an issue for you is the 8253 port pins
can only drive about 10mA each, and that won't be enough for most
relays directly. -mpm

Eeyore

unread,
May 22, 2007, 6:16:47 PM5/22/07
to

mpm wrote:

> Eeyore wrote:
> > Don Lancaster wrote:
> > > tempus fugit wrote:
> >
> > > > Is it possible to do these things with a PIC?
> >
> > > It is UNTHINKABLE to NOT use a PIC for this ap.
> >
> > You could use a Philips LPC ! That would be my choice in fact as I'm familiar > with
> the family.
>
>

> I'd go with an 8051 before an LPC.
> If an LPC, you have to do a kubookie dance to get 'em programmed.
>
> I know I probably spelled that wrong, but you get the idea.
> The flash programming documentation on the LPC series is the WORST I
> HAVE EVER SEEN!
> Plus, you have to keep switching pins in and out of the circuit to
> program it. What a hassle!
>
> TF, take a look at the Atmel 89S8253.
> Cheap, and will do the job. It has (4) 8-bit bidirectional ports (32
> in/out total).
> And, you can program it free with the Atmel download software.
> You will need a $25 adapter for your PC, but you can't get much
> cheaper.

Yes, you're quite right I was thinking of the LPCs because of newer things I've been
working on but a flash version of an 8051 would be spot on. I used the 89s53 for this
kind of thing for example and it's got plenty of port pins on it too.

Graham

Spehro Pefhany

unread,
May 22, 2007, 8:18:45 PM5/22/07
to

"LPC" may not be the best way to refer to the NXP microcontrollers. It
could refer to an 8051 in an 8-pin package (P89LPC901), an ARM9 in a
320-pin package (LPC3180FEL320) or quite a range of other parts
inbetween.

joseph2k

unread,
May 23, 2007, 12:46:22 AM5/23/07
to
Eeyore wrote:

Not at all. Switch or keyboard scanning means sampling the state of each
switch at some given rate, 500 times a second in this case. Switch / key
debounce is a convenient byproduct of the method.
--
JosephKK
Gegen dummheit kampfen die Gotter Selbst, vergebens.  
--Schiller

joseph2k

unread,
May 23, 2007, 1:15:36 AM5/23/07
to
tempus fugit wrote:

It is much to your advantage to multiplex the inputs, say use 4 "rows" and 4
"columns" to sense your switches (up to 16 of them) on 8 pins of i/o. It
is also to your advantage to drive your outputs individually.
What i do not understand is the idea of using ramps to drive relays, they
work much better with on-off control drive. I also have issues with using
relays at all, electronic switching is faster and quieter.
As for what turns on when for any given switch configuration, just decide
what you want it to do and that becomes part of the micro's program. no
witchy complexities, just a map (list) from inputs to outputs.

Spehro Pefhany

unread,
May 23, 2007, 4:07:24 AM5/23/07
to
On Wed, 23 May 2007 06:00:14 GMT, the renowned Eeyore
<rabbitsfriend...@hotmail.com> wrote:

>
>
>joseph2k wrote:
>
>> Eeyore wrote:
>> > tempus fugit wrote:
>> >
>> >> > The ramping up is perhaps best done with some analog circuitry. Since
>> >> > the switches are manually actuated you could perhaps scan them at,
>> >> > say, 500Hz rather than deal with them individually (much like your PC
>> >> > keyboard)
>> >>
>> >> I'm not familiar with this. What do you mean by scan them at 500Hz?
>> >
>> > He's thinking of a way of trying to eliminate the effect of switch bounce
>> > I think.
>> >
>> > Provided your switches only do 'X' when pressed rather than released,
>> > there's a very simple way of avoiding the issue entirely in software
>> > though.
>>
>>

>> Not at all. Switch or keyboard scanning means sampling the state of each
>> switch at some given rate, 500 times a second in this case. Switch / key
>> debounce is a convenient byproduct of the method.
>

>You really don't want switch scanning waveforms in an audio device. I've seen
>the trouble it creates.
>
>Graham

Sounds like a very bad design.

Eeyore

unread,
May 23, 2007, 8:48:24 AM5/23/07
to

Spehro Pefhany wrote:

> Eeyore wrote:
> >joseph2k wrote:
> >> Eeyore wrote:
> >> > tempus fugit wrote:
> >> >
> >> >> > The ramping up is perhaps best done with some analog circuitry. Since
> >> >> > the switches are manually actuated you could perhaps scan them at,
> >> >> > say, 500Hz rather than deal with them individually (much like your PC
> >> >> > keyboard)
> >> >>
> >> >> I'm not familiar with this. What do you mean by scan them at 500Hz?
> >> >
> >> > He's thinking of a way of trying to eliminate the effect of switch bounce
> >> > I think.
> >> >
> >> > Provided your switches only do 'X' when pressed rather than released,
> >> > there's a very simple way of avoiding the issue entirely in software
> >> > though.
> >>
> >>
> >> Not at all. Switch or keyboard scanning means sampling the state of each
> >> switch at some given rate, 500 times a second in this case. Switch / key
> >> debounce is a convenient byproduct of the method.
> >
> >You really don't want switch scanning waveforms in an audio device. I've seen
> >the trouble it creates.
>
>

> Sounds like a very bad design.

It was a very nice design actually but like all things in the real world was
subject to cost constraints so couldn't be on say a 4 layer board.

Try eliminating electro-statically and electro-magnetically coupled interference
when the audio noise floor is >=110dB below the 5V typical switching voltage. Note
that to be sure of not hearing a discrete tone, the pickup into the audio will need
to be about >=130dB below 5V since single tones are not well masked by wideband
noise.

130dB. Don't forget that.

We used to agonise over the induced click you'd get from a single short trace
switching maybe just a local control voltage. It's astonishing what makes itself
known when you actually *listen* to audio, as opposed to relying on long term
averaged measurements.

Graham

tempus fugit

unread,
May 23, 2007, 8:52:11 AM5/23/07
to

> > Thanks again
> It is much to your advantage to multiplex the inputs, say use 4 "rows" and
4
> "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.

So is the multiplexing done by the micro itself, or is it done with a
separate IC?

> What i do not understand is the idea of using ramps to drive relays, they
> work much better with on-off control drive. I also have issues with using
> relays at all, electronic switching is faster and quieter.

It isn't the relays I want to ramp, it's the relay drivers. I may end up
going to electronic switching in the end (in fact that is what I want to
experiment with, but my existing design would require quite a bit of
modification to do that, which is why I'm thinking about building from
scratch using a micro).

tempus fugit

unread,
May 23, 2007, 8:53:57 AM5/23/07
to
> The only thing that might be an issue for you is the 8253 port pins
> can only drive about 10mA each, and that won't be enough for most
> relays directly. -mpm


No problem there - I'm using relay drivers to drive the relays already, and
may end up going with CMOS switches anyway.

Man, there are a lot of different micros....

Thanks for the tip on the Atmel - it looks promising.


tempus fugit

unread,
May 23, 2007, 8:59:42 AM5/23/07
to

> You have made an error in thinking here. The switch only informs the
> micro that the switch is closed. The micro knows which group of
> things to activate for a given switch. This makes the wiring very
> simple.
>

I understand that, but do I then need 1 input pin for each switch, and 1 for
each output? That would mean 15 ins, plus 6 outs. Since I only have 6
different parameters to control, I was wondering if there was a way to use
only 6 input pins and 6 outs, plus the 1 extra for the bank switch.

The problem lies in the fact that some of the switches will control more
than 1 parameter at a time. That was what I was trying to describe in the
previous post:

a switch that switches A, and 1 that switches B, and 1 that switches A and
B

Thanks

tempus fugit

unread,
May 23, 2007, 9:10:43 AM5/23/07
to
>
> Suppose you have 14 keys. You have a single 8 bit I/O port.

So by 8 bits you mean a total of 8 pins to connect to (I'm still a bit
unsure of all the terminology)?


>We will assume that only one key can be pressed at once, otherwise you'll
have
a bit more complexity.

This is the case, although it is possible that more than one key may get
pressed accidentally...

>
> So you make half of the pins inputs and the other half outputs.

By programming them this way in the software?


>
> You drive one of the four outputs (say) low and float the others
> (essentially make them inputs). Then read the four inputs at once.

Here's where I'm getting lost. How do the ouputs get driven low? I was
thinking that if no switch was activated, that they would be already low, by
design. What do you mean read the 4 inputs at once? I was hoping to control
the micro by momentarily grounding an input with the switch.


>That gives you the states of 4 keys. Repeat 3 more times with a different
output low and you have all 14 (or 16) key states.

So are the output pins sometimes outputs and sometimes inputs? Are the
switches (inputs) then connected to the same pins as the relay drivers
(outputs)?

>but if
you only want the keys to start something you may not even need it.


The switches are indeed just to get something started.

Thanks again.


MooseFET

unread,
May 23, 2007, 9:36:47 AM5/23/07
to
On May 22, 9:46 pm, joseph2k <quiettechb...@yahoo.com> wrote:
[....]
I'm going to jump in here with a somewhat off subject comment about
the scanning of keyboards.

> Not at all. Switch or keyboard scanning means sampling the state of each
> switch at some given rate, 500 times a second in this case. Switch / key
> debounce is a convenient byproduct of the method.

Normally, when you want to scan a keyboard with a micro, you wire the
row connections to one (8 bit) port and the column connections to
another.

You are then going to strobe the column signals one at a time. In the
8051 case, you have the idle state of the ports as high and you strobe
one low at a time. If a switch is closed, the row signal will go low
at the same time.

If the OP has a slowish (or busy) micro to work with, and doesn't need
to worry about the user pressing more than one key at a time, he can
do as follows:

Assuming 4 bits of each are used:

PrevKey = NOKEY;
repeat
RowPort = 0FH
ColPort = 0
KeyNo = NOKEY
if RowPort < 0FH then begin
if (RowPort AND 01H)=0 then KeyNo=0
if (RowPort AND 02H)=0 then KeyNo=1
if (RowPort AND 04H)=0 then KeyNo=2
if (RowPort AND 08H)=0 then KeyNo=3

ColPort = 0AH
if RowPort <0FH then KeyNo = KeyNo + 4
ColPort = 0CH
if RowPort <0FH then KeyNo = KeyNo + 8
end
if (KeyNO <> NOKEY) and (KeyNo = PrevKey) then
report KeyNo
PreKey = KeyNo
end


Because the ColPort lines only change when the key is pressed, there
is less noise created. You have to check the key twice because the
test can come up with the wrong answer on a key bounce.

MooseFET

unread,
May 23, 2007, 9:51:01 AM5/23/07
to
On May 23, 5:59 am, "tempus fugit"

<tocc...@quitspammingme.ciaccess.com> wrote:
> > You have made an error in thinking here. The switch only informs the
> > micro that the switch is closed. The micro knows which group of
> > things to activate for a given switch. This makes the wiring very
> > simple.
>
> I understand that, but do I then need 1 input pin for each switch, and 1 for
> each output? That would mean 15 ins, plus 6 outs. Since I only have 6
> different parameters to control, I was wondering if there was a way to use
> only 6 input pins and 6 outs, plus the 1 extra for the bank switch.

I'm goning to try a bit of ASCII art:


Column Port
0 1 2
! ! !
R ! ! !
o 0---+-------------+------------ !
w ! ! ! ! ! !
P 0 SW 0 0 SW 0 0 SW 0
o ! ! !
r 1---+-------------+------------ !
t ! ! ! ! ! !
0 SW 0 0 SW 0 0 SW 0

A rectangular array of switches connected as shown is how you can
connect them to the ports. You then need to drive the Column Port
bits up and down and see which Row Port bit follows which Column port
bit.

Extending this array, you can do 16 keys with 4+4 = 8 port lines.

Eeyore

unread,
May 23, 2007, 10:01:34 AM5/23/07
to

tempus fugit wrote:

> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> > 4 "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

It's done by writing software to drive the micro's port pins in the required
manner.

Since you're new to all this and key scanning will in any case create an audio
tone that's very likely to break through into your signal, I very strongly
suggest you don't bother and use 1 input or output per port pin.

After all an 80C51 variant such as the 89s53
http://atmel.com/dyn/products/product_card.asp?family_id=604&family_name=8051+Architecture&part_id=1919

is inexpensive, easy to use and has 32 general purpose I/O lines anyway.

Graham

Eeyore

unread,
May 23, 2007, 10:04:53 AM5/23/07
to

tempus fugit wrote:

>
> > What i do not understand is the idea of using ramps to drive relays, they
> > work much better with on-off control drive. I also have issues with using
> > relays at all, electronic switching is faster and quieter.
>
> It isn't the relays I want to ramp, it's the relay drivers.

But what benefit do you expect to get from this ?

Graham

MooseFET

unread,
May 23, 2007, 10:05:06 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"

<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find
a place where I explained the idea of the code that does it. You
still need at least 8 port bits to do the 16 switches.

If you are willing to use douple pole switches, you can do a bit
better:

1 means connected to the switch
0 means not connected

sw connections
no R0-C0 R1-C0 R2-C0 R0-C1 R1-C1 R2-C1
1 0 0 0 0 1 1
2 0 0 0 1 0 1
3 0 0 1 0 0 1
4 0 1 0 0 0 1
5 1 0 0 0 0 1
6 0 0 0 1 1 0
7 0 0 1 0 1 0
8 0 1 0 0 1 0
9 1 0 0 0 1 0
10 0 0 1 1 0 0
11 0 1 0 1 0 0
12 1 0 0 1 0 0
13 0 1 1 0 0 0
14 1 0 1 0 0 0
15 1 1 0 0 0 0

This give 15 switches on only 5 port bits.

MooseFET

unread,
May 23, 2007, 10:05:22 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

MooseFET

unread,
May 23, 2007, 10:05:27 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

MooseFET

unread,
May 23, 2007, 10:05:30 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

MooseFET

unread,
May 23, 2007, 10:05:41 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

MooseFET

unread,
May 23, 2007, 10:06:05 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

MooseFET

unread,
May 23, 2007, 10:06:14 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

Spehro Pefhany

unread,
May 23, 2007, 11:07:59 AM5/23/07
to

Electrostatic shielding can be pretty decent on a cheap 2-layer board
if you use copper pour and housing metal effectively.

>Try eliminating electro-statically and electro-magnetically coupled interference

No much magnetic coupling, it's a keyboard scan not an LED scan. The
latter would be harder to deal with.

>when the audio noise floor is >=110dB below the 5V typical switching voltage. Note
>that to be sure of not hearing a discrete tone, the pickup into the audio will need
>to be about >=130dB below 5V since single tones are not well masked by wideband
>noise.
>
>130dB. Don't forget that.

It's for a *guitar*. What's the signal to noise ratio on the pickup?

>We used to agonise over the induced click you'd get from a single short trace
>switching maybe just a local control voltage. It's astonishing what makes itself
>known when you actually *listen* to audio, as opposed to relying on long term
>averaged measurements.
>
>Graham

MooseFET

unread,
May 23, 2007, 10:08:55 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

MooseFET

unread,
May 23, 2007, 10:08:58 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

MooseFET

unread,
May 23, 2007, 10:09:09 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

MooseFET

unread,
May 23, 2007, 10:09:28 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

Eeyore

unread,
May 23, 2007, 10:09:40 AM5/23/07
to

Eeyore wrote:

Use the 89S8253 (an update it seems)
http://uk.farnell.com/jsp/Semiconductors/Microprocessors+/+Microcontrollers+&+peripherals/ATMEL/AT89S8253-24PU/displayProduct.jsp?sku=1095746

A mere £2.97 in 1 off from Farnell and available in a DIL package so it's easy to protoytype with for the
hobbyist.

This programmer should be fine with it too but I'd want to be 100% sure of device support before buying.
http://cgi.ebay.co.uk/NSP-Universal-Programmer-Eprom-MCU-PIC-PLD-Flash_W0QQitemZ220114134875QQihZ012QQcategoryZ294QQrdZ1QQcmdZViewItem

http://cgi.ebay.co.uk/TOP2004-USB-Universal-Programmer_W0QQitemZ220114134699QQihZ012QQcategoryZ294QQrdZ1QQcmdZViewItem

Graham

MooseFET

unread,
May 23, 2007, 10:11:21 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

MooseFET

unread,
May 23, 2007, 10:11:39 AM5/23/07
to
On May 23, 5:52 am, "tempus fugit"
<tocc...@quitspammingme.ciaccess.com> wrote:
> > > Thanks again
> > It is much to your advantage to multiplex the inputs, say use 4 "rows" and
> 4
> > "columns" to sense your switches (up to 16 of them) on 8 pins of i/o.
>
> So is the multiplexing done by the micro itself, or is it done with a
> separate IC?

The micro can do the muxing. Hunt around in this thread and you find


>

Eeyore

unread,
May 23, 2007, 10:17:48 AM5/23/07