在 always_ff @ 中交换 2 个参数

Swapping 2 parameters in always_ff @

我的代码有问题。

我正在尝试在同一时钟的 Xspeed 和 Yspeed 之间切换,而 if 语句为真。

我遇到错误:

cant resolve multiple constant drivers for net

constant drivers at module_name

几个 if 语句显示相同的错误。

int Xspeed, topLeftX_FixedPoint; // local parameters 
int Yspeed, topLeftY_FixedPoint;



//////////--------------------------------------------------------------------------------------------------------------=
//  calculation 0f Y Axis speed using gravity or colision

always_ff@(posedge clk or negedge resetN)
begin
    if(!resetN) begin 
        Yspeed  <= INITIAL_Y_SPEED;
        topLeftY_FixedPoint <= INITIAL_Y * FIXED_POINT_MULTIPLIER;
    end 
    else begin
    // colision Calcultaion 
            
        //hit bit map has one bit per edge:  Left-Top-Right-Bottom
      if ((collision && HitEdgeCode [2] == 1 && HitEdgeCode[1]==1)) begin // hit top border of brick  
                if (Yspeed < 0 && Xspeed > 0) begin // while moving up and moving right
                        Yspeed <= Xspeed ;
                        Xspeed <= Yspeed ;  // negative move left 
                end
            end

完整代码:

// (c) Technion IIT, Department of Electrical Engineering 2021 
//-- Alex Grinshpun Apr 2017
//-- Dudy Nov 13 2017
// SystemVerilog version Alex Grinshpun May 2018
// coding convention dudy December 2018
// updaed Eyal Lev Feb 2021


module  pokadoor_moveCollision  (   
 
                    input   logic   clk,
                    input   logic   resetN,
                    input   logic   startOfFrame,  // short pulse every start of frame 30Hz 
                    input   logic   Y_direction,  //change the direction in Y to up  
                    input   logic   toggleX,    //toggle the X direction 
                    input logic collision,  //collision if smiley hits an object
                    input   logic   [3:0] HitEdgeCode, //one bit per edge 

                    output   logic signed   [10:0]  topLeftX, // output the top left corner 
                    output   logic signed   [10:0]  topLeftY  // can be negative , if the object is partliy outside 
                    
);


// a module used to generate the  ball trajectory.  

parameter int INITIAL_X = 320;
parameter int INITIAL_Y = 240;
parameter int INITIAL_X_SPEED = 60;
parameter int INITIAL_Y_SPEED = 150;
parameter int MAX_Y_SPEED = 230;
const int  Y_ACCEL = -1;

const int   FIXED_POINT_MULTIPLIER  =   64;
// FIXED_POINT_MULTIPLIER is used to enable working with integers in high resolution so that 
// we do all calculations with topLeftX_FixedPoint to get a resolution of 1/64 pixel in calcuatuions,
// we devide at the end by FIXED_POINT_MULTIPLIER which must be 2^n, to return to the initial proportions
const int   x_FRAME_SIZE    =   639 * FIXED_POINT_MULTIPLIER; // note it must be 2^n 
const int   y_FRAME_SIZE    =   479 * FIXED_POINT_MULTIPLIER;
const int   bracketOffset = 30;
const int   OBJECT_WIDTH_X = 64;

int Xspeed, topLeftX_FixedPoint; // local parameters 
int temp;
int Yspeed, topLeftY_FixedPoint;



//////////--------------------------------------------------------------------------------------------------------------=
//  calculation 0f Y Axis speed using gravity or colision

always_ff@(posedge clk or negedge resetN)
begin
    if(!resetN) begin 
        Yspeed  <= INITIAL_Y_SPEED;
        topLeftY_FixedPoint <= INITIAL_Y * FIXED_POINT_MULTIPLIER;
    end 
    else begin
    // colision Calcultaion 
            
        //hit bit map has one bit per edge:  Left-Top-Right-Bottom
      if ((collision && HitEdgeCode [2] == 1 && HitEdgeCode[1]==1)) begin // hit top border of brick  
                if (Yspeed < 0 && Xspeed > 0) begin // while moving up and moving right
                        Yspeed <= Xspeed ;
                        Xspeed <= Yspeed ;  // negative move left 
                end
            end
        if ((collision && HitEdgeCode [2] == 1 && HitEdgeCode[3]==1)) begin // hit top border of brick  
                if (Yspeed < 0 && Xspeed < 0) begin // while moving up and moving left
                        Yspeed <= -Xspeed ;
                        Xspeed <= -Yspeed ;  // negative move left 
                end
            end
        if ((collision && HitEdgeCode [2] == 1 && HitEdgeCode[3]==0 && HitEdgeCode[1]==0)) begin  // hit top border of brick  
                    if (Yspeed < 0) begin// while moving up
                         Yspeed <= -Yspeed ; 
                    end
        end

        
            ////
            
        if ((collision && HitEdgeCode [0] == 1 && HitEdgeCode[1]==1)) begin// || (collision && HitEdgeCode [1] == 1 ))   hit bottom border of brick  
                if (Yspeed > 0  && Xspeed > 0) begin//  while moving down and moving right
                        Yspeed <= -Xspeed ;
                        Xspeed <= -Yspeed ;
                end
        end
        if ((collision && HitEdgeCode [0] == 1 && HitEdgeCode[3]==1)) begin// || (collision && HitEdgeCode [1] == 1 ))   hit bottom border of brick  
                if (Yspeed > 0  && Xspeed < 0) begin//  while moving down and moving left
                        Yspeed <= Xspeed ;
                        Xspeed <= Yspeed ;
                end
        end
      if ((collision && HitEdgeCode [0] == 1 && HitEdgeCode[3]==0 && HitEdgeCode[1]==0 )) begin// || (collision && HitEdgeCode [1] == 1 ))   hit bottom border of brick  
                if (Yspeed > 0 ) begin//  while moving down
                        Yspeed <= -Yspeed ; 
                end
        end
        // perform  position and speed integral only 30 times per second 
        
        if (startOfFrame == 1'b1) begin 
        
                topLeftY_FixedPoint  <= topLeftY_FixedPoint + Yspeed; // position interpolation 
                
                if (Yspeed < MAX_Y_SPEED ) //  limit the spped while going down 
                        Yspeed <= Yspeed  - Y_ACCEL ; // deAccelerate : slow the speed down every clock tick 
        
                                
                if (Y_direction) begin // button was pushed to go upwards 
                        if (Yspeed > 0 ) // while moving down
                                Yspeed <= -Yspeed  ;  // change speed to go up 
                end ; 


        end
    end
end 

//////////--------------------------------------------------------------------------------------------------------------=
//  calculation of X Axis speed using and position calculate regarding X_direction key or colision

always_ff@(posedge clk or negedge resetN)
begin
    if(!resetN)
    begin
        Xspeed  <= INITIAL_X_SPEED;
        topLeftX_FixedPoint <= INITIAL_X * FIXED_POINT_MULTIPLIER;
    end
    else begin
    
                
    //  an edge input is tested here as it is a very short instance   
    //if (toggleX)  
    
                //Xspeed <= -Xspeed; 
                
    // collisions with the sides            
                if (collision && HitEdgeCode [3] == 1 && HitEdgeCode[0] ==0 && HitEdgeCode[2]==0)  begin
                    if (Xspeed < 0 ) // while moving left
                            Xspeed <= -Xspeed ; // positive move right 
                end
            
                if (collision && HitEdgeCode [1] == 1 && HitEdgeCode[0] ==0 && HitEdgeCode[2]==0 ) begin  // hit right border of brick  
                    if (Xspeed > 0 ) //  while moving right
                            Xspeed <= -Xspeed  ;  // negative move left    
                end
           
            
        if (startOfFrame == 1'b1 )//&& Yspeed != 0) 
    
                        topLeftX_FixedPoint  <= topLeftX_FixedPoint + Xspeed;
            
                    
    end
end

//get a better (64 times) resolution using integer   
assign  topLeftX = topLeftX_FixedPoint / FIXED_POINT_MULTIPLIER ;   // note it must be 2^n 
assign  topLeftY = topLeftY_FixedPoint / FIXED_POINT_MULTIPLIER ;    


endmodule

错误:

Error (10028): Can't resolve multiple constant drivers for net "Xspeed[31]" at pokadoor_moveCollision.sv(139) Error (10029): Constant driver at pokadoor_moveCollision.sv(62) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[30]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[29]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[28]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[27]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[26]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[25]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[24]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[23]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[22]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[21]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[20]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[19]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[18]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[17]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[16]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[15]" at pokadoor_moveCollision.sv(139) Error (10028): Can't resolve multiple constant drivers for net "Xspeed[14]" at pokadoor_moveCollision.sv(139) Error (12152): Can't elaborate user hierarchy "Pokadoor_Block_bdf:inst14|pokadoor_moveCollision:inst" Error: Quartus Prime Analysis & Elaboration was unsuccessful. 20 errors, 15 warnings Error: Peak virtual memory: 4797 megabytes Error: Processing ended: Thu Apr 14 14:26:35 2022 Error: Elapsed time: 00:00:07 Error: Total CPU time (on all processors): 00:00:16

这些错误消息不是很具体。您可以从其他模拟器获得更多有用的消息,例如 edaplayground(Cadence 和 Synopsys)上的模拟器。

问题是您不能分配给来自不同 always_ff 块的相同信号。例如,您的代码从两个 always_ff 块分配给 Xspeed

参考 IEEE Std 1800-2017,第 9.2.2.4 节顺序逻辑always_ff程序

Variables on the left-hand side of assignments within an always_ff procedure, including variables from the contents of a called function, shall not be written to by any other process.

您必须重组您的代码,以便对 Xspeed 的所有赋值都在同一个 always_ff 块中完成。