Maker Pro
Maker Pro

Sort of Gray code to binary converter

J

Jim Thompson

On 13 Dec 2005 21:15:27 GMT, "John B"

[snip]
Jim appeared to be working on a solution but faded at the last furlong,

[snip]

I quit because I thought you were leaning toward one of those gross uP
solutions ;-)

...Jim Thompson

uP's are not gross! Overkill here, but definitely cool in lots of
apps. Can *you* do an analog 16x16 multiply accurate to one LSB? Hell,
you don't even *have* LSBs!

John

Yep, we do... the noise floor ;-)

Talk about mixed metaphors... ".. _analog_ 16x16 multiply.."

I can do multiplies at 5GHz, can you ?:)

...Jim Thompson
 
K

Ken Smith

Rich Grise said:
unsigned int table[256]; /* Usually compilers initialize arrays to 0 */

I can't think of any compiler that initializes. I doubt that any micro
controller ones do.
table[1] = 1;
table[3] = 2;
table[2] = 3;

This construct takes a *lot* more code space.
 
K

Ken Smith

At least with a PIC there are only 35 instructions to remember and only
one register to worry about.

It's really just a PDP-8.[/QUOTE]

No, a PDP-8 had a 12 bit ALU.

It also didn't have a stack. The call and return worked by storing the
return address in the first location of the subroutine.

It also didn't subtract.
 
J

John Larkin

On 13 Dec 2005 21:15:27 GMT, "John B"

[snip]

Jim appeared to be working on a solution but faded at the last furlong,

[snip]

I quit because I thought you were leaning toward one of those gross uP
solutions ;-)

...Jim Thompson

uP's are not gross! Overkill here, but definitely cool in lots of
apps. Can *you* do an analog 16x16 multiply accurate to one LSB? Hell,
you don't even *have* LSBs!

John

Yep, we do... the noise floor ;-)

Noise? What noise? uP programs work the same way, every time, exactly.
Usually.
Talk about mixed metaphors... ".. _analog_ 16x16 multiply.."

Well you know, accurate to 15 PPM.
I can do multiplies at 5GHz, can you ?:)

No, but a decent Vertex chip can do 100 multiplies (using 100
multipliers!) in a single clock, at 100 MHz. That's 10 GHz, sort of.

This is like arguing whether to have food or wine.

John
 
S

Spehro Pefhany

On Wed, 14 Dec 2005 01:31:12 +0000 (UTC), the renowned
Rich Grise said:
unsigned int table[256]; /* Usually compilers initialize arrays to 0 */

I can't think of any compiler that initializes. I doubt that any micro
controller ones do.

If we're talking C, all objects with static storage duration *must* be
initialized. I've never seen a compiler that fails to do that.

So, if unsigned int table[256] is a global (eg. declared before
'main()'), or if you add the 'static' storage-class specifier it gets
initialized by the startup code. *Always* to 0 for each element*.

That said, this would be a horrible way to do it-- for one thing the
table would typically reside in RAM if you don't tell it otherwise
(there might not be that much RAM!), and would only be initialized
once, which leaves you open to RAM data corruption between resets
(which could be a long time).

* IME with a microcontroller compiler, typically the compiler crams
all the globals and statics together and the startup code just clears
the whole block from beginning to end in one tight loop.


Best regards,
Spehro Pefhany
 
J

Jim Thompson

On Tue, 13 Dec 2005 17:52:53 -0800, John Larkin

[snip]
This is like arguing whether to have food or wine.

John

You left out _women_ ;-)

...Jim Thompson
 
K

Ken Smith

Rich Grise said:
unsigned int table[256]; /* Usually compilers initialize arrays to 0 */

I can't think of any compiler that initializes. I doubt that any micro
controller ones do.

If we're talking C, all objects with static storage duration *must* be
initialized. I've never seen a compiler that fails to do that.

Yes that is true. The statements after the declare had me thinking of
code within a function. I still hate C BTW.
 
K

Ken Smith

John Larkin said:
No, but a decent Vertex chip can do 100 multiplies (using 100
multipliers!) in a single clock, at 100 MHz. That's 10 GHz, sort of.

If you pipeline, you may be able to do better. I've never tryed to be
sure.
 
S

Spehro Pefhany

On Wed, 14 Dec 2005 02:46:57 +0000 (UTC), the renowned
[...]
unsigned int table[256]; /* Usually compilers initialize arrays to 0 */

I can't think of any compiler that initializes. I doubt that any micro
controller ones do.

If we're talking C, all objects with static storage duration *must* be
initialized. I've never seen a compiler that fails to do that.

Yes that is true. The statements after the declare had me thinking of
code within a function. I still hate C BTW.

How do you like C++? ;-) That's the one that's giving me a headache
at the moment.



Best regards,
Spehro Pefhany
 
T

Tony Williams

A simple linear 16x comparings code would probably be
less than 100 instructions.
[/QUOTE]
The midrange PIC doesn't have a compare instruction, but there's a
trick where you XOR a literal based on the previous set of XORs to
give zero when you get the desired match.
; input port in w, return result in w, 0xFF for invalid input
convert:
xorlw 0x01
btfsc STATUS,Z
retlw 0x00
xorlw (0x3 ^ 0x01)
btfsc STATUS,Z
retlw 0x01
xorlw (0x2 ^ 0x03)
...
xorlw (0x81 ^ 080)
btfsc STATUS,Z
retlw 0x0F
retlw 0xFF

Too neat and too subtle for me Speff. This is a dedicated
uP, running just the one prog. Why not throw some simple
brute force and ignorance at the problem.

.1st Load W with 1st possible input byte.
Subtract: W - actual input byte.
Skip to .2nd if result was not zero (Z=0).
Branch if Z=1 --> Set output nibble req'd for 1st.
Clear STATUS register.
Branch back to .16th.

.2nd Load W with 2nd possible input byte.
Subtract: W - actual input byte.
Skip to .3rd if result was not zero (Z=0).
Branch if Z=1 --> Set output nibble req'd for 2nd.
Clear STATUS register.
Branch back to .1st.

Similar .3rd, .4th, up to .15th.

.16th Load W with 16th possible input byte.
Subtract: W - actual input byte.
Skip to .again if result was not zero (Z=0).
Branch if Z=1 --> Set output nibble req'd for 16th.
Clear STATUS register.
Branch back to .15th.

.again Branch back to .1st.

Branching back one place after any match focusses
each loop on the three positions centred on the
last successful match. So each 3-position loop
will be about 7 to 20 instructions.

The inputs are from microswitches, and they only need
to be visited at about 1mS intervals. That could be
a PIC with an RC clock of about 100KHz or so.
 
T

Tony Williams

Tony Williams said:
Clear STATUS register.
etc

Oh Bum! Been reading ARM code for the last few days
and forgot that the PIC's STATUS register cannot,
(and should not), have it's Result bits cleared.
 
S

Spehro Pefhany

etc

Oh Bum! Been reading ARM code for the last few days
and forgot that the PIC's STATUS register cannot,
(and should not), have it's Result bits cleared.

;-) The ARM has a relatively pleasant machine language. Maybe a $2
Philips ARM would be a good choice for this application. Nah, the
second regulator for the core voltage spoils the elegance.

Your method is the same number of instructions per comparison. The
clever jumping around adds time worst case (and adds perhaps 1/3 to
the instructions), but you've achieved better typical response by
using that degree of freedom.

But here is a perhaps a better way than either if detecting invalid
states is not a requirement. I'll not bother putting it in asm for any
particular processor:

r = 0 ; clear the result
x = input ; sample the input ABCDEFGH
y = rotate_left(x) ; rotate x 1 bit to the left
; y = BCDEFGHA
if (x & y) set bit 0 of r
y = !y & x ; !y is 1's complement of y
; y now contains
; A&/B B&/C C&/D D&/E
; E&/F F&/G G&/H H&/A

if (y & 0xAA) set bit 1 of r
if (y & 0xCC) set bit 2 of r
if (y & 0xF0) set bit 3 of r


This is based on Andrew Holme's SPLD solution.


Best regards,
Spehro Pefhany
 
K

Keith Williams

To-Email- said:
On 13 Dec 2005 21:15:27 GMT, "John B"

[snip]

Jim appeared to be working on a solution but faded at the last furlong,

[snip]

I quit because I thought you were leaning toward one of those gross uP
solutions ;-)

...Jim Thompson

uP's are not gross! Overkill here, but definitely cool in lots of
apps. Can *you* do an analog 16x16 multiply accurate to one LSB? Hell,
you don't even *have* LSBs!

John

Yep, we do... the noise floor ;-)

Talk about mixed metaphors... ".. _analog_ 16x16 multiply.."

I can do multiplies at 5GHz, can you ?:)

Actually, yes. What variety would you like? Fixed point (32 or
64bit) or float (double or single). How much money you got? ;-)
 
K

Keith Williams

To-Email- said:
On Tue, 13 Dec 2005 17:52:53 -0800, John Larkin

[snip]
This is like arguing whether to have food or wine.

John

You left out _women_ ;-)

Compromise; "it's like arguing whether to have food or wine with
your _women_". ;-)
 
J

John B

On 14/12/2005 the venerable Spehro Pefhany etched in runes:

..
..
How do you like C++? ;-) That's the one that's giving me a headache
at the moment.



Best regards,
Spehro Pefhany

If you think that C++ is bad, just wait until you graduate to Visual
C#.NET!!
 
J

John B

On 13/12/2005 the venerable Richard Henry etched in runes:

..
..
I thought we had another week, at least.

Hey Richard. Take another week if you need it.

As I said yesterday there are still 47 bottlesh (hic - shorry that'sh
now 46) in my wine shellar, sho there'sh plenty to go round!!

Have a go at the really elegant software solution. Maybe four lines of
code and a 16 entry look-up table. That's assuming I don't get there
first.
 
J

John Larkin

[...]
unsigned int table[256]; /* Usually compilers initialize arrays to 0 */

I can't think of any compiler that initializes. I doubt that any micro
controller ones do.

If we're talking C, all objects with static storage duration *must* be
initialized. I've never seen a compiler that fails to do that.

Yes that is true. The statements after the declare had me thinking of
code within a function. I still hate C BTW.

How do you like C++? ;-) That's the one that's giving me a headache
at the moment.

Well, we all know what a solid piece of code Windows is.

John
 
K

Ken Smith

Spehro Pefhany said:
How do you like C++? ;-) That's the one that's giving me a headache
at the moment.

C++ has got to be an April fools day joke that got out of hand. C was the
wrong place to start to try to extend a language to include objects. C
was intended to produce very tight code and be easy to write a compiler
for. The cost was things like not being able to pass arrays and
structures[1]. C++ loses the tightness and ease of compiling and keeps
the inability to pass some things.

[1] In both C and C++ you can tell if the following statement will change
the value of "Suspect" or not without looking in some other file.

SureToChange = FooBar(Suspect);


BTW: Java was created by the sort of sick and twisted people who like C++
but wanted to remove the "dangers of pointers". The result is a
language that sneeks pointers in here and there.
 
Top