Просмотр исходного кода

test(motor): close zero HOLD and physical-limit versus HOME semantics

codex 2 месяцев назад
Родитель
Сommit
286f760c65
2 измененных файлов с 22 добавлено и 1 удалено
  1. 9 1
      src/motor/motor_axis_core.v
  2. 13 0
      tests/sim/motor_engine_tb.v

+ 9 - 1
src/motor/motor_axis_core.v

@@ -177,9 +177,17 @@ module motor_axis_core #(
     if(selected_moving)dir_out[scan_axis]<=selected_dir;
     due[scan_axis]<=next_us+{32'd0,(selected_moving ? selected_load[95:64] : selected_load[63:32])}+
         ((selected_moving && selected_dir!=dir_out[scan_axis]) ? DIR_SETUP_TICKS : 0);
+    if(!selected_moving && selected_load[63:32]==0 && !selected_load[18]) begin
+     state[scan_axis]<=IDLE;done_pulse[scan_axis]<=1;r_reason[scan_axis]<=9;r_done_tag[scan_axis]<=selected_load[111:96];
+     r_done_exec[scan_axis]<=0;r_last[scan_axis]<=0;r_done_pos[scan_axis]<=pos_next;r_done_total[scan_axis]<=total_next;r_done_time[scan_axis]<=event_clock_us;
+    end
    end else if(state[scan_axis]==ARMED && (start_pending[scan_axis] || start_armed[scan_axis])) begin
     state[scan_axis]<=RUN;start_pending[scan_axis]<=0;
     due[scan_axis]<=(start_armed[scan_axis] ? next_us : start_time[scan_axis])+{32'd0,(r_mode[scan_axis]==4 ? r_remaining[scan_axis] : r_half_us[scan_axis])}+DIR_SETUP_TICKS;
+    if(r_mode[scan_axis]==4 && r_remaining[scan_axis]==0) begin
+     state[scan_axis]<=IDLE;done_pulse[scan_axis]<=1;r_reason[scan_axis]<=9;r_done_tag[scan_axis]<=r_tag[scan_axis];
+     r_done_exec[scan_axis]<=0;r_last[scan_axis]<=0;r_done_pos[scan_axis]<=pos_next;r_done_total[scan_axis]<=total_next;r_done_time[scan_axis]<=event_clock_us;
+    end
    end else if(edge_pending[scan_axis]) begin
     scheduled_step[scan_axis]<=step_out[scan_axis];due[scan_axis]<=edge_time[scan_axis]+{32'd0,r_half_us[scan_axis]};
     if(!step_out[scan_axis] && !r_unlimited[scan_axis] && remaining_next==0) begin
@@ -209,7 +217,7 @@ module motor_axis_core #(
      limit_records_pending[i]<=i==scan_axis ? 4'd1 : limit_records_pending[i]+1'b1;
      pending_event_zero[i]<=lower_pending[i]!=0;
     end
-    if(limit_lower[i]&&limit_upper[i])r_both[i]<=1;
+    if(limit_lower[i]&&limit_upper[i] && !(lower_q[i]&&upper_q[i]))r_both[i]<=1;
     fast_reason=0;
     if(state[i]==RUN && r_mode[i]!=4 && (r_dir_upper[i]?limit_upper[i]:limit_lower[i]))fast_reason=(limit_lower[i]&&limit_upper[i])?7:(r_dir_upper[i]?3:2);
     else if(state[i]!=IDLE && abort_req[i])fast_reason=4;

+ 13 - 0
tests/sim/motor_engine_tb.v

@@ -291,6 +291,19 @@ module motor_engine_tb;
         event_before=ev_count;
         ctl(1,16'b111,0,0);repeat(100) @(posedge clk);
         check(ev_count==event_before+3,"all simultaneous abort events retained");
+        // Physical edge while idle, then repeated HOME at an already-held
+        // lower switch: one real edge event; HOME completion is separate.
+        event_before=ev_count;limit_lower_raw[2]=1;repeat(60)@(posedge clk);
+        check(ev_count==event_before+1 && dut.ax_lhits[2]==1,"idle physical limit recorded once");
+        event_before=ev_count;ctl(6,16'b100,0,0);repeat(60)@(posedge clk);
+        check(ev_count==event_before+1 && dut.ax_lhits[2]==1,"held HOME adds completion not physical hit");
+        event_before=ev_count;ctl(6,16'b100,0,0);repeat(60)@(posedge clk);
+        check(ev_count==event_before+1 && dut.ax_lhits[2]==1,"repeated held HOME does not forge edge");
+        ctl(5,16'b100,0,0);repeat(20)@(posedge clk);
+        check(!dut.ax_llat[2] && !dut.ax_active[2],"clear latch does not restart held limit");
+        // Zero HOLD completes once through the normal queue, without STEP.
+        send_seg(0,4,0,0,0,16'hA5,0);submit(1);repeat(60)@(posedge clk);
+        check(!dut.ax_active[0] && dut.ax_last_reason[0]==9,"zero HOLD completes");
         $display("motor_engine_tb PASS");
         $finish;
     end