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

Subversion Repositories ssbcc

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

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

Line No. Rev Author Line
1 9 sinclairrf
//
2
// PERIPHERAL servo_motor:  @NAME@
3
//
4
generate
5
reg [@NBITS_PWM@-1:0] s__pwm_count_init = @DEFAULT_PWM@;
6
always @ (posedge i_clk)
7
  if (i_rst)
8
    s__pwm_count_init <= @DEFAULT_PWM@;
9
  else if (s_outport && (s_T == @IX_OUTPORT@))
10
    s__pwm_count_init <= @PWM_FORMULA@;
11
  else
12
    s__pwm_count_init <= s__pwm_count_init;
13
reg [@NBITS_PWM@-1:0] s__pwm_count = @DEFAULT_PWM@;
14
@SCALE_0_BEGIN@
15
@SCALE_0_ELSE@
16
reg s__tick = 1'b0;
17
reg [@NBITS_SCALE@-1:0] s__tick_cnt = @SCALE_MINUS_ONE@;
18
wire s__tick_last = (s__tick_cnt == @ONE_SCALE@);
19
always @ (posedge i_clk)
20
  if (i_rst) begin
21
    s__tick <= 1'b0;
22
    s__tick_cnt <= @SCALE_MINUS_ONE@;
23
  end else begin
24
    s__tick <= s__tick_last;
25
    if (s__tick)
26
      s__tick_cnt <= @SCALE_MINUS_ONE@;
27
    else
28
      s__tick_cnt <= s__tick_cnt - @ONE_SCALE@;
29
  end
30
@SCALE_0_END@
31
@PERIOD_BEGIN@
32
reg [@NBITS_PERIOD@-1:0] s__period = @PERIOD_MINUS_ONE@;
33
@SCALE_0_BEGIN@
34
always @ (posedge i_clk)
35
  if (i_rst) begin
36
    s__period <= @PERIOD_MINUS_ONE@;
37
    s__period_done <= 1'b0;
38
  end else begin
39
    if (s__period_done)
40
      s__period <= @PERIOD_MINUS_ONE@;
41
    else
42
      s__period <= s__period - @ONE_PERIOD@;
43
    s__period_done <= (s__period == @ONE_PERIOD@);
44
  end
45
@SCALE_0_ELSE@
46
always @ (posedge i_clk)
47
  if (i_rst) begin
48
    s__period <= @PERIOD_MINUS_ONE@;
49
    s__period_done <= 1'b0;
50
  end else begin
51
    if (s__period_done)
52
      s__period <= @PERIOD_MINUS_ONE@;
53
    else if (s__tick)
54
      s__period <= s__period - @ONE_PERIOD@;
55
    else
56
      s__period <= s__period;
57
    s__period_done <= s__tick_last && (s__period == @NBITS_PERIOD@'d0);
58
  end
59
@SCALE_0_END@
60
@PERIOD_END@
61
@SCALE_0_BEGIN@
62
always @ (posedge i_clk)
63
  if (i_rst)
64
    s__pwm_count <= @DEFAULT_PWM@;
65
  else if (@PERIOD_SIGNAL@)
66
    s__pwm_count <= s__pwm_count_init;
67
  else
68
    s__pwm_count <= s__pwm_count - @ONE_PWM@;
69
@SCALE_0_ELSE@
70
always @ (posedge i_clk)
71
  if (i_rst)
72
    s__pwm_count <= @DEFAULT_PWM@;
73
  else if (@PERIOD_SIGNAL@)
74
    s__pwm_count <= s__pwm_count_init;
75
  else if (s__tick)
76
    s__pwm_count <= s__pwm_count - @ONE_PWM@;
77
  else
78
    s__pwm_count <= s__pwm_count;
79
@SCALE_0_END@
80
reg s__outsignal = 1'b0;
81
always @ (posedge i_clk)
82
  if (i_rst)
83
    s__outsignal <= 1'b0;
84
  else if (@PERIOD_SIGNAL@)
85
    s__outsignal <= 1'b1;
86
@SCALE_0_BEGIN@
87
  else if (s__pwm_count == {(@NBITS_PWM@){1'b0}})
88
@SCALE_0_ELSE@
89
  else if (s__tick && (s__pwm_count == {(@NBITS_PWM@){1'b0}}))
90
@SCALE_0_END@
91
    s__outsignal <= 1'b0;
92
  else
93
    s__outsignal <= s__outsignal;
94
always @ (*)
95
  @OUTSIGNAL@ = @INVERT@s__outsignal;
96
endgenerate

powered by: WebSVN 2.1.0

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