KingMoshe
Member level 2
- Joined
- Aug 10, 2021
- Messages
- 48
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 362
4524 isn't the rounded value....NUM = 15/(15000*0.000000221) = 4524.886878 = 4524(rounded)
at the end I want to save to register the number 4524.
Hithat simplifies to:
(15*10^9/221 )/count
= 67873303/count
//////////////////////////////////////////////////////////////////////////////////
// Company: SolarEdge
//////////////////////////////////////////////////////////////////////////////////
// Company: SolarEdge
// Engineer: Moshe Novak
//
// Last Update: 20/12/2021
// Module Name: TACHOMETER (RPM DETECTOR)
// Project Name: Jupiter 48 BU
// Revision: 01
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
//`timescale 1ns / 1ps
module TACH(
RST, //input from MNGR to reset
clk, // clock input
IN_TACH, //intput from internal fan
OUT_RPM_NORM //output reister
);
//INPUTS-----------------------------------------------------------------------------------------------------
input wire RST;
input wire clk;
input wire IN_TACH; //intput from internal fan
//OUTPUTS----------------------------------------------------------------------------------------------------
output reg [15:0] OUT_RPM_NORM;
//LOCAL------------------------------------------------------------------------------------------------------
reg [15:0] rpm_counter;
reg [7:0] state;
parameter K = 67720090; // K = 15/TCLK = 15/221.5nano
// OUT_RPM_NORM = 1/(TCLK * OUT_RPM)
integer OUT_RPM;
localparam STATE_IDLE = 0;
localparam STATE_COUNT = 1;
localparam STATE_SAVE = 2;
localparam STATE_NORM = 4;
localparam STATE_STOP = 3;
always @ (posedge clk or posedge RST)
begin
if (RST)
begin
rpm_counter <= 16'b0;
state <= STATE_IDLE;
end
else begin
case (state)
STATE_IDLE: begin
if (~IN_TACH) state <= STATE_COUNT;
else state <= STATE_IDLE;
end
STATE_COUNT: begin
rpm_counter <= rpm_counter + 1'b1;
if (~IN_TACH) state <= STATE_COUNT;
else state <= STATE_SAVE;
end
STATE_SAVE: begin
OUT_RPM <= K/rpm_counter;
state <= STATE_NORM;
end
STATE_NORM: begin
OUT_RPM_NORM <= OUT_RPM;
state <= STATE_STOP;
end
STATE_STOP: begin
state <= STATE_IDLE;
rpm_counter <= 16'b0;
end
endcase
end
end
endmodule
The problem is the division operation 27bit_constant/16bit_variable. Instead of a parallel divider you should implement a serial divider like https://opencores.org/projects/serial_div_uuthat is happen just after I add this lines to my design:
reg [15:0] rpm_counter;
parameter K = 67720090; // K = 15/TCLK = 15/221.5nano
integer OUT_RPM;
OUT_RPM <= K/rpm_counter;
What is the problem?
Right, I answered the question (now post #6) before I realized that it was a duplicate of a previous post. Both threads have been merged later.Back in post #4 I said to use non-restoring division, which is a serial division algorithm.
The link in post #9, at a glance, looks like a non-restoring divider.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?