Essential FPGA Written Exam Questions

Essential FPGA Written Exam Questions
1. Implement the detection of the 10010 code using a state machine, for example, x=1001001000 z=0000100100 (output)
Examines state machines (similar questions exist, need to fully understand)
Verilog
module check(rst_i,clk_i,data_i,data_o);    input  rst_i,clk_i;    input  data_i;    output data_o;    reg[3:0] current_state,next_state;    parameter[3:0]        idle="0000",        state1="0001",        state2="0010",        state3="0100",        state4="1000";         always@(posedge clk_i or negedge rst_i)if (!rst_i)              current_state <= idle;         else             current_state <= next_state;always@(current_state,data_i)case(current_state)idle :    if (data_i==1)next_state=state1;else next_state=idle;state1: if (data_i==0)next_state=state2;else next_state=idle;state2: if (data_i==0)next_state=state3;else next_state=idle;state3:    if (data_i==1)next_state=state4;else next_state=idle;state4:    if (data_i==0)next_state=idle;else next_state=idle;endcaseassign data_o= (current_state==state4);endmodule
VHDL
library    ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity check is          port(    rst_i :in  std_logic;    clk_i :in  std_logic;data_i:in  std_logic;data_o:out std_logic);end entity;architecture behave of check is    type state is (state_a,state_b,state_c,state_d,state_e);       signal current_state:state;    signal next_state:state;begin    process(rst_i,clk_i)beginif rst_i='1' then            data_o <='0';            current_state <= state_a;elsif rising_edge(clk_i)    then            current_state <= next_state;end if;end process;    process(current_state,data_i)begincase  current_state is when state_a => if data_i='1' then                               next_state <= state_b;else                               next_state <= state_a;end if;   when state_b =>    if data_i='0' then                               next_state <= state_c;else                               next_state <= state_a;end if; when state_c =>    if data_i='0' then                               next_state <= state_d;else                               next_state <= state_a;end if; when state_d =>    if data_i='1' then                               next_state <= state_e;else                               next_state <= state_a;end if; when state_e =>    if data_i='0' then                               next_state <= state_a;      else                               next_state <= state_a;end if;   when others =>    null;end case;     end;data_o <='1' when current_state = state_e else '0';    end;
Essential FPGA Written Exam Questions
2. Write the hexadecimal representation of 169.6825
A9.AEB85 0.6825×16 take the integer part, then use the fractional part to take the integer
3. Implement a logic circuit for 2x frequency division using D flip-flops?
Verilog description:
module divide2( clk , clk_o, reset);    input     clk , reset;    output   clk_o;    wire in; reg out ;    always @ ( posedge clk or posedge reset)if ( reset)out <= 0;elseout <= in;assign in = ~out;assign clk_o = out;      endmodule
Essential FPGA Written Exam Questions
4. Describe an 8-bit D flip-flop logic using VHDL or Verilog.
module dff8(clk , reset, d, q);input        clk;input        reset;input  [7:0] d;output [7:0] q;reg   [7:0] q;always @ (posedge clk or posedge reset)if(reset)q <= 0;elseq <= d;endmodule
5. Given the setup and hold time of the register, find the delay range of the intermediate combinational logic. Delay < period – setup – hold
Essential FPGA Written Exam Questions
6. Write the Verilog module for an asynchronous D flip-flop
module dff8(clk , reset, d, q);input        clk;input        reset;input   d;output  q;reg q;always @ (posedge clk or posedge reset)if(reset)q <= 0;elseq <= d;endmodule
Essential FPGA Written Exam Questions
7. Draw a state machine that accepts 1, 2, and 5 cents for a newspaper vending machine, where each newspaper costs 5 cents
Draw the possible states (answers below).
Essential FPGA Written Exam Questions
8
Essential FPGA Written Exam Questions
Let R1 be the left register and R2 be the right register. The feedback time for R1 to itself is 7(=1+ 5*1+T_setup) and for R2 to itself is 6(=1+2*1+2+T_setup). Clearly, the minimum cycle cannot be less than 7, i.e., T >= 7 (otherwise, R1 cannot correctly sample its feedback value). Therefore, the answers are: 1) 1+5*1+2+1=9 2) 1+5*1+2+1- T_skew = 8 3) 1+5*1+2+1-T_skew = 5, but since T >= 7, Tmin=7 4) Let T_skew = t2 – t1, then during positive skew, T_skew must be less than the minimum delay from R1 to R2 (not including Tsetup), i.e., T_skew < 6(=1+3*1+2), to ensure that R2 samples the correct value. During negative skew, T – (the absolute value of T_skew) must be greater than or equal to the maximum delay from R1 to R2, which is 9, i.e., (the absolute value of T_skew) <= t – 9. Combining this gives (9-T) ≤ T_skew < 6.
Essential FPGA Written Exam Questions
9. The clock cycle is T, the maximum register to output time of trigger D1 is T1max, and the minimum is T1min. The maximum delay of the combinational logic circuit is T2max, and the minimum is T2min. What conditions should the setup time T3 and hold time satisfy for trigger D2? (华为) Tsu < T – T1max – T2max; Tth < T1min + T2min
Essential FPGA Written Exam Questions
10. Discuss the advantages and disadvantages of static and dynamic timing simulation. (VIA 2003.11.06 Shanghai written exam question)
Static timing analysis uses exhaustive analysis methods to extract all timing paths present in the circuit, calculate the propagation delay of signals along these paths, and check whether the setup and hold times meet timing requirements. By analyzing the maximum and minimum path delays, errors that violate timing constraints can be identified. It does not require input vectors to exhaust all paths, and runs quickly with low memory usage. It can not only perform comprehensive timing functional checks on chip designs but also utilize the results of timing analysis to optimize designs. Therefore, static timing analysis has increasingly been used in the verification of digital integrated circuit designs.
Dynamic timing simulation is the usual simulation. It is impossible to generate complete test vectors to cover every path in the gate-level netlist. Therefore, in dynamic timing analysis, some timing issues that may exist on certain paths cannot be exposed;
Essential FPGA Written Exam Questions
11. Use a 2-to-1 mux and an inverter to implement XOR. (Philips – Datang written exam)
input a,b;output c;assign c=a?(~b):(b);
Essential FPGA Written Exam Questions
12. A, B, C, D, E vote, the majority obeys the minority, output is F (that is, if the number of 1s among A, B, C, D, E is greater than 0, then F outputs 1, otherwise F outputs 0), implemented with NOR gates, the number of inputs is not limited.
First draw the Karnaugh map to simplify, convert to AND-OR form, and then take the inverse twice to obtain the result.
Essential FPGA Written Exam Questions
13. What is the difference between latch and register, and why are registers used more often now? How are latches generated in behavioral level description?
Latches are level-triggered, while registers are edge-triggered. Registers operate under the same clock edge, conforming to the design philosophy of synchronous circuits, whereas latches belong to asynchronous circuit design, which often leads to difficulties in timing analysis. Inappropriate use of latches can waste a lot of chip resources.
Essential FPGA Written Exam Questions
14. Write the Verilog module for an asynchronous D flip-flop. (Yangzhi Electronics written exam)
module dff8(clk , reset, d, q);input        clk;input        reset;input  [7:0] d;output [7:0] q;reg   [7:0] q;always @ (posedge clk or posedge reset)if(reset)q <= 0;elseq <= d;endmodule
Essential FPGA Written Exam Questions
15. Use D flip-flops to implement 2x frequency division in Verilog description? (Hanwang written exam)
module divide2( clk , clk_o, reset);   input     clk , reset;   output   clk_o;   wire in;reg out ;   always @ ( posedge clk or posedge reset)if ( reset)out <= 0;elseout <= in;assign in = ~out;assign clk_o = out;     endmodule
Essential FPGA Written Exam Questions
16. A drink costs 10 cents, with coins of 5 cents and 10 cents, when the total is greater than or equal to 10 cents, the drink pops out, and any extra coins will also pop out. From this, we can divide into two states: one is 0 cents, and the other is 5 cents.When the accumulated value is 10 cents, the drink pops out, giving change of 0 cents; when the accumulated value is 15 cents, the drink pops out, giving change of 5 cents.

State transition diagram:

Essential FPGA Written Exam Questions

Code design:

Essential FPGA Written Exam Questions

Essential FPGA Written Exam Questions

Essential FPGA Written Exam Questions
17. Write a FIFO controller (including empty, full, half-full signals) using Verilog/VHDL. (Philips – Datang written exam)

FIFO stands for First In First Out memory, and FIFO controllers are widely used in digital systems as data buffers.

The clock-synchronized FIFO controller interface is shown below, with the main interface signal definitions as follows:

RST_N: Asynchronous reset signal. When RST_N is low, FULL outputs ‘0’, EMPTY outputs ‘1’, and the FIFO pointer points to 0, indicating that the FIFO is cleared;

CLK: Clock signal, output signals are synchronized with CLK;

DATAIN: Data input signal, 8-bit bus;

RD: Read valid signal, high level valid. When RD is high, at the rising edge of the clock signal CLK, DATAOUT outputs a valid 8-bit data;

WR: Write valid signal. When WR is high, at the rising edge of CLK, a valid 8-bit data is written from DATAIN to memory;

DATAOUT: Data output signal, 8-bit bus. At the rising edge of CLK, when RD is high, outputs an 8-bit data from FIFO;

FULL: Memory full flag signal. High level indicates that the data in memory has been fully written;

EMPTY: Memory empty flag signal. High level indicates that the data in memory has been read empty.

Requirement: Write an 8×16 FIFO in Verilog to complete the FIFO function, and output EMPTY valid signal when FIFO is empty. The read pointer RP should not move anymore; when FIFO is full, output FULL valid signal, and even if WR is valid, it should not write data into the memory unit (the write pointer WP should not move).

The storage unit is modeled using a two-dimensional array. Note that the address of the storage unit should be able to return to the lowest value when written to or read from the highest address.

module fifo_mem(data,clk,rstN,wrN,rdN,empty,full);inout [7:0] data;input clk,rstN,wrN,rdN;output empty,full;reg [4:0]  _cntr,rd_cntr;wire [3:0] add;ram16X8 ram(.data(data),.addr(addr),.wrN(wrN),.oe(wrN));always @(posedge clk or negedge rstN)if(!rstN) wr_cntr<=0;else if (!wrN) wr_cntr<=wr_cntr+1;always @ (posedge clk or negedge rstN) if(!rstN) rd_cntr<=0; else if(!rdN) rd_cntr<=rd_cntr+1;assign addr=wrN?rd_cntr [3:0]: wr_cntr [3:0];assign empty=(wr_cntr [3:0] == rd_cntr [3:0])&&!(wr_cntr[4]^rd_cntr[4]);assign full=(wr_cntr [3:0] ==rd_cntr [3:0])&&(wr_cntr[4]^rd_cntr[4]);endmodule

18 Design a presettable initial value 7-segment cyclic counter and a 15-segment one using your familiar design method.

module counter7(clk,rst,load,data,cout);input clk,rst,load;input [2:0] data;output reg [2:0] cout;always@(posedge clk)beginif(!rst)cout<=3’d0;else if(load)cout<=data;else if(cout>=3’d6)  cout<=3’d0;else  cout<=cout+3’d1;endendmodule

– END –

Essential FPGA Written Exam Questions

NOW take action!

Leave a Comment

×