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

Subversion Repositories ssbcc

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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