Fix tachometer operation

Verified on Arctic Tern card
parent 496bdca5
...@@ -210,9 +210,9 @@ module simple_pwm_wishbone #( ...@@ -210,9 +210,9 @@ module simple_pwm_wishbone #(
.tach_in(tach4_in) .tach_in(tach4_in)
); );
assign status_reg1[15:8] = tach1_count; assign status_reg1[15:0] = tach1_count;
assign status_reg1[31:16] = tach2_count; assign status_reg1[31:16] = tach2_count;
assign status_reg2[15:8] = tach3_count; assign status_reg2[15:0] = tach3_count;
assign status_reg2[31:16] = tach4_count; assign status_reg2[31:16] = tach4_count;
endmodule endmodule
...@@ -236,7 +236,7 @@ module simple_pwm #( ...@@ -236,7 +236,7 @@ module simple_pwm #(
reg pwm_out_reg = 0; reg pwm_out_reg = 0;
assign pwm_out = pwm_out_reg; assign pwm_out = pwm_out_reg;
reg [PWM_CTL_BITS-1:0] tach_count_reg = 0; reg [TACH_COUNT_BITS-1:0] tach_count_reg = 0;
assign tach_count = tach_count_reg; assign tach_count = tach_count_reg;
reg [PWM_CTL_BITS-1:0] pwm_counter = 0; reg [PWM_CTL_BITS-1:0] pwm_counter = 0;
...@@ -244,8 +244,8 @@ module simple_pwm #( ...@@ -244,8 +244,8 @@ module simple_pwm #(
reg tach_in_prev = 0; reg tach_in_prev = 0;
reg tach_in_reg = 0; reg tach_in_reg = 0;
reg [15:0] pwm_clock_div_counter; reg [15:0] pwm_clock_div_counter = 0;
reg [23:0] tach_clock_div_counter; reg [31:0] tach_clock_div_counter = 0;
always @(posedge base_clock) begin always @(posedge base_clock) begin
if (pwm_clock_div_counter > ((BASE_CLOCK_FREQUENCY_KHZ / REQUIRED_PWM_FREQUENCY_KHZ) / (2 ** PWM_CTL_BITS))) begin if (pwm_clock_div_counter > ((BASE_CLOCK_FREQUENCY_KHZ / REQUIRED_PWM_FREQUENCY_KHZ) / (2 ** PWM_CTL_BITS))) begin
...@@ -263,7 +263,7 @@ module simple_pwm #( ...@@ -263,7 +263,7 @@ module simple_pwm #(
end end
always @(posedge base_clock) begin always @(posedge base_clock) begin
if (tach_clock_div_counter > (BASE_CLOCK_FREQUENCY_KHZ / TACHOMETER_SAMPLE_RATE_HZ)) begin if (tach_clock_div_counter > ((BASE_CLOCK_FREQUENCY_KHZ * 1000) / TACHOMETER_SAMPLE_RATE_HZ)) begin
tach_count_reg <= tach_counter; tach_count_reg <= tach_counter;
tach_counter <= 0; tach_counter <= 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment