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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [vdsm8.vhd] - Blame information for rev 221

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

Line No. Rev Author Line
1 219 jshamlet
-- Copyright (c)2018, 2020 Jeremy Seth Henry
2 218 jshamlet
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 220 jshamlet
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 218 jshamlet
--
24
-- VHDL Units :  vdsm8
25
-- Description:  8-bit variable delta-sigma modulator single-bit DAC
26 219 jshamlet
--
27
-- Revision History
28
-- Author          Date     Change
29
------------------ -------- ---------------------------------------------------
30
-- Seth Henry      04/25/18 Initial design
31
-- Seth Henry      04/14/20 Code cleanup and revision section added
32 218 jshamlet
 
33
library ieee;
34
use ieee.std_logic_1164.all;
35
use ieee.std_logic_unsigned.all;
36
use ieee.std_logic_arith.all;
37
 
38
entity vdsm8 is
39
generic(
40
  Reset_Level           : std_logic := '1';
41
  -- Do not adjust alone! DELTA constants must be
42
  --  changed as well.
43
  DAC_Width             : integer := 8
44
);
45
port(
46
  Clock                 : in  std_logic;
47
  Reset                 : in  std_logic;
48
  DACin                 : in  std_logic_vector(DAC_Width-1 downto 0);
49
  DACout                : out std_logic
50
);
51
end entity;
52
 
53
architecture behave of vdsm8 is
54
 
55
  function ceil_log2 (x : in natural) return natural is
56
    variable retval     : natural;
57
  begin
58
    retval              := 1;
59
    while ((2**retval) - 1) < x loop
60
      retval            := retval + 1;
61
    end loop;
62
    return retval;
63
  end function;
64
 
65
  constant DELTA_1_I    : integer := 1;
66
  constant DELTA_2_I    : integer := 5;
67
  constant DELTA_3_I    : integer := 25;
68
  constant DELTA_4_I    : integer := 75;
69
  constant DELTA_5_I    : integer := 125;
70
  constant DELTA_6_I    : integer := 195;
71
 
72
  constant DELTA_1      : std_logic_vector(DAC_Width-1 downto 0) :=
73
                           conv_std_logic_vector(DELTA_1_I, DAC_Width);
74
  constant DELTA_2      : std_logic_vector(DAC_Width-1 downto 0) :=
75
                           conv_std_logic_vector(DELTA_2_I, DAC_Width);
76
  constant DELTA_3      : std_logic_vector(DAC_Width-1 downto 0) :=
77
                           conv_std_logic_vector(DELTA_3_I, DAC_Width);
78
  constant DELTA_4      : std_logic_vector(DAC_Width-1 downto 0) :=
79
                           conv_std_logic_vector(DELTA_4_I, DAC_Width);
80
  constant DELTA_5      : std_logic_vector(DAC_Width-1 downto 0) :=
81
                           conv_std_logic_vector(DELTA_5_I, DAC_Width);
82
  constant DELTA_6      : std_logic_vector(DAC_Width-1 downto 0) :=
83
                           conv_std_logic_vector(DELTA_6_I, DAC_Width);
84
 
85
  constant MAX_PERIOD   : integer := 2**DAC_Width;
86
  constant DIV_WIDTH    : integer := DAC_Width * 2;
87
 
88
  constant PADJ_1_I     : integer := DELTA_1_I * MAX_PERIOD;
89
  constant PADJ_2_I     : integer := DELTA_2_I * MAX_PERIOD;
90
  constant PADJ_3_I     : integer := DELTA_3_I * MAX_PERIOD;
91
  constant PADJ_4_I     : integer := DELTA_4_I * MAX_PERIOD;
92
  constant PADJ_5_I     : integer := DELTA_5_I * MAX_PERIOD;
93
  constant PADJ_6_I     : integer := DELTA_6_I * MAX_PERIOD;
94
 
95
  constant PADJ_1       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
96
                           conv_std_logic_vector(PADJ_1_I,DIV_WIDTH);
97
  constant PADJ_2       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
98
                           conv_std_logic_vector(PADJ_2_I,DIV_WIDTH);
99
  constant PADJ_3       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
100
                           conv_std_logic_vector(PADJ_3_I,DIV_WIDTH);
101
  constant PADJ_4       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
102
                           conv_std_logic_vector(PADJ_4_I,DIV_WIDTH);
103
  constant PADJ_5       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
104
                           conv_std_logic_vector(PADJ_5_I,DIV_WIDTH);
105
  constant PADJ_6       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
106
                           conv_std_logic_vector(PADJ_6_I,DIV_WIDTH);
107
 
108
  signal DACin_q        : std_logic_vector(DAC_Width-1 downto 0);
109
 
110
  signal Divisor        : std_logic_vector(DIV_WIDTH-1 downto 0);
111
  signal Dividend       : std_logic_vector(DIV_WIDTH-1 downto 0);
112
 
113
  signal q              : std_logic_vector(DIV_WIDTH*2-1 downto 0);
114
  signal diff           : std_logic_vector(DIV_WIDTH downto 0);
115
 
116
  constant CB           : integer := ceil_log2(DIV_WIDTH);
117
  signal count          : std_logic_vector(CB-1 downto 0);
118
 
119
  signal Next_Width     : std_logic_vector(DAC_Width-1 downto 0);
120
  signal Next_Period    : std_logic_vector(DAC_Width-1 downto 0);
121
 
122
  signal PWM_Width      : std_logic_vector(DAC_Width-1 downto 0);
123
  signal PWM_Period     : std_logic_vector(DAC_Width-1 downto 0);
124
 
125
  signal Width_Ctr      : std_logic_vector(DAC_Width-1 downto 0);
126
  signal Period_Ctr     : std_logic_vector(DAC_Width-1 downto 0);
127
 
128
begin
129
 
130
  diff                  <= ('0' & q(DIV_WIDTH*2-2 downto DIV_WIDTH-1)) -
131
                           ('0' & Divisor);
132
 
133
  Dividend   <= PADJ_2 when DACin_q >= DELTA_2_I and DACin_q < DELTA_3_I else
134
                PADJ_3 when DACin_q >= DELTA_3_I and DACin_q < DELTA_4_I else
135
                PADJ_4 when DACin_q >= DELTA_4_I and DACin_q < DELTA_5_I else
136
                PADJ_5 when DACin_q >= DELTA_5_I and DACin_q < DELTA_6_I else
137
                PADJ_6 when DACin_q >= DELTA_6_I else
138
                PADJ_1;
139
 
140
  Next_Width <= DELTA_1 when DACin_q >= DELTA_1_I and DACin_q < DELTA_2_I else
141
                DELTA_2 when DACin_q >= DELTA_2_I and DACin_q < DELTA_3_I else
142
                DELTA_3 when DACin_q >= DELTA_3_I and DACin_q < DELTA_4_I else
143
                DELTA_4 when DACin_q >= DELTA_4_I and DACin_q < DELTA_5_I else
144
                DELTA_5 when DACin_q >= DELTA_5_I and DACin_q < DELTA_6_I else
145
                DELTA_6 when DACin_q >= DELTA_6_I else
146
                (others => '0');
147
 
148
  Next_Period           <= q(7 downto 0) - 1;
149
 
150
  vDSM_proc: process( Clock, Reset )
151
  begin
152
    if( Reset = Reset_Level )then
153
      q                 <= (others => '0');
154
      count             <= (others => '1');
155
      Divisor           <= (others => '0');
156
      DACin_q       <= (others => '0');
157
      PWM_Width         <= (others => '0');
158
      PWM_Period        <= (others => '0');
159
      Period_Ctr        <= (others => '0');
160
      Width_Ctr         <= (others => '0');
161
      DACout            <= '0';
162
    elsif( rising_edge(Clock) )then
163
      q                 <= diff(DIV_WIDTH-1 downto 0) &
164
                           q(DIV_WIDTH-2 downto 0) & '1';
165
      if( diff(DIV_WIDTH) = '1' )then
166
        q               <= q(DIV_WIDTH*2-2 downto 0) & '0';
167
      end if;
168
 
169
      count             <= count + 1;
170
      if( count = DIV_WIDTH )then
171
        PWM_Width       <= Next_Width;
172
        PWM_Period      <= Next_Period;
173
        DACin_q     <= DACin;
174
        Divisor         <= (others => '0');
175
        Divisor(DAC_Width-1 downto 0) <= DACin_q;
176
        q               <= conv_std_logic_vector(0,DIV_WIDTH) & Dividend;
177
        count           <= (others => '0');
178
      end if;
179
 
180
      Period_Ctr        <= Period_Ctr - 1;
181
      Width_Ctr         <= Width_Ctr - 1;
182
 
183
      DACout            <= '1';
184
      if( Width_Ctr = 0 )then
185
        DACout          <= '0';
186
        Width_Ctr       <= (others => '0');
187
      end if;
188
 
189
      if( Period_Ctr = 0 )then
190
        Period_Ctr      <= PWM_Period;
191
        Width_Ctr       <= PWM_Width;
192
      end if;
193
 
194
    end if;
195
  end process;
196
 
197
end architecture;

powered by: WebSVN 2.1.0

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