Appunti Logica Ternaria

primo esperimento in ternario: Arduino trit generator

Primo esperimento Logica Ternaria: Arduino “trit” Generator

I computer del futuro prossimo abbandoneranno il sistema binario per quello ternario o quaternario? E’ altamente probabile. Quelli che seguono sono alcuni mie appunti sul tema, ispirati, per il sistema ternario, dalle recenti pubblicazioni del prof.  D.W. Jones dell’Università  dell’Iowa.

G3TR Transistor Tester on Arduino-DUE

This little work is in memory of a great man, who honored me with his friendship: Pino Rizzitano.


This is the Arduino-DUE version of my G3TR Transistor Tester that everyone can easily build (DIY). All components required, apart an Arduino-Due board, are just two 10K resistors and a microswitch. I’ve made two different versions of the software to experiment with the SAM3X8E hardware:

  • In the first one I use the  direct  ARM processor registers manipulation. So, each register is accessed  by an “unsigned long” pointer and I gain the complete control of ARM processor hardware registers ( using C language ): g3trDue.
  • In the second one  I use the software drivers provided by Atmel: g3trDriverDue .

Anyway, in both versions, the Arduino IDE is just used to compile and upload the sketch to the board.

G3TR Transistor Tester

G3TR Transistor Tester

Translate a Gray Code into Decimal ( weighted method )

To translate an n-bit bynary code into decimal we use the well known formula:

[bn-1…….b1b0(2) ](10) = bn-1*(2)n-1 + ……. + b1*(2)1 +b0*(2)0

where : (2)n-1 …….(2)1 (2)0 are called weights and bi is the i-th bit.

To convert an n-bit Gray Code into his decimal representation I modified the previous formula as follow:

[gn-1…….g1g0 (gray)](10) = bn-1*(2)n-1 + ……. + b1*(2)1 + b0*(2)0


  • bis the i-th calculated bit;

  • bn-1 = gn-1

  • bi= [bi+1 – gi](MOD2) or bi= [bi+1 + gi](MOD2) with 0 =< i <= n-2;


  • [bi+1 – gi](MOD2) is the two-bit subtraction ignoring the borrow;

  • [bi+1+ gi](MOD2) is the two-bit addition ignoring the carry.

Two-bit subtraction MOD2 and two-bit addition MOD2 give same result bit !

Now I will explain the conversion of a Gray code into decimal with an example.

Consider the following four-bit Gray Code :


We have: n = 4. The Gray bits, starting from msb, are:

g3 =1

g2 = 0

g1 = 1

g0 = 1

and the calculated bits are:

b3 = g3 = 1

b2 = [b3 – g2](MOD2) = [1-0](MOD2) = 1

b1= [b2 – g1](MOD2) = [1-1](MOD2) = 0

b0= [b1 – g0](MOD2) = [0-1](MOD2) = 1

so, applying these calculated bits in my formula, finally we have:

[1011(gray)](10) = 1*(2)3 + 1*(2)2 + 0*(2)1 + 1*(2)0 = 13(10)

This calculation makes use of the same binary system weights and therefore proves that an n-bit Gray Code ( not a Gray Code such as that we use to code the ten digits from 0 to 9 ) may be translated into decimal by means of the weighted method shown.

Gray Code, weighted or non-weighted: that is the question!

Gray code used for shaft ­angle encoding. Thanks to Clive Maxfield  ( )  for allowing me to use his image.

Gray code used for shaft ­angle encoding.

To build the Gray Code we may use the mirror method, i.e. :

0                               0   0

1                               0   1

——-     ==>          ————    mirror line

1                               1   1

0                               1   0

A “mirror”  represented by a line is placed below the two initial bits ( 0 and 1 ), giving rise to the reflection indicated. Thereafter above the mirror line we add “0” and below the mirror line we add “1”. The following is a 2D version of the two bits Code:


Using this figure we can easily build eight different  2-bits Gray Code: 00,01,11,10 – 01,11,10,00 – 11,10,00,01 – 10, 00,01,11 —  00,10,11,01 – 10,11,01,00 – 11,01,00,10 – 01,00,10,11. By iterating the riflective process allow us to extend the Gray Code representation. Here, I show two possible 3D version of 3-bits Gray Code.  Note the two different colored paths:  they give rise to sixteen possible different  3-bits  Gray Code  each!  ( moving clockwise and counterclockwise ).



So, the sixteen representation for the standard four bits Gray Code are:

  1. 0000
  2. 0001
  3. 0011
  4. 0010
  5. 0110
  6. 0111
  7. 0101
  8. 0100
  9. 1100
  10. 1101
  11. 1111
  12. 1110
  13. 1010
  14. 1011
  15. 1001
  16. 1000

Some Gray Code features:

  •  Representation of successive word  code differ one another in only a single bit.
  • The last representation differ from the first one just for a single bit, so the code is cyclic ( see the 2D and 3D cubes shown above ).

If we need to use just ten representation to code decimal digit from 0 to 9, in Gray, we can estract two subset of Gray Code having both the features mentioned above.

Excess-3 Gray Code:

We extract the ten representations starting from  previous “four bits word”  N. 4:

Gray           Dec

0010             0

0110             1

0111             2

0101             3

0100             4

1100             5

1101             6

1111             7

1110             8

1010             9

A code like this is clearly non-weighted ( the weight of second bit in the representation 0010  corrisponding to value 0 decimal should be zero  and that is impossible !)

Second SubSet of  Gray Code:

We can extract the first five representations and the last five representations to obtain such a code:

Gray              Dec

0000                0
0001                1
0011                2
0010                3
0110                4

1110                5
1010                6
1011                7
1001                8
1000                9

A Code like this is non-weighted. See ” Fundamentals of Logic Design”  – Sixty Edition – By Charles H Roth,Jr and Larry L Kynney.

In both last two cases, the argument that Gray is non-weighted is based only on the property that consecutive values differ in one bit position.

Gray Code as “weighted code”:

Given that I have not invented it, consider the four-bit gray code: b3, b2, b1, b0.

The weight of i-th bit is given by:  (2 ^(i + 1)) – 1.

Thus, the weight of the bits b2, being i = 2, is: (2^3)  – 1 = 7.

The weights for the four bits are then: 15, 7, 3, 1, starting from the MSB.

For the conversion into  decimal of a binary Gray code is necessary to consider the sign toggling on weights of “ones” . The weight of “one” in the most significant position assumes the sign “+” and the weight of the next ‘”one” takes on the “-” sign and so on..

For example, the decimal conversion of the Gray code 1011 is:

+15   7    -3    +1    <—– weigths

1      0      1       1 (gray) ——> + 1 * (15) + 0 * (7) – 1* (3) + 1 * (1) = 13 (dec)

where in brackets are the weights.

Another example for a 5 bits Gray code:

+31 -15    7    3     +1 <—– weigths

1       1     0     0      1 (gray) ——> + 1 * (31)   -1* (15) +1* (1) = 17 (dec)

Thas, just using bit weights, It is possible to write the following table:

Gray    Dec

0000    0

0001    1

0010    3

0100    7

1000   15

and  so on…

This Gray Code approach is totally different from the  previous two. It apply to the Gray reflected ( simple mirror construction ) and It is valid for any number of bits. Finally, the book Fundamentals of Logic Design by Roth and Kenney states:

“In general, the decimal value of a coded digit cannot be computed by a simple formula when a non-weighted code is used.”

simple formula” :  this is certainly a subjective definition, based on each person’s opinion of what is simple.

Imho  the Gray Code, as I showed, is a “weighted code”, if nothing else, at least in accordance with the “simple formula” approach.

To show the simple approach I am attaching:

My algorithm ( In Italian ) to translate a gray code in decimal based on weights.

My C program ( comments are in Italian ) to translate a gray code in decimal based on weights.

Note: in the  document,  at Brandeis University (USA), the Gray Code is defined as ” variable weighted code”, using an approach different of mine.

Acknowledgment:  to Pete Sanderson for his opinions on weigthed  and  non-weigthed Gray Code sent to me recently via e-mail. I used, in this post, some of  his considerations.

A Strange Tube Headphone Amplifier


This experiment was conducted thanks to the recycling of a Car Igntion Coil recovered from my student and the gift of a tube 12AX7 by – Jungleland – Bass Guitar Accessories by Giuseppe Ceglie – Via Indipendenza, 15 Catanzaro.

The amplifier makes use of a tube powered at low voltage  ( from  40V to 60 V max for safety ) and a car ignition coil as output transformer ( impedance adapter ). The use of  low voltage avoids the problems of security that you require usually when handling vacuum tubes. Typically a tube works with high voltage ( 200-250 V or more ). The result obtained is really interesting. Here is the schematic:

Tube Headphone Amplifier

Versione in Italiano:

Uno strano Amplificatore per cuffia.

Questo semplice esperimento è stato realizzato riciclando:

  • una bobina di accensione candela per auto recuperata da un mio studente;
  •  una valvola termoionica 12AX7 ( usata negli amplificatori valvolari per chitarra ) regalatami da Giuseppe Ceglie proprietario del negozio per strumenti misicali : Jungleland – Bass Guitar Accessories  – Via Indipendenza, 15 Catanzaro.

L’ amplificatore fa uso di un tubo alimentato a basso voltaggio ( 40-60 Volt per motivi di sicurezza) e di una bobina per auto come trasformatore d’ uscita ( adattatore di impedenza ). L’ uso del basso voltaggio evita i problemi di sicurezza che si incontrano quando si lavora con le valvole termoioniche. Tipicamente i tubi lavorano con tensioni tra i 200-250V o anche superiori. Il risultato ottenuto è veramente interessante. E’ infatti possibile apprezzare il suono “caldo” degli amplificatori valvolari.