|
Home > Archive > Electrical Engineering > May 2006 > device for converting binary strings into states for switches
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
device for converting binary strings into states for switches
|
|
|
| Hi,
I need to buid a device connected to a computer. The computer will
generate binary strings (each position will be either 0 or 1) of length
N. Based on this string my device has to set the state (on/off) of N
switches.
Example:
The computer generates the string 00110.
I also have 5 switches which must be set by my device as follows: first
2 switches and the last switch must be turned OFF and the 3rd and the
4th must be turned ON.
I have a hard constrain for this problem: the operation described above
must be performed in O(1) steps. This means that it should be
INDEPENDENT of the value of N. All switches must be set in the same
moment.
I DONT want to check the value of each position and to set the state of
the corresponding switch accordingly. This will means O(N) steps and I
want only O(1) steps.
How can I make such device? I should use some properties of the
computer ports, but I dont know how.
Even some small values for N (16 or 32) are of interest for me.
Thanks.
Laura
| |
| Palindr☻me 2006-05-16, 10:21 am |
| laura wrote:
> Hi,
>
> I need to buid a device connected to a computer. The computer will
> generate binary strings (each position will be either 0 or 1) of length
> N. Based on this string my device has to set the state (on/off) of N
> switches.
>
> Example:
>
> The computer generates the string 00110.
> I also have 5 switches which must be set by my device as follows: first
> 2 switches and the last switch must be turned OFF and the 3rd and the
> 4th must be turned ON.
>
> I have a hard constrain for this problem: the operation described above
> must be performed in O(1) steps. This means that it should be
> INDEPENDENT of the value of N. All switches must be set in the same
> moment.
>
> I DONT want to check the value of each position and to set the state of
> the corresponding switch accordingly. This will means O(N) steps and I
> want only O(1) steps.
>
> How can I make such device? I should use some properties of the
> computer ports, but I dont know how.
>
> Even some small values for N (16 or 32) are of interest for me.
>
Not difficult, unless I have misunderstood you.
The serial data from the computer is clocked into an N-bit shift
register. The parallel outputs from the shift register are connected to
an N-bit latch. Once the shift register is filled, the latch transfers
all the N bits from the shift register to the latch output,
simultaneously. There are ICs which combine the shift register and
latch, for fixed values of N. These chips can normally be cascaded for
larger values of N. I have one electronics board, out of a pinball
machine,, which has 4 cascaded serial in, parallel out, chips each with
N=48.
A standard PC has a parallel port with N=8. For bigger values of N, it
is very simple to use 3 of these output lines from the parallel port of
the PC, one for serial data, one for the clock and one for operating the
latch. The computer is programmed to output a series of bytes to the
port, the first and second byte will contain the first data bit on one
line and with alternate values on the clock line, whilst holding the
latch line constant. This is repeated for all the N bits, with the final
output byte clocking the latch line.
--
Sue
| |
| laura 2006-05-16, 11:21 am |
|
Dear Sue,
Thanks for your answer. Your idea is very good.
I have some small questions (because I'm a computer scientist and I'm
not very good at electronics):
I didn't understand why the data from my computer is sent in a serial
way to the shift register. I don't want to send bit by bit. I want all
the operations to be performed in a parallel way.
I can generate those binary strings into some registers (in a 32 bit
register I can have 32 bits corresponding to 32 switches). In this case
should I send them one by one to the shift register? Can I do this
operation in parallel.
Could you also explain me again (or give me some links) on how could I
extend the method for more switches? I didn't understand that part very
well.
Thanks.
Laura
Palindr=E2=98=BBme wrote:
> laura wrote:
>
> Not difficult, unless I have misunderstood you.
>
> The serial data from the computer is clocked into an N-bit shift
> register. The parallel outputs from the shift register are connected to
> an N-bit latch. Once the shift register is filled, the latch transfers
> all the N bits from the shift register to the latch output,
> simultaneously. There are ICs which combine the shift register and
> latch, for fixed values of N. These chips can normally be cascaded for
> larger values of N. I have one electronics board, out of a pinball
> machine,, which has 4 cascaded serial in, parallel out, chips each with
> N=3D48.
>
> A standard PC has a parallel port with N=3D8. For bigger values of N, it
> is very simple to use 3 of these output lines from the parallel port of
> the PC, one for serial data, one for the clock and one for operating the
> latch. The computer is programmed to output a series of bytes to the
> port, the first and second byte will contain the first data bit on one
> line and with alternate values on the clock line, whilst holding the
> latch line constant. This is repeated for all the N bits, with the final
> output byte clocking the latch line.
>=20
> --=20
> Sue
| |
| Palindr☻me 2006-05-16, 12:21 pm |
| laura wrote:
> Dear Sue,
>
> Thanks for your answer. Your idea is very good.
>
> I have some small questions (because I'm a computer scientist and I'm
> not very good at electronics):
>
> I didn't understand why the data from my computer is sent in a serial
> way to the shift register. I don't want to send bit by bit. I want all
> the operations to be performed in a parallel way.
>
> I can generate those binary strings into some registers (in a 32 bit
> register I can have 32 bits corresponding to 32 switches). In this case
> should I send them one by one to the shift register? Can I do this
> operation in parallel.
>
> Could you also explain me again (or give me some links) on how could I
> extend the method for more switches? I didn't understand that part very
> well.
The standard data ports on a computer are 8 bits wide. To send more
than 8 bits, you have to either sequentially program a number of ports,
or sequentially send data to the same port.
The former can be achieved by adding more parallel ports to the computer
- either cards with printer ports or (expensive) I/O cards with 8,
16,32, 64 or even 128 bits of parallel output.
However, it is possible to use a single 8 bit port (eg a printer port)
to send as much data as you want. By using it with a shift register and
latch.
If you do a Google search on serial in, parallel out shift registers,
you can read up on how they work. You can make a shift register as long
as you want, simply by adding extra stages.
>
> Thanks.
> Laura
>
> Palindr☻me wrote:
>
>
>
| |
| Palindr☻me 2006-05-16, 1:21 pm |
| laura wrote:
> Dear Sue,
>
> Thanks for your answer. Your idea is very good.
>
> I have some small questions (because I'm a computer scientist and I'm
> not very good at electronics):
>
> I didn't understand why the data from my computer is sent in a serial
> way to the shift register. I don't want to send bit by bit. I want all
> the operations to be performed in a parallel way.
>
> I can generate those binary strings into some registers (in a 32 bit
> register I can have 32 bits corresponding to 32 switches). In this case
> should I send them one by one to the shift register? Can I do this
> operation in parallel.
>
> Could you also explain me again (or give me some links) on how could I
> extend the method for more switches? I didn't understand that part very
> well.
If you aren't at all into electonics, a card like this may be a better
bet for you:
ebay item 7619325709
The card above is only 24 bits wide. You can get them in anything from 8
bits to 128 bits wide. However, you can use several cards together -
although they won't work quite simultaneously - there can be a delay of
a few mSec between the outputs of one card changing and the outputs of
another.
--
Sue
| |
|
|
Palindr=E2=98=BBme wrote:
> laura wrote:
>
> If you aren't at all into electonics, a card like this may be a better
> bet for you:
>
> ebay item 7619325709
>
>
> The card above is only 24 bits wide. You can get them in anything from 8
> bits to 128 bits wide. However, you can use several cards together -
> although they won't work quite simultaneously - there can be a delay of
> a few mSec between the outputs of one card changing and the outputs of
> another.
>
>
> --
> Sue
Hi all,
I have received several posts and I've got confused. I mean I'm not
very sure if I can do this operation purely in parallel.
I mean: I have that binary string generated into a variable of type int
(max 32 bits from C language). Or, imagine that I have it into the
processor registry AX. Or, in a smaller registry/variable (that has
only 8 bits).
Can I map this string into states of the switches doing only operations
in parallel? I need NO serial operations (I mean I DON'T want to have
an operation which traverse that string bit by bit - for shift
purposes, etc). The serial operations means O(N) complexity, and I want
to avoid that. I want to make only O(1) operations. This means that
everything should be performed in parallel - from that binary string
which is stored in the bits of AX registry .... to the states of the
switches that I want to turn ON/OFF.
Is this possible?
Thanks,
Laura
| |
|
|
Palindr=E2=98=BBme wrote:
> laura wrote:
>
> If you aren't at all into electonics, a card like this may be a better
> bet for you:
>
> ebay item 7619325709
>
>
> The card above is only 24 bits wide. You can get them in anything from 8
> bits to 128 bits wide. However, you can use several cards together -
> although they won't work quite simultaneously - there can be a delay of
> a few mSec between the outputs of one card changing and the outputs of
> another.
>
>
> --
> Sue
Hi all,
I have received several posts and I've got confused. I mean I'm not
very sure if I can do this operation purely in parallel.
I mean: I have that binary string generated into a variable of type int
(max 32 bits from C language). Or, imagine that I have it into the
processor registry AX. Or, in a smaller registry/variable (that has
only 8 bits).
Can I map this string into states of the switches doing only operations
in parallel? I need NO serial operations (I mean I DON'T want to have
an operation which traverse that string bit by bit - for shift
purposes, etc). The serial operations means O(N) complexity, and I want
to avoid that. I want to make only O(1) operations. This means that
everything should be performed in parallel - from that binary string
which is stored in the bits of AX registry .... to the states of the
switches that I want to turn ON/OFF.
Is this possible?
Thanks,
Laura
| |
| Keith Williams 2006-05-16, 3:21 pm |
| In article <1147800472.058784.312390@i40g2000cwc.googlegroups.com>,
laura.brandusan@gmail.com says...
>
> Palindr?me wrote:
>
> Hi all,
>
> I have received several posts and I've got confused. I mean I'm not
> very sure if I can do this operation purely in parallel.
>
> I mean: I have that binary string generated into a variable of type int
> (max 32 bits from C language). Or, imagine that I have it into the
> processor registry AX. Or, in a smaller registry/variable (that has
> only 8 bits).
>
> Can I map this string into states of the switches doing only operations
> in parallel? I need NO serial operations (I mean I DON'T want to have
> an operation which traverse that string bit by bit - for shift
> purposes, etc). The serial operations means O(N) complexity, and I want
> to avoid that. I want to make only O(1) operations. This means that
> everything should be performed in parallel - from that binary string
> which is stored in the bits of AX registry .... to the states of the
> switches that I want to turn ON/OFF.
>
> Is this possible?
Sure, you need a 32bit parallel port of some sort though.
--
Keith
| |
| Palindr☻me 2006-05-16, 3:21 pm |
| laura wrote:
> Palindr☻me wrote:
>
>
>
> Hi all,
>
> I have received several posts and I've got confused. I mean I'm not
> very sure if I can do this operation purely in parallel.
>
> I mean: I have that binary string generated into a variable of type int
> (max 32 bits from C language). Or, imagine that I have it into the
> processor registry AX. Or, in a smaller registry/variable (that has
> only 8 bits).
>
> Can I map this string into states of the switches doing only operations
> in parallel? I need NO serial operations (I mean I DON'T want to have
> an operation which traverse that string bit by bit - for shift
> purposes, etc). The serial operations means O(N) complexity, and I want
> to avoid that. I want to make only O(1) operations. This means that
> everything should be performed in parallel - from that binary string
> which is stored in the bits of AX registry .... to the states of the
> switches that I want to turn ON/OFF.
>
If you want the computer to turn the switches on/off then the switches
have to have a control input - these sorts of switches are called
relays. A control signal determines whether the relay is on or off. If
you have 8 relays, you need 8 control signals, one per relay.
Your starting point is a register which can have the value set by a
computer program. Once it is there, you have to get it to appear as
control signals coming out of the computer.
A card, such as the ebay one, has a number of library routines for
taking a register content and making it appear as control signals. eg
Write_port_A(val). You set the variable val to the register value and
then call the library routine. These typically are 8 bit. So, to output
a 16 bit variable, your code may be:
...
....
...
Write_Port_A(High_byte(val));
Write_Port_B(Low_byte(val));
...
...
...
This assumes that val is a 16 bit unsigned variable.
Note that, as the second library call happens after the first one, there
will be a delay of a few mSec between the two sets of 8 relays (computer
controlled switches) changing. In practice, this tiny delay is less than
the variation in operating times of the relays themselves.
If the tiny delay matters, or if you want large values of N, then you
have to allow for the computer outputing data byte by byte (or bit by
bit) and waiting until all the outputs have been set before passing
their values to the relays.
That is when shift registers and latches come into their own. The
example I gave was a pinball machine with N = 132. There is no way a
computer can change 132 bits all in one go - it doesn't have a register
big enough to do it. So it has to do it in chunks and a shift register
plus latch is a very, very effective way of handling this.
--
Sue
|
|
|
|
|