// -------------------------------------------------------------
// 
// File Name: hdl_prj\hdlsrc\controllerPeripheralHdlAdi\controllerHdl\controllerHdl_Set_Acceleration.v
// Created: 2014-09-08 14:12:04
// 
// Generated by MATLAB 8.2 and HDL Coder 3.3
// 
// -------------------------------------------------------------


// -------------------------------------------------------------
// 
// Module: controllerHdl_Set_Acceleration
// Source Path: controllerHdl/Field_Oriented_Control/Open_Loop_Control/Generate_Position_And_Voltage_Ramp/Rotor_Acceleration_To_Velocity/Set_Acceleration
// Hierarchy Level: 6
// 
// -------------------------------------------------------------

`timescale 1 ns / 1 ns

module controllerHdl_Set_Acceleration
          (
           CLK_IN,
           reset,
           enb_1_2000_0,
           v_target,
           v_current,
           a
          );


  input   CLK_IN;
  input   reset;
  input   enb_1_2000_0;
  input   signed [17:0] v_target;  // sfix18_En8
  input   signed [31:0] v_current;  // sfix32_En22
  output  signed [17:0] a;  // sfix18_En10


  wire signed [31:0] Relational_Operator_1_cast;  // sfix32_En22
  wire Relational_Operator_relop1;
  wire current_less_than_target;
  wire current_less_than_target_1;
  wire current_greater_than_target;
  wire target_has_changed;
  wire Latch_out1;
  reg  Delay1_out1;
  wire Latch_out1_1;
  wire negative_direction;
  wire switch_compare_1;
  wire signed [17:0] Acceleration1_out1;  // sfix18_En10
  wire signed [18:0] Neg_cast;  // sfix19_En10
  wire signed [18:0] Neg_cast_1;  // sfix19_En10
  wire signed [35:0] Neg_cast_2;  // sfix36_En27
  wire signed [17:0] Neg_out1;  // sfix18_En10
  wire current_greater_than_target_1;
  wire stop_positive_acceleration;
  wire current_less_than_target_2;
  wire stop_negative_acceleration;
  wire stop_positive_acceleration_1;
  wire stop_accelerating;
  wire signed [17:0] positive_accleration;  // sfix18_En10
  wire signed [17:0] accleration;  // sfix18_En10
  wire signed [17:0] Constant_out1;  // sfix18_En10
  wire signed [17:0] Switch_Stop_out1;  // sfix18_En10

  // Set Acceleration


  // <S29>/Relational Operator
  assign Relational_Operator_1_cast = {v_target, 14'b00000000000000};
  assign Relational_Operator_relop1 = (Relational_Operator_1_cast > v_current ? 1'b1 :
              1'b0);



  assign current_less_than_target = Relational_Operator_relop1;

  // <S29>/NOT2
  assign current_less_than_target_1 =  ~ current_less_than_target;



  assign current_greater_than_target = current_less_than_target_1;

  // <S29>/Detect_Change
  controllerHdl_Detect_Change   u_Detect_Change   (.CLK_IN(CLK_IN),
                                                   .reset(reset),
                                                   .enb_1_2000_0(enb_1_2000_0),
                                                   .x(v_target),  // sfix18_En8
                                                   .y(target_has_changed)
                                                   );

  // <S29>/Delay1
  always @(posedge CLK_IN)
    begin : Delay1_process
      if (reset == 1'b1) begin
        Delay1_out1 <= 1'b0;
      end
      else if (enb_1_2000_0) begin
        Delay1_out1 <= Latch_out1;
      end
    end



  // <S29>/Latch
  // 
  // <S29>/Signal Specification
  assign Latch_out1 = (target_has_changed == 1'b0 ? Delay1_out1 :
              current_less_than_target);



  // <S29>/NOT3
  assign Latch_out1_1 =  ~ Latch_out1;



  assign negative_direction = Latch_out1_1;

  assign switch_compare_1 = (Latch_out1 > 1'b0 ? 1'b1 :
              1'b0);



  // <S29>/Acceleration1
  assign Acceleration1_out1 = 18'sb001010000000000000;



  // <S29>/Neg
  assign Neg_cast = Acceleration1_out1;
  assign Neg_cast_1 =  - (Neg_cast);
  assign Neg_cast_2 = {Neg_cast_1, 17'b00000000000000000};
  assign Neg_out1 = Neg_cast_2[34:17];



  // <S29>/AND_Pos
  assign current_greater_than_target_1 = current_greater_than_target & Latch_out1;



  assign stop_positive_acceleration = current_greater_than_target_1;

  // <S29>/AND_Neg
  assign current_less_than_target_2 = current_less_than_target & negative_direction;



  assign stop_negative_acceleration = current_less_than_target_2;

  // <S29>/OR_SAT1
  assign stop_positive_acceleration_1 = stop_positive_acceleration | stop_negative_acceleration;



  assign stop_accelerating = stop_positive_acceleration_1;

  // <S29>/Acceleration
  assign positive_accleration = 18'sb001010000000000000;



  // <S29>/Switch_Dir
  assign accleration = (switch_compare_1 == 1'b0 ? Neg_out1 :
              positive_accleration);



  // <S29>/Constant
  assign Constant_out1 = 18'sb000000000000000000;



  // <S29>/Switch_Stop
  assign Switch_Stop_out1 = (stop_accelerating == 1'b0 ? accleration :
              Constant_out1);



  assign a = Switch_Stop_out1;

endmodule  // controllerHdl_Set_Acceleration

