EmbDev.net

Forum: FPGA, VHDL & Verilog Misunderstood in Verilog basics?


von Lapo (Company: Radioteknos) (lapo)


Rate this post
useful
not useful
Hi,
I'm quite new to Verilog but I've some code working but from time to 
time I got some uncompresible behaviour and I think I lake some knoledge 
in Verilog.

Here is a quick example of a more complex project, it works with div2 
module (/* go */) and don't with div5 module (/* no go */). Go / no go 
means I got ssoc signal on LED2 debug output or not.
1
module test_div_1(
2
       /* iCEstick clk (12MHz) */
3
       input  clkin,
4
5
       /* 10MHz ref_in */
6
       input  ref_in,
7
8
       /* iCEstick leds */
9
       output LED_GREEN, 
10
       output LED0, output LED1, output LED2, output LED3,
11
12
          /* ADC (DIV) spi */
13
       );   
14
15
   
16
   SB_PLL40_CORE #(
17
       .FEEDBACK_PATH("SIMPLE"),
18
       /* $ icepll -i 12 -o 30 */
19
       /* clkin=12MHz */
20
       .DIVR(0),    /* DIVR =  0  (div 1) */
21
       .DIVF(79),      /* DIVF = 79 (x80) */
22
       .DIVQ(5),    /* DIVQ =  5 (div 6) */
23
       /* main_clk=30MHz */
24
       .FILTER_RANGE(3'b001)  /* FILTER_RANGE = 1 */
25
       ) uut (
26
        .LOCK(LED_GREEN),
27
        .RESETB(1'b1),
28
        .BYPASS(1'b0),
29
        .REFERENCECLK(clkin),
30
        .PLLOUTCORE(main_clk)
31
        );
32
   
33
   
34
   wire      main_clk;
35
   wire      ref_in;
36
   wire            soc;         
37
   reg        ssoc;
38
   wire       spi_m_clk;
39
   
40
   /* soc generator (125kHz) */
41
   div80 d80_1(ref_in, soc);
42
      
43
   /* cs and clk generation */
44
45
/* -----\/----- EXCLUDED -----\/-----
46
   div2 div_spi_clk(ref_in, spi_m_clk); /-* go *-/
47
 -----/\----- EXCLUDED -----/\----- */
48
   div5 div_spi_clk(ref_in, spi_m_clk); /* no go */
49
50
   always @ (negedge spi_m_clk)
51
     ssoc<=soc;
52
   
53
   
54
   /* TODO: remove (debug) */
55
   assign LED0=spi_m_clk;
56
   assign LED1=soc;
57
   assign LED2=ssoc;
58
   assign LED3=1'b0;   
59
endmodule /* # test_div_1 end # */
60
61
module div80(input in,
62
        output out);
63
64
   wire        in;
65
   reg          out;
66
   reg [6:0]        c;
67
68
   initial
69
     begin
70
  c=7'b0000000;
71
     end
72
   
73
   always@(posedge in)
74
     begin
75
  if(c>=79)
76
    begin
77
       c<=0;
78
       out<=1'b1;
79
    end
80
  else
81
    begin
82
       out<=1'b0;
83
       c<=c+1;
84
    end
85
     end
86
   
87
endmodule /* # div80 end # */
88
89
90
module div5(input in,
91
        output out);
92
93
   wire        in;
94
   reg         out;
95
   reg [2:0]        c;
96
   
97
   initial
98
     begin
99
  c=3'b000;
100
     end
101
   
102
   always@(posedge in)
103
     begin
104
  if(c>=4)
105
    begin
106
       c<=0;
107
       out<=1'b1;
108
    end
109
  else
110
    begin
111
       out<=1'b0;
112
       c<=c+1;
113
    end
114
     end
115
116
endmodule /* # div5 end # */
117
118
module div2(input in,
119
      output out);
120
121
   wire            in, out;
122
   reg             c;
123
124
   always@(posedge in)
125
     begin
126
  c<=!c;
127
  
128
     end
129
   
130
   assign out=c;
131
   
132
endmodule /* # div2 end # */


div80 module output works fine...

Am I wrong in something about wire/reg? Or what ever?

If it matter I'm using ice40stick and icestorm toolchain (yosys, nextpnr 
and icepack).

Could you help me?
Thanks!

Lapo

von Rick D. (rickdangerus)


Rate this post
useful
not useful
Lapo wrote:
> Go / no go
> means I got ssoc signal on LED2 debug output or not.
LED debugging may work with microcontrollers, but not with FPGA.
Learn to use a simulator for debugging your designs.

von Lapo (Company: Radioteknos) (lapo)


Rate this post
useful
not useful
Rick D. wrote:
> LED debugging may work with microcontrollers, but not with FPGA.
> Learn to use a simulator for debugging your designs.

You are right. I should learn to use simulator and debugger in a lot
of situation.
In any case, the code was working but my logic design was wrong.

Thank you!

Lapo

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.