logo

Verilog sivi brojač

Gray kod je vrsta binarnog brojevnog sustava gdje se samo jedan bit mijenja u jednom trenutku. Danas se sivi kod naširoko koristi u digitalnom svijetu. Bit će od pomoći za ispravljanje grešaka i prijenos signala. Gray brojač je također koristan u projektiranju i provjeri u VLSI domeni.

Verilog sivi brojač

Gray Code kodira cijele brojeve kao nizove bitova sa svojstvom da se prikazi susjednih cijelih brojeva razlikuju u točno jednoj binarnoj poziciji.

Postoje različite vrste sivih kodova, kao što su uravnoteženi, binarni reflektirani, maksimalni razmak i antipodalni sivi kod.

Brojači imaju primarnu funkciju proizvodnje određene izlazne sekvence i ponekad se nazivaju generatori uzoraka.

Oblikovati

U sivom kodu samo se jedan bit mijenja odjednom. Ovaj dizajnerski kod ima dva ulaza, signale sata i resetiranja i jedan 4-bitni izlaz koji će generirati sivi kod.

Prvo, ako je rstn signal visok, tada će izlaz biti nula, a čim rstn ide nisko, na uzlaznom rubu clk , dizajn će generirati četverobitni sivi kod i nastaviti generirati na svakom rastućem rubu clk signal.

Ovaj dizajn koda može se nadograditi i staviti binarne brojeve kao ulaz, a ovaj dizajn će raditi kao pretvarač binarnog u sivi kod.

 module gray_ctr # (parameter N = 4) ( input clk, input rstn, output reg [N-1:0] out); reg [N-1:0] q; always @ (posedge clk) begin if (!rstn) begin q <= 0; out <="0;" end else begin q + 1; `ifdef for_loop for (int i="0;" n-1; out[i] ^ q[i]; out[n-1] `else q[n-1:1] q[n-2:0]}; `endif endmodule pre> <h3>Hardware Schematic</h3> <img src="//techcodeview.com/img/verilog-tutorial/27/verilog-gray-counter-2.webp" alt="Verilog Gray Counter"> <h3>Testbench</h3> <pre> module tb; parameter N = 4; reg clk; reg rstn; wire [N-1:0] out; gray_ctr u0 ( .clk(clk), .rstn(rstn), .out(out)); always #10 clk = ~clk; initial begin {clk, rstn} <= 0; $monitor ('t="%0t" rstn="%0b" out="0x%0h&apos;," $time, rstn, out); repeat(2) @ (posedge clk); <="1;" repeat(20) $finish; end endmodule pre> <p>And it produces the following output, such as:</p> <pre> ncsim&gt; run T=0 rstn=0 out=0xx T=10 rstn=0 out=0x0 T=30 rstn=1 out=0x0 T=50 rstn=1 out=0x1 T=70 rstn=1 out=0x3 T=90 rstn=1 out=0x2 T=110 rstn=1 out=0x6 T=130 rstn=1 out=0x7 T=150 rstn=1 out=0x5 T=170 rstn=1 out=0x4 T=190 rstn=1 out=0xc T=210 rstn=1 out=0xd T=230 rstn=1 out=0xf T=250 rstn=1 out=0xe T=270 rstn=1 out=0xa T=290 rstn=1 out=0xb T=310 rstn=1 out=0x9 T=330 rstn=1 out=0x8 T=350 rstn=1 out=0x0 T=370 rstn=1 out=0x1 T=390 rstn=1 out=0x3 T=410 rstn=1 out=0x2 Simulation complete via $finish(1) at time 430 NS + 0 </pre> <h3>Balanced Gray Code</h3> <p>In balanced Gray codes, the number of changes in different coordinate positions is as close as possible.</p> <p>A Gray code is <strong> <em>uniform</em> </strong> or <strong> <em>uniformly</em> </strong> balanced if its transition counts are all equal.</p> <p>Gray codes can also be <strong> <em>exponentially</em> </strong> balanced if all of their transition counts are adjacent powers of two, and such codes exist for every power of two.</p> <p>For example, a balanced 4-bit Gray code has 16 transitions, which can be evenly distributed among all four positions (four transitions per position), making it uniformly balanced.</p> <pre> 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1 </pre> <h3>n-ary Gray Code</h3> <p>There are many specialized types of Gray codes other than the binary-reflected Gray code. One such type of Gray code is the n-ary Gray code, also known as a <strong> <em>non-Boolean</em> </strong> Gray code. As the name implies, this type of Gray code uses non-Boolean values in its encodings.</p> <p>For example, a 3-ary ternary Gray code would use the values {0, 1, and 2}. The (n, k)-Gray code is the n-ary Gray code with k digits. The sequence of elements in the (3, 2)-Gray code is: {00, 01, 02, 12, 11, 10, 20, 21, and 22}.</p> <p>The (n, k)-Gray code may be constructed recursively, as the BRGC, or may be constructed iteratively.</p> <h3>Monotonic Gray Codes</h3> <p>Monotonic codes are useful in interconnection networks theory, especially for minimizing dilation for linear arrays of processors.</p> <p>If we define the weight of a binary string to be the number of 1s in the string, then although we clearly cannot have a Gray code with strictly increasing weight, we may want to approximate this by having the code run through two adjacent weights before reaching the next one.</p> <h3>Beckett-Gray Code</h3> <p>Another type of Gray code, the Beckett-Gray code, is named for Irish playwright <strong> <em>Samuel Beckett</em> </strong> , who was interested in <strong> <em>symmetry</em> </strong> . His play <strong> <em>Quad</em> </strong> features four actors and is divided into sixteen time periods. Each period ends with one of the four actors entering or leaving the stage.</p> <p>The play begins with an empty stage, and Beckett wanted each subset of actors to appear on stage exactly once. A 4-bit binary Gray code can represent the set of actors currently on stage.</p> <p>However,</p> <p>Beckett placed an additional restriction on the script: he wished the actors to enter and exit so that the actor who had been on stage the longest would always be the one to exit.</p> <p>The actors could then be represented by a first-in, first-out (FIFO) queue so that the actor being dequeued is always the one who was enqueued first.</p> <p>Beckett was unable to find a Beckett-Gray code for his play, and indeed, an exhaustive listing of all possible sequences reveals that no such code exists for n = 4. It is known today that such codes do exist for n = 2, 5, 6, 7, and 8, and do not exist for n = 3 or 4.</p> <h3>Snake-in-the-box Codes</h3> <p>Snake-in-the-box codes, or snakes, are the sequences of nodes of induced paths in an n-dimensional <strong> <em>hypercube</em> </strong> graph, and coil-in-the-box codes, or coils, are the sequences of nodes of induced cycles in a hypercube.</p> <p>Viewed as Gray codes, these sequences have the property of detecting any single-bit coding error.</p> <h3>Single-track Gray Code</h3> <p>Another kind of Gray code is the single-track Gray code (STGC) developed by <strong> <em>Norman B. Spedding</em> </strong> and refined by <strong> <em>Hiltgen, Paterson</em> </strong> and <strong> <em>Brandestini</em> </strong> in &apos;Single-track Gray codes&apos; (1996).</p> <p>The STGC is a cyclical list of P unique binary encodings of length n such that two consecutive words differ in exactly one position. When the list is examined as a P &#xD7; n matrix, each column is a cyclic shift of the first column.</p> <p>The name comes from their use with rotary encoders, where many tracks are being sensed by contacts, resulting in each in an output of 0 or 1. To reduce noise due to different contacts not switching the same moment in time, one preferably sets up the tracks so that the contacts&apos; data output is in Gray code.</p> <p>To get high angular accuracy, one needs lots of contacts; to achieve at least 1-degree accuracy, one needs at least 360 distinct positions per revolution, which requires a minimum of 9 bits of data and the same number of contacts.</p> <p>If all contacts are placed at the same angular position, then 9 tracks are needed to get a standard BRGC with at least 1-degree accuracy. However, if the manufacturer moves a contact to a different angular position but at the same distance from the center shaft, then the corresponding &apos;ring pattern&apos; needs to be rotated the same angle to give the same output.</p> <h3>Two-dimensions Gray Code</h3> <p>Two-dimensional Gray codes are used in communication to minimize the number of bit errors in quadrature amplitude modulation adjacent points in the constellation.</p> <p>In a standard encoding, the horizontal and vertical adjacent constellation points differ by a single bit, and adjacent diagonal points differ by 2 bits.</p> <hr></=></pre></=>

Uravnoteženi sivi kod

U uravnoteženim Grayevim kodovima, broj promjena u različitim koordinatnim položajima je što je moguće bliži.

Greyev kod je uniforma ili jednolično uravnotežen ako su svi njegovi brojevi prijelaza jednaki.

Gray kodovi također mogu biti eksponencijalno uravnoteženi ako su svi njihovi brojevi prijelaza susjedni potencije dvojke, a takvi kodovi postoje za svaku potenciju dvojke.

Na primjer, uravnoteženi 4-bitni Grayev kod ima 16 prijelaza, koji se mogu ravnomjerno rasporediti među sva četiri položaja (četiri prijelaza po položaju), što ga čini ravnomjerno uravnoteženim.

 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1 

n-arni Grayev kod

Postoje mnoge specijalizirane vrste Grayeva koda osim Grayeva koda s binarnom refleksijom. Jedna takva vrsta Grayeva koda je n-arni Grayev kod, također poznat kao a ne-Booleov Sivi kod. Kao što naziv implicira, ova vrsta Grayeva koda koristi ne-Booleove vrijednosti u svom kodiranju.

Na primjer, 3-arni ternarni Grayev kod koristio bi vrijednosti {0, 1 i 2}. (n, k)-Grayev kod je n-arni Grayev kod s k znamenki. Redoslijed elemenata u (3, 2)-Grayovom kodu je: {00, 01, 02, 12, 11, 10, 20, 21 i 22}.

(n, k)-Grayov kod može se konstruirati rekurzivno, kao BRGC, ili se može konstruirati iterativno.

Monotoni sivi kodovi

Monotoni kodovi korisni su u teoriji mreža međusobnog povezivanja, posebno za minimiziranje dilatacije za linearne nizove procesora.

Ako definiramo težinu binarnog niza kao broj 1s u nizu, tada, iako očito ne možemo imati Grayev kod sa striktno rastućom težinom, možda ćemo htjeti to aproksimirati tako da kod prođe kroz dvije susjedne težine prije nego što dosegne sljedeći.

Beckett-Grayov kod

Druga vrsta Grayeva koda, Beckett-Grayev kod, nazvana je po irskom dramatičaru Samuel Beckett , koje je zanimalo simetrija . Njegova igra četverostruki ima četiri glumca i podijeljen je u šesnaest vremenskih razdoblja. Svako razdoblje završava ulaskom ili odlaskom jednog od četiri glumca na pozornicu.

Predstava počinje s praznom pozornicom, a Beckett je želio da se svaka podgrupa glumaca pojavi na pozornici točno jednom. 4-bitni binarni Grayev kod može predstavljati skup glumaca koji su trenutno na pozornici.

Međutim,

Beckett je postavio dodatno ograničenje scenariju: želio je da glumci ulaze i izlaze tako da uvijek izlazi onaj glumac koji je najdulje na sceni.

Glumci bi tada mogli biti predstavljeni redom čekanja prvi ušao, prvi izašao (FIFO), tako da je glumac koji se uklanja iz reda uvijek onaj koji je prvi stavljen u red.

Beckett nije uspio pronaći Beckett-Grayev kod za svoju igru, i doista, iscrpan popis svih mogućih nizova otkriva da takav kod ne postoji za n = 4. Danas je poznato da takvi kodovi postoje za n = 2, 5. , 6, 7 i 8, i ne postoje za n = 3 ili 4.

Kodovi zmije u kutiji

Kodovi zmije u kutiji, ili zmije, sekvence su čvorova induciranih staza u n-dimenzionalnom hiperkocka graf, a coil-in-the-box kodovi ili zavojnice su nizovi čvorova induciranih ciklusa u hiperkocki.

Gledano kao Grayevi kodovi, ovi nizovi imaju svojstvo otkrivanja bilo koje jednobitne pogreške kodiranja.

Jednotračni Gray Code

Druga vrsta Grayeva koda je jednotračni Grayev kod (STGC) koji je razvio Norman B. Spedding i oplemenjen od strane Hiltgen, Paterson i Brandestini u 'Single-track Gray codes' (1996).

STGC je ciklički popis P jedinstvenih binarnih kodiranja duljine n tako da se dvije uzastopne riječi razlikuju u točno jednoj poziciji. Kada se lista ispituje kao P × n matrica, svaki stupac je ciklički pomak prvog stupca.

mini alatna traka excel

Naziv dolazi od njihove upotrebe s rotirajućim koderima, gdje kontakti očitavaju mnoge staze, što rezultira izlazom 0 ili 1 za svaki. Kako bi se smanjio šum zbog različitih kontakata koji se ne prebacuju u istom trenutku, poželjno je postaviti prati tako da je izlaz podataka o kontaktima u Grayevom kodu.

Za postizanje visoke kutne točnosti potrebno je puno kontakata; da bi se postigla točnost od najmanje 1 stupnja, potrebno je najmanje 360 ​​različitih pozicija po okretaju, što zahtijeva minimalno 9 bitova podataka i isti broj kontakata.

Ako su svi kontakti postavljeni u isti kutni položaj, tada je potrebno 9 staza da bi se dobio standardni BRGC s točnošću od najmanje 1 stupnja. Međutim, ako proizvođač pomakne kontakt u drugačiji kutni položaj, ali na istoj udaljenosti od središnjeg vratila, tada se odgovarajući 'uzorak prstena' mora zakrenuti pod istim kutom kako bi se dobio isti učinak.

Dvodimenzionalni Gray kod

Dvodimenzionalni Grayevi kodovi koriste se u komunikaciji kako bi se smanjio broj bitnih pogrešaka u kvadraturnoj modulaciji amplitude susjednih točaka u konstelaciji.

U standardnom kodiranju, horizontalne i okomite susjedne konstelacijske točke razlikuju se za jedan bit, a susjedne dijagonalne točke razlikuju se za 2 bita.