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

Subversion Repositories ssbcc

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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