data/full_repos/permissive/505451992/Pendulum.v
data/verilator_xmls/bb376cb4-f724-4af7-807f-35ed60441d12.xml
module Pendulum(
  input clk,
  input reset,
  input [9:0] Position,
  input[1:0] State,
  output Drive,
  output Load,
  output Drive_Led,
  output Load_Led
  
    );
    


    reg Drive_R;
    reg Load_R;
    reg Drive_Led_R;
    reg Load_Led_R;
    
    assign Drive = Drive_R;
    assign Load = Load_R;
    assign Drive_Led = Drive_Led_R;
    assign Load_Led = Load_Led_R;
    
    
    reg signed [10:0] Direction;
    
    
    
  
    reg[9:0] Last_P;
     

    
    localparam Braking =2'b00;
    localparam Short =2'b01;
    localparam Open = 2'b10;
    localparam Driving =  2'b11;
    
    always@(posedge clk or posedge reset ) begin
     if(reset) begin

      Last_P <= 0;
      end
      else if (Position!=Last_P) begin
      Direction <= Position - Last_P;
      Last_P <= Position;
      end
      
    
    
    
    end
    
    
    
    
    
    
    
    always@* begin
        case(State)
            Braking:begin


                if (Position >= 512 && Position <= 612 && Direction[10]) begin
                    Drive_R = 0;
                    Load_R = 0;
                    Drive_Led_R = 1;
                    Load_Led_R = 0; 
                end    
                else begin   
                    Drive_R = 1;
                    Load_R = 0;
                    Drive_Led_R = 0;
                    Load_Led_R = 0;  
                end          
            
             end
            
            Short:begin
                Drive_R = 0;
                Load_R = 1;
                Drive_Led_R = 0;
                Load_Led_R = 1;
            end   
             
            Open:begin
                Drive_R = 0; 
                Load_R = 0;
                Drive_Led_R = 0;
                Load_Led_R = 0;
            end
            
            Driving:begin
               if (Position < 512 && Position >= 412 && Direction[10]) begin

                       Drive_R = 0;
                       Load_R = 0;
                       Drive_Led_R = 1;
                       Load_Led_R = 0; 
                end
                
                else begin   
                     Drive_R = 1;
                     Load_R = 0;
                     Drive_Led_R = 0;
                     Load_Led_R = 0;  
                 end   
                
            end  
            
            endcase
     end          
endmodule
module Pendulum(
  input clk,
  input reset,
  input [9:0] Position,
  input[1:0] State,
  output Drive,
  output Load,
  output Drive_Led,
  output Load_Led
  
    );

    


    reg Drive_R;
    reg Load_R;
    reg Drive_Led_R;
    reg Load_Led_R;
    
    assign Drive = Drive_R;
    assign Load = Load_R;
    assign Drive_Led = Drive_Led_R;
    assign Load_Led = Load_Led_R;
    
    
    reg signed [10:0] Direction;
    
    
    
  
    reg[9:0] Last_P;
     

    
    localparam Braking =2'b00;
    localparam Short =2'b01;
    localparam Open = 2'b10;
    localparam Driving =  2'b11;
    
    always@(posedge clk or posedge reset ) begin
     if(reset) begin

      Last_P <= 0;
      end
      else if (Position!=Last_P) begin
      Direction <= Position - Last_P;
      Last_P <= Position;
      end
      
    
    
    
    end
    
    
    
    
    
    
    
    always@* begin
        case(State)
            Braking:begin


                if (Position >= 512 && Position <= 612 && Direction[10]) begin
                    Drive_R = 0;
                    Load_R = 0;
                    Drive_Led_R = 1;
                    Load_Led_R = 0; 
                end    
                else begin   
                    Drive_R = 1;
                    Load_R = 0;
                    Drive_Led_R = 0;
                    Load_Led_R = 0;  
                end          
            
             end
            
            Short:begin
                Drive_R = 0;
                Load_R = 1;
                Drive_Led_R = 0;
                Load_Led_R = 1;
            end   
             
            Open:begin
                Drive_R = 0; 
                Load_R = 0;
                Drive_Led_R = 0;
                Load_Led_R = 0;
            end
            
            Driving:begin
               if (Position < 512 && Position >= 412 && Direction[10]) begin

                       Drive_R = 0;
                       Load_R = 0;
                       Drive_Led_R = 1;
                       Load_Led_R = 0; 
                end
                
                else begin   
                     Drive_R = 1;
                     Load_R = 0;
                     Drive_Led_R = 0;
                     Load_Led_R = 0;  
                 end   
                
            end  
            
            endcase
     end          
endmodule