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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_vdsm8.vhd] - Blame information for rev 213

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

Line No. Rev Author Line
1 213 jshamlet
-- Copyright (c)2016, 2020 Jeremy Seth Henry
2 167 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 194 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 167 jshamlet
--
24
-- VHDL Units :  o8_vdsm8
25
-- Description:  8-bit variable delta-sigma modulator. Requires Open8_pkg.vhd
26 213 jshamlet
--
27
-- Revision History
28
-- Author          Date     Change
29
------------------ -------- ---------------------------------------------------
30
-- Seth Henry      06/23/16 Design start
31
-- Seth Henry      04/10/20 Code Cleanup
32 167 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
library work;
39
  use work.open8_pkg.all;
40
 
41
entity o8_vdsm8 is
42
generic(
43
  Reset_Level           : std_logic;
44
  Address               : ADDRESS_TYPE
45
);
46
port(
47
  Clock                 : in  std_logic;
48
  Reset                 : in  std_logic;
49
  --
50
  Bus_Address           : in  ADDRESS_TYPE;
51
  Wr_Enable             : in  std_logic;
52
  Wr_Data               : in  DATA_TYPE;
53
  Rd_Enable             : in  std_logic;
54
  Rd_Data               : out DATA_TYPE;
55
  --
56
  DACout                : out std_logic
57
);
58
end entity;
59
 
60
architecture behave of o8_vdsm8 is
61
 
62
  constant User_Addr    : std_logic_vector(15 downto 0) := Address;
63
  alias  Comp_Addr      is Bus_Address(15 downto 0);
64 213 jshamlet
  signal Addr_Match     : std_logic := '0';
65
  signal Wr_En          : std_logic := '0';
66
  signal Wr_Data_q      : DATA_TYPE := x"00";
67
  signal Rd_En          : std_logic := '0';
68
  signal DACin          : DATA_TYPE := x"00";
69 172 jshamlet
 
70 167 jshamlet
  -- DAC WIDTH = 8 is fixed, with all constants normalized
71
  --  against 256 (the MAX PERIOD)
72 172 jshamlet
 
73 167 jshamlet
  constant DAC_WIDTH    : integer := 8;
74 172 jshamlet
 
75 167 jshamlet
  constant DELTA_1_I    : integer := 1;
76
  constant DELTA_2_I    : integer := 5;
77
  constant DELTA_3_I    : integer := 25;
78
  constant DELTA_4_I    : integer := 75;
79
  constant DELTA_5_I    : integer := 125;
80
  constant DELTA_6_I    : integer := 195;
81
 
82
  constant DELTA_1      : std_logic_vector(DAC_WIDTH - 1 downto 0) :=
83
                           conv_std_logic_vector(DELTA_1_I, DAC_WIDTH);
84
  constant DELTA_2      : std_logic_vector(DAC_WIDTH - 1 downto 0) :=
85
                           conv_std_logic_vector(DELTA_2_I, DAC_WIDTH);
86
  constant DELTA_3      : std_logic_vector(DAC_WIDTH - 1 downto 0) :=
87
                           conv_std_logic_vector(DELTA_3_I, DAC_WIDTH);
88
  constant DELTA_4      : std_logic_vector(DAC_WIDTH - 1 downto 0) :=
89
                           conv_std_logic_vector(DELTA_4_I, DAC_WIDTH);
90
  constant DELTA_5      : std_logic_vector(DAC_WIDTH - 1 downto 0) :=
91
                           conv_std_logic_vector(DELTA_5_I, DAC_WIDTH);
92
  constant DELTA_6      : std_logic_vector(DAC_WIDTH - 1 downto 0) :=
93
                           conv_std_logic_vector(DELTA_6_I, DAC_WIDTH);
94
 
95
  constant MAX_PERIOD   : integer := 2**DAC_WIDTH;
96
  constant DIV_WIDTH    : integer := 2 * DAC_WIDTH;
97
 
98
  constant PADJ_1_I     : integer := DELTA_1_I * MAX_PERIOD;
99
  constant PADJ_2_I     : integer := DELTA_2_I * MAX_PERIOD;
100
  constant PADJ_3_I     : integer := DELTA_3_I * MAX_PERIOD;
101
  constant PADJ_4_I     : integer := DELTA_4_I * MAX_PERIOD;
102
  constant PADJ_5_I     : integer := DELTA_5_I * MAX_PERIOD;
103
  constant PADJ_6_I     : integer := DELTA_6_I * MAX_PERIOD;
104
 
105
  constant PADJ_1       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
106
                           conv_std_logic_vector(PADJ_1_I,DIV_WIDTH);
107
  constant PADJ_2       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
108
                           conv_std_logic_vector(PADJ_2_I,DIV_WIDTH);
109
  constant PADJ_3       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
110
                           conv_std_logic_vector(PADJ_3_I,DIV_WIDTH);
111
  constant PADJ_4       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
112
                           conv_std_logic_vector(PADJ_4_I,DIV_WIDTH);
113
  constant PADJ_5       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
114
                           conv_std_logic_vector(PADJ_5_I,DIV_WIDTH);
115
  constant PADJ_6       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
116
                           conv_std_logic_vector(PADJ_6_I,DIV_WIDTH);
117
 
118 213 jshamlet
  signal DACin_q        : DATA_TYPE := x"00";
119 167 jshamlet
 
120 213 jshamlet
  signal Divisor        : std_logic_vector(DIV_WIDTH-1 downto 0) :=
121
                           (others => '0');
122
  signal Dividend       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
123
                           (others => '0');
124 167 jshamlet
 
125 213 jshamlet
  signal q              : std_logic_vector(DIV_WIDTH*2-1 downto 0) :=
126
                           (others => '0');
127 167 jshamlet
 
128 213 jshamlet
  signal diff           : std_logic_vector(DIV_WIDTH downto 0) :=
129
                           (others => '0');
130
 
131 167 jshamlet
  constant CB           : integer := ceil_log2(DIV_WIDTH);
132 213 jshamlet
  signal count          : std_logic_vector(CB-1 downto 0) :=
133
                           (others => '0');
134 167 jshamlet
 
135 213 jshamlet
  signal Next_Width     : DATA_TYPE := x"00";
136
  signal Next_Period    : DATA_TYPE := x"00";
137 167 jshamlet
 
138 213 jshamlet
  signal PWM_Width      : DATA_TYPE := x"00";
139
  signal PWM_Period     : DATA_TYPE := x"00";
140 167 jshamlet
 
141 213 jshamlet
  signal Width_Ctr      : DATA_TYPE := x"00";
142
  signal Period_Ctr     : DATA_TYPE := x"00";
143 167 jshamlet
 
144
begin
145
 
146
  Addr_Match            <= '1' when Comp_Addr = User_Addr else '0';
147
 
148
  io_reg: process( Clock, Reset )
149
  begin
150
    if( Reset = Reset_Level )then
151 172 jshamlet
      Wr_En             <= '0';
152 167 jshamlet
      Wr_Data_q         <= x"00";
153
      Rd_En             <= '0';
154 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
155 172 jshamlet
      DACin             <= x"00";
156 167 jshamlet
    elsif( rising_edge( Clock ) )then
157
      Wr_En             <= Addr_Match and Wr_Enable;
158
      Wr_Data_q         <= Wr_Data;
159
      if( Wr_En = '1' )then
160 172 jshamlet
        DACin           <= Wr_Data_q;
161
      end if;
162 167 jshamlet
 
163 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
164 167 jshamlet
      Rd_En             <= Addr_Match and Rd_Enable;
165
      if( Rd_En = '1' )then
166
        Rd_Data         <= DACin;
167
      end if;
168
    end if;
169
  end process;
170
 
171
  diff                  <= ('0' & q(DIV_WIDTH*2-2 downto DIV_WIDTH-1)) -
172
                           ('0' & Divisor);
173
 
174
  Dividend   <= PADJ_2 when DACin_q >= DELTA_2_I and DACin_q < DELTA_3_I else
175
                PADJ_3 when DACin_q >= DELTA_3_I and DACin_q < DELTA_4_I else
176
                PADJ_4 when DACin_q >= DELTA_4_I and DACin_q < DELTA_5_I else
177
                PADJ_5 when DACin_q >= DELTA_5_I and DACin_q < DELTA_6_I else
178
                PADJ_6 when DACin_q >= DELTA_6_I else
179
                PADJ_1;
180
 
181
  Next_Width <= DELTA_1 when DACin_q >= DELTA_1_I and DACin_q < DELTA_2_I else
182
                DELTA_2 when DACin_q >= DELTA_2_I and DACin_q < DELTA_3_I else
183
                DELTA_3 when DACin_q >= DELTA_3_I and DACin_q < DELTA_4_I else
184
                DELTA_4 when DACin_q >= DELTA_4_I and DACin_q < DELTA_5_I else
185
                DELTA_5 when DACin_q >= DELTA_5_I and DACin_q < DELTA_6_I else
186
                DELTA_6 when DACin_q >= DELTA_6_I else
187
                (others => '0');
188
 
189
  Next_Period           <= q(7 downto 0) - 1;
190 172 jshamlet
 
191 167 jshamlet
  vDSM_proc: process( Clock, Reset )
192
  begin
193
    if( Reset = Reset_Level )then
194
      q                 <= (others => '0');
195
      count             <= (others => '1');
196
      Divisor           <= (others => '0');
197
      DACin_q           <= (others => '0');
198
      PWM_Width         <= (others => '0');
199
      PWM_Period        <= (others => '0');
200
      Period_Ctr        <= (others => '0');
201
      Width_Ctr         <= (others => '0');
202
      DACout            <= '0';
203
    elsif( rising_edge(Clock) )then
204
      q                 <= diff(DIV_WIDTH-1 downto 0) &
205
                           q(DIV_WIDTH-2 downto 0) & '1';
206
      if( diff(DIV_WIDTH) = '1' )then
207
        q               <= q(DIV_WIDTH*2-2 downto 0) & '0';
208
      end if;
209
 
210
      count             <= count + 1;
211
      if( count = DIV_WIDTH )then
212
        PWM_Width       <= Next_Width;
213
        PWM_Period      <= Next_Period;
214
        DACin_q         <= DACin;
215
        Divisor         <= (others => '0');
216
        Divisor(7 downto 0) <= DACin_q;
217
        q               <= conv_std_logic_vector(0,DIV_WIDTH) & Dividend;
218
        count           <= (others => '0');
219
      end if;
220
 
221
      Period_Ctr        <= Period_Ctr - 1;
222
      Width_Ctr         <= Width_Ctr - 1;
223
 
224
      DACout            <= '1';
225
      if( Width_Ctr = 0 )then
226
        DACout          <= '0';
227
        Width_Ctr       <= (others => '0');
228
      end if;
229
 
230
      if( Period_Ctr = 0 )then
231
        Period_Ctr      <= PWM_Period;
232
        Width_Ctr       <= PWM_Width;
233
      end if;
234
 
235
    end if;
236
  end process;
237
 
238
end architecture;

powered by: WebSVN 2.1.0

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