📄 percent.tdf
字号:
%
******************************************************************************
* This function is given as a free design, and may be freely distributed *
* and modified, as long as this message remains intact. *
* *
* Written by Steven Groom (steven.groom@arrow.co.nz) *
* Revision 1.0 *
******************************************************************************
%
include "fn_divide";
include "fn_multiply";
parameters
(
lpm_width=16
);
subdesign percent
(
clock : input; -- global clock input
go_calc : input; -- give a '1' on this signal for 1 period
-- to start the state machine
dataa[lpm_width-1..0] : input; -- qty counted
datab[lpm_width-1..0] : input; -- total qty
result[7..0] : output; -- percentage (1 -> 100)
no_calc : output; -- this gives a '1' for 1 period to signal
-- the end of the function
)
variable
process : machine with states (idle,calc);
fn_div : fn_divide with (lpm_width=lpm_width+7);
fn_mult : fn_multiply with (lpm_width=lpm_width);
begin
fn_div.clock=global(clock);
fn_mult.clock=clock;
process.clk=clock;
fn_mult.dataa[]=dataa[];
fn_mult.datab[]=100;
fn_div.divnd[]=fn_mult.result[lpm_width+6..0];
fn_div.divsr[]=(0,datab[]);
fn_div.go_calc=fn_mult.no_calc;
result[]=fn_div.quot[7..0];
case process is
when idle =>
fn_mult.go_calc=go_calc;
if go_calc then -- wait for start semaphore
process=calc;
end if;
when calc =>
if fn_div.no_calc then -- wait for stop semaphore
no_calc=vcc;
process=idle;
end if;
end case;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -