Ternary logic - a story

An area for asking questions, making suggestion, share ideas and place circuit examples.
Post Reply
User avatar
sir Kamba
Posts: 17
Joined: Wed Jun 10, 2015 1:46 pm
Location: northern hemisphere

Ternary logic - a story

Post by sir Kamba »

Recently i stubled across the concept of ternary logic and wanted to play around with it.Link to wikipedia
After a bit of reading I realised that logicCircuit support this kind of system using the tri-state gate and some conversion circuitry.
To start of with I needed a way to detect the 3 states of the wire. The first two [0 and 1] is easy, but the third state [high z][-] was not so easy.
After reading This thread I realised that if I defaulted it to both low and high and checked if the result was different I knew it was in the third state.
This resulted in the circuit a called branch.
Image
Now that I had a to check the 3 states i needed a way to set the wire to the desired state. This i achieved with 2 tri-state gates to drive the wire to 0 or 1 as the default state of the wire is -.
The resulting circuit I called bunch and uses the -0+ outputs from branch as input and a rom to make sure that only one of them are high at once.
Image

Now that I had a way of to control the 3 states of the wire i could start implementing the actual ternary logic.
Going from the wikipedia article I started implementing the truth tables as binary logic starting with the ternary equivalent to the and gate.
Image
Using the same methods to synthesize the other gates metioned in the wikipedia article I was now left with a bunch of ternary logic gates.
Image

Now that the basic logic was made what was I going to do with it?
Me being me what could be better than to make a computer, and what part of the computer is better to start with than the humble adder.
After looking around for different ternary numbering systems, I settled on Balanced ternary for it's apparent benefits.
After this some research was needed, so i set of in search of some examples to work of. After a while of searching I had learned of some attempts of making a ternary computer in Russia (some apparently successful), but I had yet to see any examples of balanced ternary addition.
At this point my interest in ternary math had been significantly reduced, and a new question had arisen in my head;
how much information can be pushed through a wire in logiccircuit?.
The obvious answer is 32 bits using the built in splitter.
Image
But I just learned to properly control all the 3 states of the wires in logiccircuit, and since 3 is more than 2 this must mean I can put MORE data though the cable than that.
This is indeed the case, and I started small and found the smallest easily convertible number, which turns out to 3 binary (with 8 states) to 2 ternary(with 9 states). The extra state I ignored for now (found out later that it is rather usefull later).
I started by making a conversion table

Code: Select all

 dec : bin : tern
 0 : 000 : 00
 1 : 001 : 0-
 2 : 010 : 01
 3 : 011 : -0
 4 : 100 : --
 5 : 101 : -1
 6 : 110 : 10
 7 : 111 : 1-
Later i found out that the state [--] is usefull becaus it represent not connected or NC so i mended the table and the following circuit without saving the original.

Code: Select all

 dec : bin : tern
 0 : 000 : 00
 1 : 001 : 0-
 2 : 010 : 01
 3 : 011 : -0
 4 : 100 : 11
 5 : 101 : -1
 6 : 110 : 10
 7 : 111 : 1-
 NC: 000 : --
Using this table I synthesized the circuits I creatively named "3binto2ten" and "2tento3bin".
I also gave them enable output and detect input using the NC state.
Image
With these circuits a have successfully pushed 3 bits of data through 2 wires.
Using more of these circuits in conjunction with the splitters I pushed a maximum of 48 bit of data through a single wire in logiccircuit!
Now remember the NC state I left behind? Well it is unused potential and when calculating the theoretical maximum I got 50.7 bits of data can theoretically be pushed though a wire in logiccircuit!!!
Image


If you want to try for yourself I will include all the circuit in the attached file.
It would be fantastic if anyone could make a balanced (or otherwise) ternary adder even though I have yet to make one.
This was not the only thing to come out of this experimenting with ternary logic/tri-state, but this post have run out of url's so it will have to be a follow up post.

Almost forgot the file:
ternary_logic.CircuitProject
(328.2 KiB) Downloaded 1291 times
User avatar
Xaetral
Posts: 46
Joined: Mon Nov 06, 2017 2:25 pm
Location: France

Re: Ternary logic - a story

Post by Xaetral »

nice post ^^
User avatar
sir Kamba
Posts: 17
Joined: Wed Jun 10, 2015 1:46 pm
Location: northern hemisphere

Re: Ternary logic - a story

Post by sir Kamba »

Thanks :)
I went ahead and made a balanced ternary adder today. It was surprisingly easy after the idea had lingered in my head for a bit, despite some bugs in logicCircuit.
It is not fully done as it lacks some testing, but as far as i can see it works fine.
Next up is subtraction, multiplication and memory. :P
Image
balanced ternary adder.CircuitProject
(156.52 KiB) Downloaded 1222 times
User avatar
Xaetral
Posts: 46
Joined: Mon Nov 06, 2017 2:25 pm
Location: France

Re: Ternary logic - a story

Post by Xaetral »

to answer the question "how much data can be pushed into one logiccircuit wire?" I would like to say that I made a 8 bit serial communication, so "infinite" and "32 bits per clock cycle" are valid answers to this question, even though I'm pretty sure I can go beyond 32b/cc

EDIT: 2^50 is roughly 3^32 so I think that you can put 50 bits in one wire with you method
User avatar
sir Kamba
Posts: 17
Joined: Wed Jun 10, 2015 1:46 pm
Location: northern hemisphere

Re: Ternary logic - a story

Post by sir Kamba »

You are correct and I should have specified it to "How much data can be pushed through a wire in logiccircuit in a single instance of time" or specified it to be data per unit of time. :)
User avatar
sir Kamba
Posts: 17
Joined: Wed Jun 10, 2015 1:46 pm
Location: northern hemisphere

Re: Ternary logic - Basic logic

Post by sir Kamba »

In binary logic there are 2 state; true and false.
This gives a total of 4 possible gates with 1 input and 1 output, and 16 possible gates with 2 inputs and 1 output.
Ternary logic has 3 states; true, false and unknown.
This gives 27 gates with 1 input and 1 output, and a staggering 19683 possible gates with 2 inputs and 1 output.

Because of the sheer number of possible gates, it is important to separate the useful ones from the useless ones.
The first ones to be called useless, are the ones with static output regardless of the inputs. There are 3 of these; True, false and unknown.

Beyond this i have identified a few useful 2 input gates and a few useful 1 input gates.
They are listed on the following format: Image
Image
These i have all used so far to some degree.

When it comes to single input gates, I have found 2 types that are useful: the humble negation/not gate and
the gates that follow this formula: "If state then True else False" and the negative of these, as they make it easier to manage the different states.

All of the ternary gates can be combined in the same manner that binary gates are combined to make circuits.
A few circuits are easy to make, such as the multiplexer and full adder/subtractor,
but I have yet to make anything ternary equivalent to the sr-latch or the jk flip-flop.

I will upload a distilled version of my logiccircuit file and a spreadsheet in the near future.
User avatar
sir Kamba
Posts: 17
Joined: Wed Jun 10, 2015 1:46 pm
Location: northern hemisphere

Re: Ternary logic - Input and output

Post by sir Kamba »

Sorry for waiting so long before continuing to upload. Most of this was done almost a month ago.

In order to test any any of the ternary circuits we need a way to give them inputs and to read the output.
And to start with I did it in the simplest possible way 1 button for each state of the wire as inputs and 1 led for each state as output. This was implemented with the branch/bunch circuits and then grouped into 8 terns.
Image
I then realized that the 0 button in the middle was useless as when no button was pressed it defaulted to 0. and as such i simplified it to:
Image

This is fine for simple circuits, but I wanted something easier to understand.
I started with a way to implement constants. The simplest way to do this was to have 2 binary wires for each ternary wires.
Image
This was also grouped to 8 terns since I had already decided to work with that quantity of wires.
Image
I also made a converting tool in libreoffice calc.

Now this is fine for most cases, but what if I want to simply write a hex number and get a hex number to display?
To get a Hexadecimal output I made this:
Image
a brute force aproach that converts 8 tern balanced ternary to 12 bit binary + a sign bit and hooked it up to a hexadecimal 7 segment display.
Now the next thing needed is a way to convert hex to balanced ternary.
Image
This uses the same principle of brute forcing to convert the values.
And at the end I have a easy way to test my balanced ternary adder (ignoring the fact that a few of the previous circuits requires it to function).
Image

OOOPs, did not intend for my cursor to be in so many of the images. Even twice in the same one???
Attachments
ternary_IO.CircuitProject
updated to work with newest version (added all the probes)
(863.97 KiB) Downloaded 1263 times
terniary_operands.xlsx
also contains tool for converter.
(12.71 KiB) Downloaded 1144 times
Post Reply