EmbDev.net

Forum: FPGA, VHDL & Verilog Puls generator


von Gerhard K. (gerhardkreuzer)


Rate this post
useful
not useful
Hi,
I have a multi stage process and each step need some time. I want to 
create some sequencer which is able to generate positive edges at 
certain intervals and at the end /beginning of the cycle reset this 
signals.
Not that complicated, I thought, but I fail totally.

If I do it in hardware:
Counter, 11 bit wide, increments at each clock cycle, some comparators, 
comparing the actual count against a constant and if equal, set the 
output for one clock cycle, ==> get my positive edge.

If I do it in Verilog:
1
   
2
always @ (negedge clk)
3
    begin
4
      if ( reset )
5
        reg_step = 3'd0;
6
        else
7
        if ( reg_step < 8'd240 || reg_sel != 3'd7 ) reg_step <= ( reg_step == 8'd240 ) ? 8'd0 : reg_step + 8'd1;
8
    end  
9
      
10
  // Generate stage clocks and incremet wave index
11
  always @ (posedge clk)
12
    if ( reset )
13
      begin
14
        reg_sel      = 3'd7;
15
        reg_accu_clk  =    0;
16
        reg_lut_clk    =    0;
17
        reg_mix_clk    =    0;  
18
      end
19
    else
20
    /*
21
      case ( reg_step )
22
        8'd2:
23
          begin
24
            reg_sel      = reg_sel + 3'd1;
25
            reg_accu_clk  = 0;
26
            reg_lut_clk    = 0;
27
            reg_mix_clk    = 0;  
28
          end
29
        8'd10:
30
          reg_accu_clk <= 1;
31
        8'd20:
32
          reg_lut_clk   <= 1;          
33
        8'd200:                          // 100 .. fails, 150 works, 150-20 = 130 * 2.5ns = 325 ns for the 12 bit sin_lut
34
          reg_mix_clk  <= 1;
35
      endcase  
36
    */
37
    
38
    begin
39
      if ( reg_step == 8'd2 ) 
40
        begin
41
          reg_sel      = reg_sel + 3'd1;
42
          reg_accu_clk  = 0;
43
          reg_lut_clk    = 0;
44
          reg_mix_clk    = 0;  
45
        end
46
        
47
      if ( reg_step == 8'd10 )  reg_accu_clk  <= 1;
48
      
49
      if ( reg_step == 8'd20 )  reg_lut_clk  <= 1;
50
      
51
      if ( reg_step == 8'd200 ) reg_mix_clk  <= 1;
52
    end

I tried two options.
In the simulation, everything is fine.
In real nothing works.

I use the RTL viewer and it was funny to see what the compiler thought 
that I want to do.

Can some body help me and tell me, how I can implement such a simple 
sequencer in Verilog or should I better start drawing a schematic using 
primitives in my Quartus Prime?

What is the target:
At negedge, the counter advances/resets. At the posedge (the counter 
value is stable I guess ...) the counter value is compared with some 
constants and if there is one found to be equal, the output is 1, 0 
otherwise.

I get posedges at certain poits in time (relative to the start), 
synchronized with the posedge of my clock.

Sorry about code formatting ..

With best regards

Gerhard

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.