logo

Comptador Verilog Grey

El codi gris és una mena de sistema de nombres binaris on només canviarà un bit alhora. Avui el codi gris s'utilitza àmpliament al món digital. Serà útil per a la correcció d'errors i la transmissió del senyal. El comptador de gris també és útil en el disseny i la verificació al domini VLSI.

Comptador Verilog Grey

Un codi gris codifica nombres enters com a seqüències de bits amb la propietat que les representacions dels nombres enters adjacents difereixen exactament en una posició binària.

Hi ha diferents tipus de codis grisos, com ara el codi equilibrat, el binari reflectit, el buit màxim i el codi gris antípoda.

Els comptadors tenen la funció principal de produir una seqüència de sortida especificada i de vegades s'anomenen generadors de patrons.

Disseny

En un codi gris, només canvia un bit alhora. Aquest codi de disseny té dues entrades, senyals de rellotge i reinici i una sortida de 4 bits que generarà codi gris.

Primer, si el primer senyal és alt, llavors la sortida serà zero, i tan aviat com primer baixa, a la vora ascendent de clk , el disseny generarà un codi gris de quatre bits i continuarà generant-se a cada front ascendent de clk senyal.

Aquest codi de disseny es pot actualitzar i posar números binaris com a entrada, i aquest disseny funcionarà com a convertidor de codi binari a gris.

 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></=>

Codi de gris equilibrat

En els codis de grisos equilibrats, el nombre de canvis en diferents posicions de coordenades és el més proper possible.

Un codi gris és uniforme o uniformement equilibrat si els seus comptes de transició són tots iguals.

Els codis grisos també ho poden ser exponencialment equilibrat si tots els seus recomptes de transició són potències adjacents de dos, i aquests codis existeixen per a cada potència de dos.

Per exemple, un codi gris equilibrat de 4 bits té 16 transicions, que es poden distribuir uniformement entre les quatre posicions (quatre transicions per posició), fent-lo uniformement equilibrat.

 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 

Codi gris n-ari

Hi ha molts tipus especialitzats de codis de gris a part del codi de gris reflectit en binari. Un d'aquests tipus de codi Gray és el codi Gray n-ari, també conegut com a no booleà Codi gris. Com el seu nom indica, aquest tipus de codi Gray utilitza valors no booleans en les seves codificacions.

Per exemple, un codi gris ternari de 3 àries utilitzaria els valors {0, 1 i 2}. El codi (n, k)-Gray és el codi gris n-ari amb k dígits. La seqüència d'elements del codi (3, 2)-Gris és: {00, 01, 02, 12, 11, 10, 20, 21 i 22}.

El codi (n, k)-Gray es pot construir de manera recursiva, com el BRGC, o es pot construir de manera iterativa.

Codis grisos monòtons

Els codis monòtons són útils en la teoria de xarxes d'interconnexió, especialment per minimitzar la dilatació de matrius lineals de processadors.

Si definim que el pes d'una cadena binària és el nombre d'1 a la cadena, aleshores, tot i que clarament no podem tenir un codi Gray amb un pes estrictament creixent, potser voldrem aproximar-ho fent que el codi passi per dos pesos adjacents abans d'arribar. el següent.

Codi Beckett-Gray

Un altre tipus de codi Gray, el codi Beckett-Gray, rep el nom del dramaturg irlandès Samuel Beckett , a qui li interessava simetria . La seva jugada Quad compta amb quatre actors i es divideix en setze períodes de temps. Cada període acaba amb un dels quatre actors entrant o sortint de l'escenari.

L'obra comença amb un escenari buit i Beckett volia que cada subconjunt d'actors aparegués a l'escenari exactament una vegada. Un codi gris binari de 4 bits pot representar el conjunt d'actors que es troben actualment a l'escenari.

Malgrat això,

Beckett va posar una restricció addicional al guió: va desitjar que els actors entréssin i sortissin perquè l'actor que havia estat més temps a l'escenari sempre fos el que sortís.

Aleshores, els actors es podrien representar amb una cua de primer en entrar, primer en sortir (FIFO) de manera que l'actor que s'elimina sempre sigui el que s'ha posat primer a la cua.

Beckett no va poder trobar un codi de Beckett-Gray per a la seva obra i, de fet, una llista exhaustiva de totes les seqüències possibles revela que no existeix aquest codi per a n = 4. Avui se sap que aquests codis existeixen per a n = 2, 5. , 6, 7 i 8, i no existeixen per a n = 3 o 4.

Codis de la serp a la caixa

Els codis de serp a la caixa, o serps, són les seqüències de nodes de camins induïts en una n-dimensional hipercub graf i els codis de bobina a la caixa, o bobines, són les seqüències de nodes de cicles induïts en un hipercub.

Vistes com a codis grisos, aquestes seqüències tenen la propietat de detectar qualsevol error de codificació d'un sol bit.

Codi gris d'una sola pista

Un altre tipus de codi Gray és el codi Gray d'una sola pista (STGC) desenvolupat per Norman B. Spedding i refinat per Hiltgen, Paterson i Brandestini a 'Single-track Grey codes' (1996).

El STGC és una llista cíclica de P codificacions binàries úniques de longitud n de manera que dues paraules consecutives difereixen exactament en una posició. Quan la llista s'examina com una matriu P × n, cada columna és un desplaçament cíclic de la primera columna.

on són la configuració del navegador

El nom prové del seu ús amb codificadors rotatius, on moltes pistes estan sent detectades per contactes, donant com a resultat una sortida de 0 o 1. Per reduir el soroll a causa de diferents contactes que no canvien al mateix moment en el temps, preferiblement es configura el pistes perquè les dades de sortida dels contactes estiguin en codi gris.

Per obtenir una alta precisió angular, es necessiten molts contactes; Per aconseguir una precisió d'almenys 1 grau, cal com a mínim 360 posicions diferents per revolució, la qual cosa requereix un mínim de 9 bits de dades i el mateix nombre de contactes.

Si tots els contactes es col·loquen a la mateixa posició angular, calen 9 pistes per obtenir un BRGC estàndard amb una precisió d'almenys 1 grau. Tanmateix, si el fabricant mou un contacte a una posició angular diferent però a la mateixa distància de l'eix central, el 'patró d'anell' corresponent s'ha de girar amb el mateix angle per donar la mateixa sortida.

Codi gris de dues dimensions

Els codis de gris bidimensionals s'utilitzen en la comunicació per minimitzar el nombre d'errors de bits en els punts adjacents de la modulació d'amplitud en quadratura de la constel·lació.

En una codificació estàndard, els punts de constel·lació adjacents horitzontals i verticals difereixen en un sol bit, i els punts diagonals adjacents difereixen en 2 bits.