OpenCores
URL https://opencores.org/ocsvn/sbd_sqrt_fp/sbd_sqrt_fp/trunk

Subversion Repositories sbd_sqrt_fp

[/] [sbd_sqrt_fp/] [tags/] [start/] [sbd_sqrt_fp_state_mach.v] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sbdesign
/****************************************************************************
2
sbd_sqrt_fp_state_mach
3
 
4
- state machine for sbd_sqrt_fp32
5
 
6
Copyright (C) 2005 Samuel Brown
7
sam.brown@sbdesign.org
8
 
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2.1 of the License, or (at your option) any later version.
13
 
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
Lesser General Public License for more details.
18
 
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
 
23
****************************************************************************/
24
 
25
 
26
module sbd_sqrt_fp_state_mach ( CLK,VAL_IN,INIT,LSR,ENR,ENL,EN_D,DLEFT,VAL_OUT );
27
 
28
parameter termval = 25;
29
 
30
input CLK;
31
input VAL_IN;
32
output wire INIT;
33
output wire LSR;
34
output wire ENR;
35
output wire ENL;
36
output wire EN_D;
37
output wire DLEFT;
38
output wire VAL_OUT;
39
 
40
wire  begPulse;
41
reg   terminate;
42
reg   [6:0] currentState;
43
wire  [6:0] nextState;
44
reg   [5:0] countValue;
45
 
46
reg val_state_reg;
47
wire active;
48
 
49
initial
50
begin
51
   currentState = 0;
52
   countValue = 0;
53
   val_state_reg = 0;
54
end
55
 
56
assign INIT = currentState[6];
57
assign LSR = currentState[5];
58
assign ENR = currentState[4];
59
assign ENL = currentState[3];
60
assign EN_D = currentState[2];
61
assign DLEFT = currentState[1];
62
 
63
assign nextState[6] = begPulse & ~terminate;
64
assign nextState[5] = currentState[4];  // 31 or 25
65
assign nextState[4] = currentState[6] | (currentState[5] & ~terminate);
66
assign nextState[3] = currentState[6] | (currentState[5] & ~terminate);
67
assign nextState[2] = currentState[4] | (currentState[5] & ~terminate);
68
assign nextState[1] = currentState[5] & ~terminate;
69
assign nextState[0] = currentState[6] | (currentState[5] & ~terminate);
70
 
71
always @ (posedge CLK)
72
begin:sqrtcount
73
   if(begPulse) countValue <= 0;
74
   else if(currentState[0]) countValue <= countValue + 1;
75
end
76
 
77
always @ (posedge CLK)
78
begin:stateReg
79
   currentState <= nextState;
80
end
81
 
82
always @ (countValue, begPulse)
83
begin:termassign
84
   if((countValue == termval) && ~begPulse) terminate = 1;
85
   else terminate = 0;
86
end
87
 
88
//assign terminate = (countValue[4] & countValue[3] & ~countValue[2] & ~countValue[1] & countValue[0]) & ~begPulse; 
89
 
90
//------------------- val in and out states ---------------------
91
 
92
always @ (posedge CLK)
93
begin:val_state_register
94
   val_state_reg <= active & ~VAL_OUT;
95
end
96
 
97
assign begPulse = VAL_IN & ~val_state_reg;
98
assign active = begPulse | val_state_reg;
99
assign VAL_OUT = terminate & active;
100
 
101
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.