EmbDev.net

Forum: FPGA, VHDL & Verilog Modelsim simulation OK but FPGA implementation incorrect!!


von Omar (Guest)


Attached files:

Rate this post
useful
not useful
I am designing a divide by 4/ divide by 8 module. Modelsim simulation 
runs as expected. However upon programming with Altera I get a funky 
output on d_out but clk_out is running as expected.

I have attached the project file which includes everything.

von dude (Guest)


Rate this post
useful
not useful
I dont like to open .rar. maybe single files ok?

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Omar wrote:
> I am designing a divide by 4/ divide by 8 module.
That's a few lines of code. Why do you post them in a rar?

von Omar R. (ojay77)


Rate this post
useful
not useful
1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
5
entity decimator2 is
6
  port (clk, sync, d_in: IN std_logic; 
7
        clk_out, d_out: OUT std_logic);
8
end decimator2;
9
10
architecture FSM of decimator2 is
11
type state is (s0, s1, s2, s3, s4, s51, s61, s71, s81, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16);
12
signal c_state: state := s0;
13
signal temp: std_logic;
14
15
begin
16
17
d_out <= temp;
18
19
process (clk)
20
begin
21
if (clk = '1' and clk'event) then
22
  case c_state is
23
    when s0 => if (sync = '1') then
24
        c_state <= s1;
25
         else
26
        c_state <= s0;
27
         end if;
28
    when s1 => if (sync = '1') then
29
        c_state <= s2;
30
         else
31
        c_state <= s0;
32
         end if;
33
    when s2 => if (sync = '1') then
34
        c_state <= s3;
35
         else 
36
        c_state <= s0;
37
         end if;
38
    when s3 => if (sync = '1') then
39
        c_state <= s4;
40
         else
41
        c_state <= s0;
42
         end if;
43
    when s4 => if (sync = '1') then
44
        c_state <= s5;
45
         else
46
        c_state <= s51;
47
         end if;
48
    when s51 => if (sync = '1') then 
49
        c_state <= s1;
50
          else
51
        c_state <= s61;
52
          end if;
53
    when s61 => if (sync = '1') then
54
        c_state <= s1;
55
          else
56
        c_state <= s71;
57
          end if;
58
    when s71 => if (sync = '1') then
59
        c_state <= s1;
60
          else
61
        c_state <= s81;
62
          end if;
63
    when s81 => if (sync = '1') then
64
        c_state <= s1;
65
          else
66
        c_state <= s51;
67
          end if;
68
    when s5 => if (sync = '1') then
69
        c_state <= s6;
70
         else
71
        c_state <= s0;
72
         end if;
73
    when s6 => if (sync = '1') then
74
        c_state <= s7;
75
         else
76
        c_state <= s0;
77
         end if;
78
    when s7 => if (sync = '1') then
79
        c_state <= s8;
80
         else
81
        c_state <= s0;
82
         end if;
83
    when s8 => if (sync = '0') then
84
        c_state <= s9;
85
         else
86
        c_state <= s1;
87
         end if;
88
    when s9 => if (sync = '0') then
89
        c_state <= s10;
90
         else
91
        c_state <= s1;
92
         end if;
93
    when s10 => if (sync = '0') then
94
        c_state <= s11;
95
         else
96
        c_state <= s1;
97
         end if;
98
    when s11 => if (sync = '0') then
99
        c_state <= s12;
100
         else
101
        c_state <= s1;
102
         end if;
103
    when s12 => if (sync = '0') then
104
        c_state <= s13;
105
         else
106
        c_state <= s1;
107
         end if;
108
    when s13 => if (sync = '0') then
109
        c_state <= s14;
110
         else
111
        c_state <= s1;
112
         end if;
113
    when s14 => if (sync = '0') then
114
        c_state <= s15;
115
         else
116
        c_state <= s1;
117
         end if;
118
    when s15 => if (sync = '0') then
119
        c_state <= s16;
120
         else
121
        c_state <= s1;
122
         end if;
123
    when s16 => if (sync = '0') then
124
        c_state <= s9;
125
         else
126
        c_state <= s1;
127
         end if;
128
    when others => c_state <= s0;
129
  end case;
130
end if;
131
end process;
132
133
process (c_state)
134
begin
135
case c_state is
136
  when s0 => temp <= '0'; clk_out <= '0';
137
  when s1 => temp <= '0'; clk_out <= '0';
138
  when s2 => temp <= '0'; clk_out <= '0';
139
  when s3 => temp <= '0'; clk_out <= '0';
140
  when s4 => temp <= '0'; clk_out <= '0';
141
  when s51 => temp <= d_in; clk_out <= '0';
142
  when s61 => temp <= temp; clk_out <= '1';
143
  when s71 => temp <= temp; clk_out <= '1';
144
  when s81 => temp <= temp; clk_out <= '0';
145
  when s5 => temp <= '0'; clk_out <= '0';
146
  when s6 => temp <= '0'; clk_out <= '0';
147
  when s7 => temp <= '0'; clk_out <= '0';
148
  when s8 => temp <= '0'; clk_out <= '0';
149
  when s9 => temp <= d_in; clk_out <= '0';    --beginning of decimate by 8
150
  when s10 => temp <= temp; clk_out <= '0';
151
  when s11 => temp <= temp; clk_out <= '1';
152
  when s12 => temp <= temp; clk_out <= '1';
153
  when s13 => temp <= temp; clk_out <= '1';
154
  when s14 => temp <= temp; clk_out <= '1';
155
  when s15 => temp <= temp; clk_out <= '0';
156
  when s16 => temp <= temp; clk_out <= '0';
157
end case;
158
end process;
159
end FSM;

I added a .rar file because I wanted to present all the project files, 
not just the source code.

von Omar (Guest)


Rate this post
useful
not useful
Bump!

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Omar R. wrote:
> the source code.
What's the intention of that code? What should it do? And what does it 
do instead?

Omar R. wrote:
>   port (clk, sync, d_in: IN std_logic
You must read about asynchronous inputs and about synchronizing inputs.
To keep things short: never ever use a async input in a FSM.

von Omar R. (ojay77)


Rate this post
useful
not useful
The intention is for it to divide the input data and input clock (d_iun, 
clk) by 4 or by 8 based on the length of the sync signal (if it is 4 
cycles long then divide by 4, if 8 then divide by 8).

d_out should be basically a sampled and held d_in (held for 4 or 8 
cycles). Currently it is not being held correctly. However, clk_out is 
correct.

von daniel__m (Guest)


Rate this post
useful
not useful
Omar R. wrote:
> process (c_state)

rethink the sensitivity list of your second process. the simulation my 
be wrong.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Indeed the synthesizer should report something about an incomplete 
sensitivity list...

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.