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

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [core/] [9x8/] [peripherals/] [PWM_8bit.v] - Blame information for rev 6

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

Line No. Rev Author Line
1 2 sinclairrf
//
2
// PERIPHERAL PWM_8bit:  @NAME@
3
//
4
localparam L__COUNT = @COUNT@-1;
5
localparam L__COUNT_NBITS = $clog2(L__COUNT+1);
6
generate
7
// generate the ticks for the PWM
8
reg [L__COUNT_NBITS-1:0] s__tick_counter = L__COUNT[0+:L__COUNT_NBITS];
9
reg s__tick_counter_is_zero = 1'b0;
10
always @ (posedge i_clk)
11
  if (i_rst) begin
12
    s__tick_counter <= L__COUNT[0+:L__COUNT_NBITS];
13
    s__tick_counter_is_zero <= 1'b0;
14
  end else if (s__tick_counter_is_zero) begin
15
    s__tick_counter <= L__COUNT[0+:L__COUNT_NBITS];
16
    s__tick_counter_is_zero <= 1'b0;
17
  end else begin
18
    s__tick_counter <= s__tick_counter - { {(L__COUNT_NBITS-1){1'b0}}, 1'b1 };
19
    s__tick_counter_is_zero <= (s__tick_counter == { {(L__COUNT_NBITS-1){1'b0}}, 1'b1 });
20
  end
21
// run the 1 to 255 PWM counter
22
reg [7:0] s__pwm_counter = 8'd1;
23
always @ (posedge i_clk)
24
  if (i_rst)
25
    s__pwm_counter <= 8'd1;
26
  else if (s__tick_counter_is_zero)
27
    if (s__pwm_counter == 8'hFF)
28
      s__pwm_counter <= 8'd1;
29
    else
30
      s__pwm_counter <= s__pwm_counter + 8'd1;
31
  else
32
    s__pwm_counter <= s__pwm_counter;
33
// Use a loop to instantiate each channel
34
reg [@INSTANCES@-1:0] s__raw = {(@INSTANCES@){@OFF@}};
35
genvar ix;
36
for (ix=0; ix<@INSTANCES@; ix=ix+1) begin : gen__channel
37
  reg [7:0] s__threshold = 8'd0;
38
  /* verilator lint_off WIDTH */
39
  wire [7:0] s__ix = ix; // Xilinx ISE can't bit-slice a genvar
40
  /* verilator lint_on WIDTH */
41
  always @ (posedge i_clk)
42
    if (i_rst)
43
      s__threshold <= 8'd0;
44
    else if (s_outport && (s_T == (8'd@IX_OUTPORT_0@ + s__ix)))
45
      s__threshold <= s_N;
46
    else
47
      s__threshold <= s__threshold;
48
  wire [7:0] s__threshold_use;
49
  if (@NORUNT@) begin : gen__norunt
50
    reg [7:0] s__threshold_use_tmp = 8'd0;
51
    always @ (posedge i_clk)
52
      if (i_rst)
53
        s__threshold_use_tmp <= 8'd0;
54
      else if (s__tick_counter_is_zero && (s__pwm_counter == 8'd255))
55
        s__threshold_use_tmp <= s__threshold;
56
      else
57
        s__threshold_use_tmp <= s__threshold_use_tmp;
58
    assign s__threshold_use = s__threshold_use_tmp;
59
  end else begin : gen__not_norunt
60
    assign s__threshold_use = s__threshold;
61
  end
62
  always @ (posedge i_clk)
63
    if (i_rst)
64
      s__raw[ix] <= @OFF@;
65
    else
66
      s__raw[ix] <= (s__pwm_counter <= s__threshold_use) ? @ON@ : @OFF@;
67
end
68
// needed since 1-bit wide signals don't have indices.
69
always @ (s__raw)
70
  @NAME@ = s__raw;
71
endgenerate

powered by: WebSVN 2.1.0

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