Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Writing latches in verilog

HI:

here is my code:

module part4(SW,LEDR,LEDG);

input[2:0] SW;

output[2:0] LEDR;

output[0:0] LEDG;

assign LEDR = SW;

assign Clk = SW[2];

assign R = SW[1];

assign S = SW[0];

wire R_g,S_g,Qa,Qb;/*synthesis keep*/

always @ (posedge Clk);

assign R_g = Clk&R; // R&Clk

assign S_g = Clk&S; // S&Clk

assign Qa = ~(R_g|Qb);

assign Qb = ~(S_g|Qa);

assign LEDG = Qa;

endmodule​

Here are the problems :

1: wire R_g,S_g,Qa,Qb;/*synthesis keep*/

Error: Warning (10885): Verilog HDL Attribute warning at DLatch.v(11): synthesis attribute "keep" with value "1" has no object and is ignored

2: assign Qa = Qb&S_g;

assign Qb = Qa&R_g;

Error: Their value just simply cannot be assigned . The line is red in model sim

Thanks in advance .

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    1. You also cannot make a reg out of a wire. thats what the reg type is for. hence why you cannot keep it.

    2. you cannot put an assign inside an always block.