Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me with designing a modular exponential unit for a thesis

Status
Not open for further replies.

moharaza

Junior Member level 3
Joined
Mar 26, 2006
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,483
dsp_48

hi,

I need some urgent help, I am trying to design a modular exponential unit for my project which is in deep crisis.
I have designed one, which is not working as expected when it is downloaded on the board. But, The simulation is giving perfect result.

i am not getting any errors, just few warnings--
something like--
"cannot use dsp_48 technology"

please take a look and help me out if possible.

notes--

1.I am using XUPV2P board.
2.post contains 2 verilog files
3.interleavedMultiplier unit is working fine when it is downloaded on the board.
4. I am getting "out=0" from the board when i download ModExp.v



Maruf
Code:
//Exponential calculator

`timescale 1ns / 1ps

/*

                for i=bits;i>0;i--

                                {

                                                if(e[i]==1)result=(result*base)%M;
                                                result=(result*result)%M;

                                }

*/

 

module ModExp(clk,reset,start,base,e,M,out,done);

parameter bits=3,Count_Max=3'd4,Count_bits=2;

    input clk;

    input reset;

    input start;

    input [bits:0]base;

    input [bits:0]e;

    input [bits:0]M;

                 output reg [bits:0]out;

                 output reg done=0;

                 

parameter IDLE=3'b000, COUNTER = 3'b001, CHECK_FOR_ONE = 3'b010, SQUARE=3'b011, MULT_ONE=3'b100,MULT_TWO=3'b101,BUFFER_A=3'b110,BUFFER_B=3'b111;

                 

                 reg [bits:0]temp;

                 reg flag;

                 reg [2:0]state=0;

                 reg [Count_bits:0]count;

                 

                 /*-------------------------Interleaved Multiplier Declaration-------------*/

                 

                 reg [bits:0]opA=0;

                 reg [bits:0]opB=0;

                 reg [bits:0]Mod;

                 

                 wire doneM;

                 wire [bits:0]result;

                 

                 InterleavedMult ah(clk,reset,start,opA,opB,Mod,result,doneM);

   

               reg [bits:0]tempBase=0;

                 reg [bits:0]tempE=0;

                 reg [bits:0]tempM=0;

                 reg tempDone=0;

                 reg control;

                 

                 

                 always @(posedge clk)

                                if((tempBase !=base)||(tempE !=e)||(tempM !=M)||(tempDone!=done))

                                                begin

                                                                if(flag)flag=~done;

                                                                else flag=1'b1;

                                                                

                                                                tempBase<=base;

                                                                tempE<=e;

                                                                tempM<=M;

                                                                

                                                                if(done) tempDone<=done;

                                                                else tempDone<=0;

                                                end

                

                always @(posedge clk)

                                if(reset)

                                                state<=IDLE;

                                else if(start && flag)

                                           case(state)
                                                      IDLE:
                                                                begin
                                                                    control<=0;
                                                                    state<=CHECK_FOR_ONE;
                                                                    count=Count_Max;
                                                                    temp=1;
                                                                    out=0;
                                                                end

                                                        CHECK_FOR_ONE:
                                                              begin
                                                                    if(e[count-1])
                                                                       begin
                                                                          if((opA!=base) || (opB!=temp))
                                                                                 begin
                                                                                     opA=base;
                                                                                     opB=temp;
                                                                                      Mod=M;
                                                                                      control<=0;
                                                                                      state<=MULT_ONE;
                                                                       end
                                                                  else state<=SQUARE;
                                                                         end
                                                                   else 
                                                                               state<=SQUARE;
                                                           end
                                                          MULT_ONE:
                                                                  begin
                                                                       if(doneM && control)
                                                                             begin
                                                                                  temp=result;
                                                                                   control<=0;
                                                                                   state<=SQUARE;
                                                                             end
                                                                         if(!doneM)
                                                                                control<=1;
                                                                 end
                                                      SQUARE:
                                                           begin
                                                               if(count!=1)
                                                                      begin
                                                   if(((opA!=temp) || (opB!=temp)) && (temp>1))
                                                            begin
                                                               opA=temp;
                                                               opB=temp;
                                                                Mod=M;
                                                               control<=0;
                                                                 state<=MULT_TWO;
                                                            end
                                                    else
                                                        begin
                                                            count=count-1;
                                                            done=0;
                                                             state<=CHECK_FOR_ONE;
                                                        end
                                                   end
                                                else
                                                      begin
                                                         out=temp;
                                                          done=1'b1;
                                                          state<=IDLE;
                                                      end
                                            end
                                       MULT_TWO:
                                                begin
                                                     if(doneM && control)
                                                                 begin
                                                                     temp=result;
                                                                      control<=0;
                                                                      count=count-1;
                                                                        done=0;
                                                                      state<=CHECK_FOR_ONE;
                                                  end
                                                      if(!doneM)control<=1;
                                              end
                                  default:state<=IDLE;
                     endcase

endmodule


/////////////////////////////////////////////////////// Multiplier///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

`timescale 1ns / 1ps

 module InterleavedMult(clk, reset, start, opA, opB, M, out, done);

    

                 parameter bits=3,Count_Max=3'd4,Count_bits=2;

                 

                 input clk;

    input reset;

    input start;

    input [bits:0]opA;

    input [bits:0]opB;

    input [bits:0]M;

    output reg [bits:0]out;

    output reg done=0;

                 

                 parameter IDLE=2'b00, COUNTER = 2'b01, CHECK_FOR_ONE = 2'b10, CHECK_FOR_GRT_M=2'b11;

                 

                 reg [bits+2:0]temp;

                 reg flag;

                 reg [1:0]state;

                 reg [Count_bits:0]count;

                 

                 reg [bits:0]tempOpA=0;

                 reg [bits:0]tempOpB=0;

                 reg [bits:0]tempM=0;

                 reg [bits+1:0]temp_M_2=9'd0;

                 reg tempDone=1'b0;

                                

                always @(posedge clk)

                                if((tempOpA!=opA) || (tempOpB!=opB) || (tempM!=M)||(tempDone!=done))

                                                begin

                                                                if(flag)flag=~done;

                                                                else flag=1'b1;

                                                                

                                                                tempOpA<=opA;

                                                                tempOpB<=opB;

                                                                tempM<=M;

                                                                

                                                                if(done)

                                                                                tempDone<=done;

                                                                else tempDone<=0;

                                                end

                

     always @ (posedge clk)
              begin
                     if(reset)
                          state<=IDLE;
                               else if(start && flag)
                                        case(state)
                                            IDLE:
                                                   begin
                                                       temp=0;
                                                       count=Count_Max;
                                                        state<=COUNTER;
                                                   end

                                                  COUNTER:
                                                      begin
                                                           if(count>0)
                                                                 begin
                                                                       temp={temp[bits+1:0],1'b0};
                                                                       state<=CHECK_FOR_ONE;
                                                                  end
                                                            else 
                                                               begin
                                                                   done=1'b1;
                                                                   out=temp;
                                                                   state<=IDLE;
                                                               end
                                                        end
                                    CHECK_FOR_ONE:
                                                begin
                                                     if(opA[count-1])
                                                           temp=temp+opB;
                                                           done=0;
                                                            temp_M_2={M[bits:0],1'b0};
                                                            state<=CHECK_FOR_GRT_M;
                                                     end
                                   CHECK_FOR_GRT_M:
                                              begin
                                                    if(temp>=temp_M_2)
                                                             temp=temp-temp_M_2;
                                                   else if (temp>=M)
                                                              temp=temp-M;
                                                     count=count-1;
                                                     state<=COUNTER;

                                              end
                                 default:state<=IDLE;
                         endcase
            end

endmodule
 

thesis in crisis

What is the module suppose to do? Show us your test bench.

It's difficult to read due to wild indenting.

In synchronous sections, use non-blocking '<=' assignments instead of blocking '=' assignments.
 

Re: thesis in crisis

The "cannot use dsp_48 technology" warning is normal - the Virtex2Pro doesn't have that kind of cells. Apparently this warning is false, should be suppressed by the Xilinx tools, and this will be fixed in a future release.

Is this the only warning you get while synthesizing? Perhaps others might lead to a cue.
 

Re: thesis in crisis

Please provide a test bench that shows the intended interface signal timing and numerical values (including expected result) for a case, that fails in synthesized design.
 

Re: thesis in crisis

here i have indented the code
Code:
//Exponential calculator

`timescale 1ns / 1ps

/*

                for i=bits;i>0;i--

                                {

                                                if(e[i]==1)result=(result*base)%M;
                                                result=(result*result)%M;

                                }

*/

 

module ModExp(clk,reset,start,base,e,M,out,done);

parameter bits=3,Count_Max=3'd4,Count_bits=2;

    input clk;

    input reset;

    input start;

    input [bits:0]base;

    input [bits:0]e;

    input [bits:0]M;

                 output reg [bits:0]out;

                 output reg done=0;

                 

parameter IDLE=3'b000, COUNTER = 3'b001, CHECK_FOR_ONE = 3'b010, SQUARE=3'b011, MULT_ONE=3'b100,MULT_TWO=3'b101,BUFFER_A=3'b110,BUFFER_B=3'b111;

                 

                 reg [bits:0]temp;

                 reg flag;

                 reg [2:0]state=0;

                 reg [Count_bits:0]count;

                 

                 /*-------------------------Interleaved Multiplier Declaration-------------*/

                 

                 reg [bits:0]opA=0;

                 reg [bits:0]opB=0;

                 reg [bits:0]Mod;

                 

                 wire doneM;

                 wire [bits:0]result;

                 

                 InterleavedMult ah(clk,reset,start,opA,opB,Mod,result,doneM);

   

               reg [bits:0]tempBase=0;

                 reg [bits:0]tempE=0;

                 reg [bits:0]tempM=0;

                 reg tempDone=0;

                 reg control;

                 

                 

                 always @(posedge clk)

                                if((tempBase !=base)||(tempE !=e)||(tempM !=M)||(tempDone!=done))

                                                begin

                                                                if(flag)flag=~done;

                                                                else flag=1'b1;

                                                               

                                                                tempBase<=base;

                                                                tempE<=e;

                                                                tempM<=M;

                                                               

                                                                if(done) tempDone<=done;

                                                                else tempDone<=0;

                                                end

               

                always @(posedge clk)

                                if(reset)

                                                state<=IDLE;

                                else if(start && flag)

                                           case(state)
                                                      IDLE:
                                                                begin
                                                                    control<=0;
                                                                    state<=CHECK_FOR_ONE;
                                                                    count=Count_Max;
                                                                    temp=1;
                                                                    out=0;
                                                                end

                                                        CHECK_FOR_ONE:
                                                              begin
                                                                    if(e[count-1])
                                                                       begin
                                                                          if((opA!=base) || (opB!=temp))
                                                                                 begin
                                                                                     opA=base;
                                                                                     opB=temp;
                                                                                      Mod=M;
                                                                                      control<=0;
                                                                                      state<=MULT_ONE;
                                                                       end
                                                                  else state<=SQUARE;
                                                                         end
                                                                   else
                                                                               state<=SQUARE;
                                                           end
                                                          MULT_ONE:
                                                                  begin
                                                                       if(doneM && control)
                                                                             begin
                                                                                  temp=result;
                                                                                   control<=0;
                                                                                   state<=SQUARE;
                                                                             end
                                                                         if(!doneM)
                                                                                control<=1;
                                                                 end
                                                      SQUARE:
                                                           begin
                                                               if(count!=1)
                                                                      begin
                                                   if(((opA!=temp) || (opB!=temp)) && (temp>1))
                                                            begin
                                                               opA=temp;
                                                               opB=temp;
                                                                Mod=M;
                                                               control<=0;
                                                                 state<=MULT_TWO;
                                                            end
                                                    else
                                                        begin
                                                            count=count-1;
                                                            done=0;
                                                             state<=CHECK_FOR_ONE;
                                                        end
                                                   end
                                                else
                                                      begin
                                                         out=temp;
                                                          done=1'b1;
                                                          state<=IDLE;
                                                      end
                                            end
                                       MULT_TWO:
                                                begin
                                                     if(doneM && control)
                                                                 begin
                                                                     temp=result;
                                                                      control<=0;
                                                                      count=count-1;
                                                                        done=0;
                                                                      state<=CHECK_FOR_ONE;
                                                  end
                                                      if(!doneM)control<=1;
                                              end
                                  default:state<=IDLE;
                     endcase

endmodule


/////////////////////////////////////////////////////// Multiplier///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

`timescale 1ns / 1ps

 module InterleavedMult(clk, reset, start, opA, opB, M, out, done);

   

                 parameter bits=3,Count_Max=3'd4,Count_bits=2;

                 

                 input clk;

    input reset;

    input start;

    input [bits:0]opA;

    input [bits:0]opB;

    input [bits:0]M;

    output reg [bits:0]out;

    output reg done=0;

                 

                 parameter IDLE=2'b00, COUNTER = 2'b01, CHECK_FOR_ONE = 2'b10, CHECK_FOR_GRT_M=2'b11;

                 

                 reg [bits+2:0]temp;

                 reg flag;

                 reg [1:0]state;

                 reg [Count_bits:0]count;

                 

                 reg [bits:0]tempOpA=0;

                 reg [bits:0]tempOpB=0;

                 reg [bits:0]tempM=0;

                 reg [bits+1:0]temp_M_2=9'd0;

                 reg tempDone=1'b0;

                               

                always @(posedge clk)

                                if((tempOpA!=opA) || (tempOpB!=opB) || (tempM!=M)||(tempDone!=done))

                                                begin

                                                                if(flag)flag=~done;

                                                                else flag=1'b1;

                                                               

                                                                tempOpA<=opA;

                                                                tempOpB<=opB;

                                                                tempM<=M;

                                                               

                                                                if(done)

                                                                                tempDone<=done;

                                                                else tempDone<=0;

                                                end

               

     always @ (posedge clk)
              begin
                     if(reset)
                          state<=IDLE;
                               else if(start && flag)
                                        case(state)
                                            IDLE:
                                                   begin
                                                       temp=0;
                                                       count=Count_Max;
                                                        state<=COUNTER;
                                                   end

                                                  COUNTER:
                                                      begin
                                                           if(count>0)
                                                                 begin
                                                                       temp={temp[bits+1:0],1'b0};
                                                                       state<=CHECK_FOR_ONE;
                                                                  end
                                                            else
                                                               begin
                                                                   done=1'b1;
                                                                   out=temp;
                                                                   state<=IDLE;
                                                               end
                                                        end
                                    CHECK_FOR_ONE:
                                                begin
                                                     if(opA[count-1])
                                                           temp=temp+opB;
                                                           done=0;
                                                            temp_M_2={M[bits:0],1'b0};
                                                            state<=CHECK_FOR_GRT_M;
                                                     end
                                   CHECK_FOR_GRT_M:
                                              begin
                                                    if(temp>=temp_M_2)
                                                             temp=temp-temp_M_2;
                                                   else if (temp>=M)
                                                              temp=temp-M;
                                                     count=count-1;
                                                     state<=COUNTER;

                                              end
                                 default:state<=IDLE;
                         endcase
            end

endmodule
 

Re: thesis in crisis

To my opinion, the design is operating correctly. How did you check it?
 

Re: thesis in crisis

I have attached verilog files, testbench and design summery.

The design is operating perfectly when simulated. Problem is-- it is not functioning as expected when downloaded on the board.

Multiplier unit works well, not the exponential unit..



//from the board, "out=0" and "done=1" ??
 

Re: thesis in crisis

You didn't tell how you tested in hardware and what kind of error could been seen.

How did you try to locate the problem, e. g. usage of Chipscope? Did you also perform a post-synthesis simulation?

P.S.: The other warning (Xst:1293 - FF/Latch <temp_M_2_0> has a constant value of 0 in block <InterleavedMult>) is correct, cause temp_M_2[0] is constantly 0 by design.
 

Re: thesis in crisis

I used very trivial technique to varify,
LEDs and Switches,

i used only 4 bits and manual inputs through pinouts and switches,

from post synthesis simulation report i get the following info--

INFO:NetListWriters:633 - The generated Verilog netlist contains Xilinx UNISIM
simulation primitives and has to be used with UNISIM simulation library for
correct compilation and simulation.


The output from LEDs is always zero, and done bit is set to 1,it is not changing with operands, and i have tested each inputs individually, they are ok.

may be i should start over, try differently and try simple arithmetic with multiplication output first.

any suggestion?
 

Re: thesis in crisis

Well, the output is also always zero in simulation, except for one cycle after the rising edge of done output - whyever this may be. You need some synchronous edge detection like the following construct to catch the output:

Code:
always @ (posedge clk)
 begin
  done_v <= done;
  if (done && ~done_v)
   outlatch <= out;
 end

Alternatively, you can drop the out<=0 assignment in IDLE state, which has no understandable purpose to my opinion.
 

Re: thesis in crisis

hi,

out !=0 always, please check the following testbench,
after done=1, and out=result, the value of done and out will switch back to 'zero', when there is new operand on M,e or base.


Code:
`timescale 1ns/1ps

module testa_tb_0;
    reg clk = 1'b0;
    reg reset = 1'b0;
    reg start = 1'b0;
    reg [7:0] base = 8'b00000000;
    reg [7:0] e = 8'b00000000;
    reg [7:0] M = 8'b00000000;
    wire [7:0] out;
    wire done;

    parameter PERIOD = 20;
    parameter real DUTY_CYCLE = 0.5;
    parameter OFFSET = 10;

    initial    // Clock process for clk
    begin
        #OFFSET;
        forever
        begin
            clk = 1'b0;
            #(PERIOD-(PERIOD*DUTY_CYCLE)) clk = 1'b1;
            #(PERIOD*DUTY_CYCLE);
        end
    end

    ModExp UUT (
        .clk(clk),
        .reset(reset),
        .start(start),
        .base(base),
        .e(e),
        .M(M),
        .out(out),
        .done(done));

    initial begin
        // -------------  Current Time:  18ns
         #18		 
        start=1;
        M = 8'd251;
        base = 8'd196;
        e = 8'd125;
		  
        #8000
        start = 1'b1;
        M = 8'd197;
        base = 8'd157;
        e = 8'd99;
		  // -------------------------------------
    end

endmodule

Added after 2 minutes:

hi,

out !=0 always, please check the following testbench, ( with clk period=20ns, i got result at 6900ns)

after done=1, and out="result", the value of done and out will switch back to 'zero', when there is new operand on M,e or base.


Code:
`timescale 1ns/1ps

module testa_tb_0;
    reg clk = 1'b0;
    reg reset = 1'b0;
    reg start = 1'b0;
    reg [7:0] base = 8'b00000000;
    reg [7:0] e = 8'b00000000;
    reg [7:0] M = 8'b00000000;
    wire [7:0] out;
    wire done;

    parameter PERIOD = 20;
    parameter real DUTY_CYCLE = 0.5;
    parameter OFFSET = 10;

    initial    // Clock process for clk
    begin
        #OFFSET;
        forever
        begin
            clk = 1'b0;
            #(PERIOD-(PERIOD*DUTY_CYCLE)) clk = 1'b1;
            #(PERIOD*DUTY_CYCLE);
        end
    end

    ModExp UUT (
        .clk(clk),
        .reset(reset),
        .start(start),
        .base(base),
        .e(e),
        .M(M),
        .out(out),
        .done(done));

    initial begin
        // -------------  Current Time:  18ns
         #18		 
        start=1;
        M = 8'd251;
        base = 8'd196;
        e = 8'd125;
		  
        #8000
        start = 1'b1;
        M = 8'd197;
        base = 8'd157;
        e = 8'd99;
		  // -------------------------------------
    end

endmodule
 

Re: thesis in crisis

The files in Crisis.rar seem to simulate fine for me, although I don't know what the correct output should be.

I tried synthesizing in ISE 10.1i, and the post-route simulation looks pretty similar to the behavioral simulation.
However, I had to change the test bench delay from #18 to #5 to avoid an input setup violation during post-route synthesis.
Your results may vary depending on your synthesis constraints.
 

Re: thesis in crisis

out !=0 always, please check the following testbench
I don't understand what you want to say here. I referred to the design you posted
previously, not to any other design, you may have used another day. It shows the
said behaviour. But as the problem isn't with the testbench, the question is: Which
design was actually used in your hardware test? There is no need to discuss the
testbenches any more. I also confirmed their correct operation.
 

Re: thesis in crisis

hi,

the design in crisis.rar and the one without intending on the post is almost same.
(in rar i tried with non blocking statements), but in hardware test, results were same for both sadly.

by out!=0 on my previous post, i wanted to defend that the design is working properly in simulation.

"Well, the output is also always zero in simulation, except for one cycle after the rising edge of done output - whyever this may be.
 

Re: thesis in crisis

I'll describe the situation from my view. The simulated design could work in a hardware test, when these conditions are met:

1. The output must be latched in an appropriate way, to persist longer than one clock cycle and be e. g. viewable at a LED display.

2. The design must be driven by a real hardware clock signal, not a #delay construct usable in a testbench. Also a hardware reset may be necessary.
 

    moharaza

    Points: 2
    Helpful Answer Positive Rating
thesis in crisis

Thank you very much FvM, Now, everything is working fine with the inclusion of following codes--

always @ (posedge clk)
begin
done_v <= done;
if (done && ~done_v)
outlatch <= out;
end

CASE DISMISS!!

Thank you

Thank you Edaboard
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top