Forum Discussion

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

multiple driver error during simulation

Hi

I am doing a project and am stuck in the synthesis part in Quartus.

The code was successfully compiled using icarus verilog software.But while compiling the code in Quartus , I get some error messages.

The code is as follows with its description:

/*

Whenever positive edge of switch occurs , I need to take the incoming 8 bits (serial inputs on a single pin) and after that I

have to discard all the bits, until the next posedge of switch. These bits are coming from a parallel in serial out register.

These bits are stored in a reg called c and i is an integer which keeps the count.

*/

module test(si,po,clk,switch,flag);

input si,clk,switch;

output reg [7:0] po;

reg [7:0] c,d;

output reg flag;

reg count;

//reg flag;

integer j,i;

initial i=0;

initial flag=0;

initial count=0;

always@(posedge clk)

begin

if (flag==1)

begin

c[i]=si;

i=i+1;

if(i==8)

begin

//count<=1;

//po<=c;

po<=(c[7:4]*10)+c[3:0];

i=0;

flag<=0;

end

end

end

always@(posedge switch)

begin

flag<=1;

end

endmodule

The error messges are as follows:

Error: Can't elaborate top-level user hierarchy

Error (10029): Constant driver at test.v(16)

Error (10028): Can't resolve multiple constant drivers for net "flag" at test.v(38)

Could anyone help in rectifying the mistake?

17 Replies

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

    The counter is used to move the current input bit to the coorect bit index of output. Thats why I say output(count) <= input i.e.:

    output(0) <= input bit when count = 0

    output(1) <= input bit when count = 1 ...etc.

    so count must go up at speed of incoming serial bits.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ok well trying out some suggestions, I am here with the final code

    module test1(si,po,clk,switch,flag);

    input si,clk,switch;

    output reg [7:0] po;

    reg [7:0] c,d;

    output reg flag;

    reg check;

    reg count;

    //reg flag;

    integer j,i;

    initial i=0;

    initial flag=0;

    initial count=0;

    always@(posedge clk)

    begin

    if(switch==0)

    check=1;

    if(switch==1 & check==1)

    begin

    check<=0;

    flag<=1;

    end

    if (flag==1)

    begin

    c[i]=si;

    i=i+1;

    ///end

    if(i==8)

    begin

    po<=(c[7:4]*10)+c[3:0];

    i=0;

    flag<=0;

    end

    end

    end

    endmodule

    Can someone suggest how to optimise this code . I am using a CPLD board which says it requires 94 macrocells for this code but it has got only 64.:)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    aside from resource issue, I think you need a bit more thought on the issue of counting. you need to count 0 ~7 and then freeze on zero until next switch edge.

    One way is this:

    if switch = '1' ...

    count <= 1;

    elsif flag = '1' then

    count <= count + 1;

    end if;

    flag <= '1' when count > 0 else '0';
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    To avoid the multiplier you can use shift and addition for 10 i.e. multiply by 8 using 3 bit shift then multiply by 2 using one bit shift then add products

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

    Thank You Kaz for the help.

    I am still short of 13 macrocells and also I would like to extend this code for 16 bits instead of 8 bits.

    Any concrete solution?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I haven't done verilog for ages. I believe your integer (i ) may imply 32 bits in hardware. You only need 3 bits so try constraining that e.g. by using reg.