Sort of Gray code to binary converter
Electronics Forum Index Electronics
Circuits, theory, electrons and discussions.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web ElectronicsHelp.net
Sort of Gray code to binary converter
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Electronics Forum Index -> Design
Author Message
Fred Bloggs
Guest





Posted: Mon Dec 12, 2005 1:35 am    Post subject: Re: Sort of Gray code to binary converter Reply with quote

Quote:
I say 'sort of' because the input I have is not true reflected binary
Gray code. The input is a wind direction sensor with eight discrete
positions. They are activated by a small magnet which triggers either
one or two sensors at any time. Thus the eight sensors produce the
following sequence:

00000001
00000011
00000010
00000110
00000100
00001100
00001000
00011000
00010000
00110000
00100000
01100000
01000000
11000000
10000000
10000001

What logic do I need to convert these 16 values to a 4-bit binary
number.

Thanks for your attention.

The direct approaches are uninteresting- like the dumb C stuff that
presumably uses 16 I/O which seems burdensome on the embedded flea power
hardware. The answer in terms of an efficient solution is not only pat
but also obvious if you can recognize the analogy with another
well-known method...

Back to top
Spehro Pefhany
Guest





Posted: Mon Dec 12, 2005 1:35 am    Post subject: Re: Sort of Gray code to binary converter Reply with quote

On Sun, 11 Dec 2005 23:10:10 +0100, the renowned "Frank Bemelman"
<f.bemelmanq@xs4all.invalid.nl> wrote:

Quote:
"Spehro Pefhany" <speffSNIP@interlogDOTyou.knowwhat> schreef in bericht
news:i54pp113kh23c3b7m55qp153ei79evkiu6@4ax.com...

How fast is that wind direction going to change? ;-) The table can
consume 448 bytes in a typical midrange PIC, which may not be
insignificant, and table lookup is pretty ugly as well (none of your
dedicated CPU32 table instructions.. and paging has to be handled).

Ugliness is in the eye of the beholder. The CPU couldn't care less ;)

Any ugly CPU like a PIC probably looks forward having its PCLATH
diddled once in a while.


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





Posted: Mon Dec 12, 2005 8:02 am    Post subject: Re: Sort of Gray code to binary converter Reply with quote

Ken Smith wrote:
Quote:
In article <1134321036.940842.244290@f14g2000cwb.googlegroups.com>,
slebetman@yahoo.com <slebetman@gmail.com> wrote:
[...]
In C it is simple. Don't do clever tricks, you'll only forget why they
worked later on. Do it the obvious way:

char code2number(unsigned char code)
{
switch (code) {

or

Y = Table[X];


I considered that one. That requires an array of 256 elements 93.75% or
which simply store errors/illegal values. The switch statement on the
other hand requires less typing (16 cases instead of 256 values).

Back to top
Robert Scott
Guest





Posted: Mon Dec 12, 2005 8:53 am    Post subject: Re: Sort of Gray code to binary converter Reply with quote

On Sun, 11 Dec 2005 22:57:33 +0000 (UTC), kensmith@green.rahul.net
(Ken Smith) wrote:

Quote:
In article <439c9707.5949614@news.provide.net>,
Robert Scott <no-one@dont-mail-me.com> wrote:
Using 74LS00 series logic I can do it with the following chips:

74LS00 x 4
74LS20 x 2
74LS30 x 1
74LS04 x 1

I've got you very beat on chip count but mine are higher level chips.
See my post elsewhere in this thread.

How about comparing solutions on the basis of equivalent number of
gates? Obviously an ASIC could be built to do this job, but the
puzzle, as an intellectual exercise, is more interesting if you place
complexity limitations on the solution.

(For a practical solution I would just program a PIC.)

-Robert Scott
Ypsilanti, Michigan
Back to top
John Larkin
Guest





Posted: Mon Dec 12, 2005 9:30 am    Post subject: Re: Sort of Gray code to binary converter Reply with quote

On Mon, 12 Dec 2005 02:53:14 GMT, no-one@dont-mail-me.com (Robert
Scott) wrote:

Quote:
On Sun, 11 Dec 2005 22:57:33 +0000 (UTC), kensmith@green.rahul.net
(Ken Smith) wrote:

In article <439c9707.5949614@news.provide.net>,
Robert Scott <no-one@dont-mail-me.com> wrote:
Using 74LS00 series logic I can do it with the following chips:

74LS00 x 4
74LS20 x 2
74LS30 x 1
74LS04 x 1

I've got you very beat on chip count but mine are higher level chips.
See my post elsewhere in this thread.

How about comparing solutions on the basis of equivalent number of
gates? Obviously an ASIC could be built to do this job, but the
puzzle, as an intellectual exercise, is more interesting if you place
complexity limitations on the solution.

(For a practical solution I would just program a PIC.)


Or even easier, a 22CV10.

John
Back to top
Mac
Guest





Posted: Mon Dec 12, 2005 9:35 am    Post subject: Re: Sort of Gray code to binary converter Reply with quote

On Sun, 11 Dec 2005 12:33:50 -0800, John Larkin wrote:

Quote:
On Sun, 11 Dec 2005 20:22:42 GMT, Fred Bloggs <nospam@nospam.com
wrote:



Frank Bemelman wrote:

This is all very understandable,
as there exists no assembly equivalent for a switch statement, so ...

Whatever happened to doing an indirect jump through a table ( of
addresses) indexed into by the argument?

Exactly. A 256-entry lookup table, indexed by the eight input bits,
delivers a 4-bit code for every input combination. Fast. That sure
beats a bushel of logic.

I did a *very* fast 16-bit sine function a while back. It was 128
kbytes long.


Ah, a straight LUT. That is how the AD DDS's do it, too.

Quote:
There's nothing you can't do in assembly. If a compiler can generate
machine code, I can too.

John

Assembly isn't very portable, though. Sometimes that matters, and
sometimes it doesn't.

Sounds like for you it usually doesn't. ;-)

--Mac
Back to top
Ken Smith
Guest





Posted: Mon Dec 12, 2005 2:44 pm    Post subject: Re: Sort of Gray code to binary converter Reply with quote

In article <1134352497.340491.182910@g44g2000cwa.googlegroups.com>,
slebetman@yahoo.com <slebetman@gmail.com> wrote:
[... me ...]
Quote:

Y = Table[X];


I considered that one. That requires an array of 256 elements 93.75% or
which simply store errors/illegal values. The switch statement on the
other hand requires less typing (16 cases instead of 256 values).

In ASM you can do like this:

Table:
rept 256 ; Repeat 256 times
db 0FFH ; Fill with error
endm ; End repeat

org Table+00000011 ; Address the cell
db 1 ; Put the value in
org Table+00000110
db 2
..... etc .......
org Table + 256 ; put the pointer to after the table
.... more code ...

As is often the case, it is easier to do in ASM.



--
--
kensmith@rahul.net forging knowledge
Back to top
Ken Smith
Guest





Posted: Mon Dec 12, 2005 2:48 pm    Post subject: Re: Sort of Gray code to binary converter Reply with quote

In article <439ce57a.5974844@news.provide.net>,
Robert Scott <no-one@dont-mail-me.com> wrote:
Quote:
On Sun, 11 Dec 2005 22:57:33 +0000 (UTC), kensmith@green.rahul.net
(Ken Smith) wrote:
[...]
I've got you very beat on chip count but mine are higher level chips.
See my post elsewhere in this thread.

How about comparing solutions on the basis of equivalent number of
gates? Obviously an ASIC could be built to do this job, but the
puzzle, as an intellectual exercise, is more interesting if you place
complexity limitations on the solution.

(For a practical solution I would just program a PIC.)

A PIC has a really huge number of gates inside. Personally, I'd more
likely put it into a CMOS 22V10. Both you and my practical solutions
contain more logic than the ones we are comparing.

A real contest would be to do it in terms of transistors.

--
--
kensmith@rahul.net forging knowledge
Back to top
Ken Smith
Guest





Posted: Mon Dec 12, 2005 2:50 pm    Post subject: Re: Sort of Gray code to binary converter Reply with quote

In article <tlrpp1523so91armmluesrk2muvk499b64@4ax.com>,
John Larkin <jjlarkin@highNOTlandTHIStechnologyPART.com> wrote:
[...]
Quote:
Or even easier, a 22CV10.

Yes.
Get one of the "zero power" ones and you can run it for a couple of years
on a 9V battery.

--
--
kensmith@rahul.net forging knowledge
Back to top
Ken Smith
Guest





Posted: Mon Dec 12, 2005 3:13 pm    Post subject: Re: Sort of Gray code to binary converter Reply with quote

In article <439d6608$0$32464$4c56ba96@master.news.zetnet.net>,
John B <spamj_baraclough@blockerzetnet.co.uk> wrote:
Quote:
Well so far we've got quite a plethora of answers. Ken seems to be
ahead of the field in the hardware stakes, although he's keeping the
design under wraps just now ;-).

Actually, no it isn't under wraps. The only thing I didn't say was the
obvious. Take a look at my first post on the subject where I said that it
takes a priority decoder+parity generator+quad nand. I gave what each
does.

Quote:
I like the 16V8 or 22V10 PLD approach
and that could yet creep to the front of the field.

This would be my vote.

Quote:
well. So we're probably looking at 'C' on an AVR as the front runner.

Anything involving "C" makes me ill.

Quote:
Look-up tables are too wasteful

If the chip you use has the code space needed, you may as well go that
way. You can't save the unused part of the prom for use in some future
chip.


Quote:
and if(); else if() or switch{}
contructs are too ugly so let's have some lateral thinking.

If your CPU does floating point with the IEEE format:

Assume that EXP returns the exponent part of the number.
Assume that MAN returns the mantissa part of the number without the
implied bit.

if ( X == 0x81) Y = SOMEVALUE
else {
TempFloat = X
Y = (2 * EXP(TempFloat)) + ( 1 & (0 < MAN(TempFloat)));
}



--
--
kensmith@rahul.net forging knowledge
Back to top
John B
Guest





Posted: Mon Dec 12, 2005 5:35 pm    Post subject: Re: Sort of Gray code to binary converter Reply with quote

Well so far we've got quite a plethora of answers. Ken seems to be
ahead of the field in the hardware stakes, although he's keeping the
design under wraps just now ;-). I like the 16V8 or 22V10 PLD approach
and that could yet creep to the front of the field.

The software field is more open. Several people had suggested a PIC,
that's definitely not in the field as the hardware is tooo.. ugly! Now
an AVR, yes that's a goer, but not in assembler as that is ugly as
well. So we're probably looking at 'C' on an AVR as the front runner.
Look-up tables are too wasteful and if(); else if() or switch{}
contructs are too ugly so let's have some lateral thinking.

It's interesting to see that Win is keeping his powder dry. As one of
the perpetrators of my long time reference book of 20 odd years
standing I would like to know what he's thinking.

Anyway there's still nine days left until the Northern Hemisphere
Winter Solstice (that's for the pedants) and, as long as we can keep
the momentum up, the competition closes three days after that.

It looks as though there will have to be two toasts drunk as a
celebration. I'll need to get out my zimmer frame to be able to stand
up after that.

Happy thinking.

--
John B
Back to top
Luhan Monat
Guest





Posted: Mon Dec 12, 2005 5:35 pm    Post subject: Re: Sort of Gray code to binary converter Reply with quote

Jim Thompson wrote:
Quote:
On Mon, 12 Dec 2005 14:48:42 +0000 (UTC), kensmith@green.rahul.net
(Ken Smith) wrote:


In article <439ce57a.5974844@news.provide.net>,
Robert Scott <no-one@dont-mail-me.com> wrote:

On Sun, 11 Dec 2005 22:57:33 +0000 (UTC), kensmith@green.rahul.net
(Ken Smith) wrote:

[...]

I've got you very beat on chip count but mine are higher level chips.
See my post elsewhere in this thread.

How about comparing solutions on the basis of equivalent number of
gates? Obviously an ASIC could be built to do this job, but the
puzzle, as an intellectual exercise, is more interesting if you place
complexity limitations on the solution.

(For a practical solution I would just program a PIC.)

A PIC has a really huge number of gates inside. Personally, I'd more
likely put it into a CMOS 22V10. Both you and my practical solutions
contain more logic than the ones we are comparing.

A real contest would be to do it in terms of transistors.

--


Can I do it all in 2N2222 ?:-)

...Jim Thompson

How about some mind-numbing array of diodes?


--
Luhan Monat
luhanxmonat 'at' yahoo 'dot' com
http://members.cox.net/berniekm
Back to top
Rick
Guest





Posted: Mon Dec 12, 2005 5:35 pm    Post subject: Re: Sort of Gray code to binary converter Reply with quote

"Jim Thompson" <To-Email-Use-The-Envelope-Icon@My-Web-Site.com> wrote
in message news:febrp1ti4dgag61l5bq9br4n7msu6ljn5a@4ax.com...
Quote:
On Mon, 12 Dec 2005 10:04:47 -0700, Luhan Monat <fake@not.valid
wrote:

Jim Thompson wrote:
On Mon, 12 Dec 2005 14:48:42 +0000 (UTC),
kensmith@green.rahul.net
(Ken Smith) wrote:


In article <439ce57a.5974844@news.provide.net>,
Robert Scott <no-one@dont-mail-me.com> wrote:

On Sun, 11 Dec 2005 22:57:33 +0000 (UTC),
kensmith@green.rahul.net
(Ken Smith) wrote:

[...]

I've got you very beat on chip count but mine are higher level
chips.
See my post elsewhere in this thread.

How about comparing solutions on the basis of equivalent number
of
gates? Obviously an ASIC could be built to do this job, but the
puzzle, as an intellectual exercise, is more interesting if you
place
complexity limitations on the solution.

(For a practical solution I would just program a PIC.)

A PIC has a really huge number of gates inside. Personally, I'd
more
likely put it into a CMOS 22V10. Both you and my practical
solutions
contain more logic than the ones we are comparing.

A real contest would be to do it in terms of transistors.

--


Can I do it all in 2N2222 ?:-)

...Jim Thompson

How about some mind-numbing array of diodes?

Relays ?:-)

...Jim Thompson


Spare parts from a Friedan mechanical calculator....
Back to top
Jim Thompson
Guest





Posted: Mon Dec 12, 2005 5:35 pm    Post subject: Re: Sort of Gray code to binary converter Reply with quote

On Mon, 12 Dec 2005 10:04:47 -0700, Luhan Monat <fake@not.valid>
wrote:

Quote:
Jim Thompson wrote:
On Mon, 12 Dec 2005 14:48:42 +0000 (UTC), kensmith@green.rahul.net
(Ken Smith) wrote:


In article <439ce57a.5974844@news.provide.net>,
Robert Scott <no-one@dont-mail-me.com> wrote:

On Sun, 11 Dec 2005 22:57:33 +0000 (UTC), kensmith@green.rahul.net
(Ken Smith) wrote:

[...]

I've got you very beat on chip count but mine are higher level chips.
See my post elsewhere in this thread.

How about comparing solutions on the basis of equivalent number of
gates? Obviously an ASIC could be built to do this job, but the
puzzle, as an intellectual exercise, is more interesting if you place
complexity limitations on the solution.

(For a practical solution I would just program a PIC.)

A PIC has a really huge number of gates inside. Personally, I'd more
likely put it into a CMOS 22V10. Both you and my practical solutions
contain more logic than the ones we are comparing.

A real contest would be to do it in terms of transistors.

--


Can I do it all in 2N2222 ?:-)

...Jim Thompson

How about some mind-numbing array of diodes?

Relays ?:-)

...Jim Thompson
--
| James E.Thompson, P.E. | mens |
| Analog Innovations, Inc. | et |
| Analog/Mixed-Signal ASIC's and Discrete Systems | manus |
| Phoenix, Arizona Voice:(480)460-2350 | |
| E-mail Address at Website Fax:(480)460-2142 | Brass Rat |
| http://www.analog-innovations.com | 1962 |

I love to cook with wine. Sometimes I even put it in the food.
Back to top
Spehro Pefhany
Guest





Posted: Mon Dec 12, 2005 5:35 pm    Post subject: Re: Sort of Gray code to binary converter Reply with quote

On Mon, 12 Dec 2005 14:48:42 +0000 (UTC), the renowned
kensmith@green.rahul.net (Ken Smith) wrote:

Quote:
In article <439ce57a.5974844@news.provide.net>,
Robert Scott <no-one@dont-mail-me.com> wrote:
On Sun, 11 Dec 2005 22:57:33 +0000 (UTC), kensmith@green.rahul.net
(Ken Smith) wrote:
[...]
I've got you very beat on chip count but mine are higher level chips.
See my post elsewhere in this thread.

How about comparing solutions on the basis of equivalent number of
gates? Obviously an ASIC could be built to do this job, but the
puzzle, as an intellectual exercise, is more interesting if you place
complexity limitations on the solution.

(For a practical solution I would just program a PIC.)

A PIC has a really huge number of gates inside. Personally, I'd more
likely put it into a CMOS 22V10. Both you and my practical solutions
contain more logic than the ones we are comparing.

What do you guys use to write programs for the SPLDs? CUPL?

Quote:
A real contest would be to do it in terms of transistors.

One way is to just decode the valid states (8 inverters and 8 2-input
AND gates) and use a handful of diodes to generate the binary. That's
perhaps 8 NPN transistors, a couple of dozen resistors, and 48 diodes
(HCMOS input and output).


Best regards,
Spehro Pefhany
--
"it's the network..." "The Journey is the reward"
speff@interlog.com Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog Info for designers: http://www.speff.com
Back to top
 
Post new topic   Reply to topic    Electronics Forum Index -> Design All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Home & Living New Topics
Contact Us
Powered by phpBB