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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_vdsm12.vhd] - Blame information for rev 191

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

Line No. Rev Author Line
1 180 jshamlet
-- Copyright (c)2019 Jeremy Seth Henry
2
-- 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
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  o8_vdsm12
25
-- Description:  12-bit variable delta-sigma modulator. Requires Open8_pkg.vhd
26
--
27
-- Register Map:
28
-- Offset  Bitfield Description                        Read/Write
29
--   0x0   AAAAAAAA Pending DAC Level (7:0)            (R/W)
30
--   0x1   AAAAAAAA Pending DAC Level (11:8)           (R/W)
31
--   0x2   -------- Clear DAC Output (on write)        (WO)
32
--   0x3   AAAAAAAA Update DAC Output (on write)       (RO)
33
--
34
-- Revision History
35
-- Author          Date     Change
36
------------------ -------- ---------------------------------------------------
37
-- Seth Henry      12/18/19 Design start
38
 
39
library ieee;
40
use ieee.std_logic_1164.all;
41
use ieee.std_logic_unsigned.all;
42
use ieee.std_logic_arith.all;
43
 
44
library work;
45
  use work.open8_pkg.all;
46
 
47
entity o8_vdsm12 is
48
generic(
49
  Reset_Level           : std_logic := '1';
50
  Address               : ADDRESS_TYPE
51
);
52
port(
53
  Clock                 : in  std_logic;
54
  Reset                 : in  std_logic;
55
  --
56
  Bus_Address           : in  ADDRESS_TYPE;
57
  Wr_Enable             : in  std_logic;
58
  Wr_Data               : in  DATA_TYPE;
59
  Rd_Enable             : in  std_logic;
60
  Rd_Data               : out DATA_TYPE;
61
  --
62
  PDM_Out               : out std_logic
63
);
64
end entity;
65
 
66
architecture behave of o8_vdsm12 is
67
 
68
  constant User_Addr    : std_logic_vector(15 downto 2)
69
                          := Address(15 downto 2);
70
  alias  Comp_Addr      is Bus_Address(15 downto 2);
71
  alias  Reg_Addr       is Bus_Address(1 downto 0);
72
  signal Reg_Sel        : std_logic_vector(1 downto 0);
73
  signal Addr_Match     : std_logic;
74
  signal Wr_En          : std_logic;
75
  signal Wr_Data_q      : DATA_TYPE;
76
  signal Rd_En          : std_logic;
77
 
78
  constant DAC_Width    : integer := 12;
79
 
80
  signal DAC_Val_LB     : DATA_TYPE;
81
  signal DAC_Val_UB     : DATA_TYPE;
82
  signal DAC_Val        : std_logic_vector(DAC_Width-1 downto 0);
83
 
84
  constant DELTA_1_I    : integer := 1;
85
  constant DELTA_2_I    : integer := 5;
86
  constant DELTA_3_I    : integer := 25;
87
  constant DELTA_4_I    : integer := 75;
88
  constant DELTA_5_I    : integer := 125;
89
  constant DELTA_6_I    : integer := 250;
90
  constant DELTA_7_I    : integer := 500;
91
  constant DELTA_8_I    : integer := 1000;
92
  constant DELTA_9_I    : integer := 2000;
93
  constant DELTA_10_I   : integer := 3000;
94
 
95
  constant DELTA_1      : std_logic_vector(DAC_Width-1 downto 0) :=
96
                           conv_std_logic_vector(DELTA_1_I, DAC_Width);
97
  constant DELTA_2      : std_logic_vector(DAC_Width-1 downto 0) :=
98
                           conv_std_logic_vector(DELTA_2_I, DAC_Width);
99
  constant DELTA_3      : std_logic_vector(DAC_Width-1 downto 0) :=
100
                           conv_std_logic_vector(DELTA_3_I, DAC_Width);
101
  constant DELTA_4      : std_logic_vector(DAC_Width-1 downto 0) :=
102
                           conv_std_logic_vector(DELTA_4_I, DAC_Width);
103
  constant DELTA_5      : std_logic_vector(DAC_Width-1 downto 0) :=
104
                           conv_std_logic_vector(DELTA_5_I, DAC_Width);
105
  constant DELTA_6      : std_logic_vector(DAC_Width-1 downto 0) :=
106
                           conv_std_logic_vector(DELTA_6_I, DAC_Width);
107
  constant DELTA_7      : std_logic_vector(DAC_Width-1 downto 0) :=
108
                           conv_std_logic_vector(DELTA_7_I, DAC_Width);
109
  constant DELTA_8      : std_logic_vector(DAC_Width-1 downto 0) :=
110
                           conv_std_logic_vector(DELTA_8_I, DAC_Width);
111
  constant DELTA_9      : std_logic_vector(DAC_Width-1 downto 0) :=
112
                           conv_std_logic_vector(DELTA_9_I, DAC_Width);
113
  constant DELTA_10     : std_logic_vector(DAC_Width-1 downto 0) :=
114
                           conv_std_logic_vector(DELTA_10_I, DAC_Width);
115
 
116
  constant MAX_PERIOD   : integer := 2**DAC_Width;
117
  constant DIV_WIDTH    : integer := DAC_Width * 2;
118
 
119
  constant PADJ_1_I     : integer := DELTA_1_I * MAX_PERIOD;
120
  constant PADJ_2_I     : integer := DELTA_2_I * MAX_PERIOD;
121
  constant PADJ_3_I     : integer := DELTA_3_I * MAX_PERIOD;
122
  constant PADJ_4_I     : integer := DELTA_4_I * MAX_PERIOD;
123
  constant PADJ_5_I     : integer := DELTA_5_I * MAX_PERIOD;
124
  constant PADJ_6_I     : integer := DELTA_6_I * MAX_PERIOD;
125
  constant PADJ_7_I     : integer := DELTA_7_I * MAX_PERIOD;
126
  constant PADJ_8_I     : integer := DELTA_8_I * MAX_PERIOD;
127
  constant PADJ_9_I     : integer := DELTA_9_I * MAX_PERIOD;
128
  constant PADJ_10_I    : integer := DELTA_10_I * MAX_PERIOD;
129
 
130
  constant PADJ_1       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
131
                           conv_std_logic_vector(PADJ_1_I,DIV_WIDTH);
132
  constant PADJ_2       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
133
                           conv_std_logic_vector(PADJ_2_I,DIV_WIDTH);
134
  constant PADJ_3       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
135
                           conv_std_logic_vector(PADJ_3_I,DIV_WIDTH);
136
  constant PADJ_4       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
137
                           conv_std_logic_vector(PADJ_4_I,DIV_WIDTH);
138
  constant PADJ_5       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
139
                           conv_std_logic_vector(PADJ_5_I,DIV_WIDTH);
140
  constant PADJ_6       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
141
                           conv_std_logic_vector(PADJ_6_I,DIV_WIDTH);
142
  constant PADJ_7       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
143
                           conv_std_logic_vector(PADJ_7_I,DIV_WIDTH);
144
  constant PADJ_8       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
145
                           conv_std_logic_vector(PADJ_8_I,DIV_WIDTH);
146
  constant PADJ_9       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
147
                           conv_std_logic_vector(PADJ_9_I,DIV_WIDTH);
148
  constant PADJ_10      : std_logic_vector(DIV_WIDTH-1 downto 0) :=
149
                           conv_std_logic_vector(PADJ_10_I,DIV_WIDTH);
150
 
151
  signal DACin_q        : std_logic_vector(DAC_Width-1 downto 0);
152
 
153
  signal Divisor        : std_logic_vector(DIV_WIDTH-1 downto 0);
154
  signal Dividend       : std_logic_vector(DIV_WIDTH-1 downto 0);
155
 
156
  signal q              : std_logic_vector(DIV_WIDTH*2-1 downto 0);
157
  signal diff           : std_logic_vector(DIV_WIDTH downto 0);
158
 
159
  constant CB           : integer := ceil_log2(DIV_WIDTH);
160
  signal count          : std_logic_vector(CB-1 downto 0);
161
 
162
  signal Next_Width     : std_logic_vector(DAC_Width-1 downto 0);
163
  signal Next_Period    : std_logic_vector(DAC_Width-1 downto 0);
164
 
165
  signal PWM_Width      : std_logic_vector(DAC_Width-1 downto 0);
166
  signal PWM_Period     : std_logic_vector(DAC_Width-1 downto 0);
167
 
168
  signal Width_Ctr      : std_logic_vector(DAC_Width-1 downto 0);
169
  signal Period_Ctr     : std_logic_vector(DAC_Width-1 downto 0);
170
 
171
 
172
begin
173
 
174
  Addr_Match            <= '1' when Comp_Addr = User_Addr else '0';
175
 
176
  io_reg: process( Clock, Reset )
177
  begin
178
    if( Reset = Reset_Level )then
179
      Reg_Sel           <= "00";
180
      Rd_En             <= '0';
181 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
182 180 jshamlet
      Wr_En             <= '0';
183
      Wr_Data_q         <= x"00";
184
      DAC_Val_LB        <= x"00";
185
      DAC_Val_UB        <= x"00";
186
      DAC_Val           <= (others => '0');
187
    elsif( rising_edge( Clock ) )then
188
      Reg_Sel           <= Reg_Addr;
189
 
190
      Wr_En             <= Addr_Match and Wr_Enable;
191
      Wr_Data_q         <= Wr_Data;
192
      if( Wr_En = '1' )then
193
        case( Reg_Sel )is
194
          when "00" =>
195
            DAC_Val_LB  <= Wr_Data_q;
196
          when "01" =>
197
            DAC_Val_UB  <= "0000" & Wr_Data_q(3 downto 0);
198
          when "10" =>
199
            DAC_Val     <= (others => '0');
200
          when "11" =>
201
            DAC_Val     <= DAC_Val_UB(3 downto 0) & DAC_Val_LB;
202
          when others => null;
203
        end case;
204
      end if;
205
 
206 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
207 180 jshamlet
      Rd_En             <= Addr_Match and Rd_Enable;
208
      if( Rd_En = '1' )then
209
        case( Reg_Sel )is
210
          when "00" =>
211
            Rd_Data     <= DAC_Val_LB;
212
          when "01" =>
213
            Rd_Data     <= DAC_Val_UB;
214
          when others => null;
215
        end case;
216
      end if;
217
    end if;
218
  end process;
219
 
220
  diff                  <= ('0' & q(DIV_WIDTH*2-2 downto DIV_WIDTH-1)) -
221
                           ('0' & Divisor);
222
 
223
  Dividend   <= PADJ_2  when DACin_q >= DELTA_2_I and DACin_q < DELTA_3_I else
224
                PADJ_3  when DACin_q >= DELTA_3_I and DACin_q < DELTA_4_I else
225
                PADJ_4  when DACin_q >= DELTA_4_I and DACin_q < DELTA_5_I else
226
                PADJ_5  when DACin_q >= DELTA_5_I and DACin_q < DELTA_6_I else
227
                PADJ_6  when DACin_q >= DELTA_6_I and DACin_q < DELTA_7_I else
228
                PADJ_7  when DACin_q >= DELTA_7_I and DACin_q < DELTA_8_I else
229
                PADJ_8  when DACin_q >= DELTA_8_I and DACin_q < DELTA_9_I else
230
                PADJ_9  when DACin_q >= DELTA_9_I and DACin_q < DELTA_10_I else
231
                PADJ_10 when DACin_q >= DELTA_10_I else
232
                PADJ_1;
233
 
234
  Next_Width <= DELTA_1  when DACin_q >= DELTA_1_I and DACin_q < DELTA_2_I else
235
                DELTA_2  when DACin_q >= DELTA_2_I and DACin_q < DELTA_3_I else
236
                DELTA_3  when DACin_q >= DELTA_3_I and DACin_q < DELTA_4_I else
237
                DELTA_4  when DACin_q >= DELTA_4_I and DACin_q < DELTA_5_I else
238
                DELTA_5  when DACin_q >= DELTA_5_I and DACin_q < DELTA_6_I else
239
                DELTA_6  when DACin_q >= DELTA_6_I and DACin_q < DELTA_7_I else
240
                DELTA_7  when DACin_q >= DELTA_7_I and DACin_q < DELTA_8_I else
241
                DELTA_8  when DACin_q >= DELTA_8_I and DACin_q < DELTA_9_I else
242
                DELTA_9  when DACin_q >= DELTA_9_I and DACin_q < DELTA_10_I else
243
                DELTA_10 when DACin_q >= DELTA_10_I else
244
                (others => '0');
245
 
246
  Next_Period            <= q(DAC_Width-1 downto 0) - 1;
247 191 jshamlet
 
248 180 jshamlet
  vDSM_proc: process( Clock, Reset )
249
  begin
250
    if( Reset = Reset_Level )then
251
      q                 <= (others => '0');
252
      count             <= (others => '1');
253
      Divisor           <= (others => '0');
254
      DACin_q           <= (others => '0');
255
      PWM_Width         <= (others => '0');
256
      PWM_Period        <= (others => '0');
257
      Period_Ctr        <= (others => '0');
258
      Width_Ctr         <= (others => '0');
259
      PDM_Out           <= '0';
260
    elsif( rising_edge(Clock) )then
261
      q                 <= diff(DIV_WIDTH-1 downto 0) &
262
                           q(DIV_WIDTH-2 downto 0) & '1';
263
      if( diff(DIV_WIDTH) = '1' )then
264
        q               <= q(DIV_WIDTH*2-2 downto 0) & '0';
265
      end if;
266
 
267
      count             <= count + 1;
268
      if( count = DIV_WIDTH )then
269
        PWM_Width       <= Next_Width;
270
        PWM_Period      <= Next_Period;
271
        DACin_q         <= DAC_val;
272
        Divisor         <= (others => '0');
273
        Divisor(DAC_Width-1 downto 0) <= DACin_q;
274
        q               <= conv_std_logic_vector(0,DIV_WIDTH) & Dividend;
275
        count           <= (others => '0');
276
      end if;
277
 
278
      Period_Ctr        <= Period_Ctr - 1;
279
      Width_Ctr         <= Width_Ctr - 1;
280
 
281
      PDM_Out           <= '1';
282
      if( Width_Ctr = 0 )then
283
        PDM_Out         <= '0';
284
        Width_Ctr       <= (others => '0');
285
      end if;
286
 
287
      if( Period_Ctr = 0 )then
288
        Period_Ctr      <= PWM_Period;
289
        Width_Ctr       <= PWM_Width;
290
      end if;
291
 
292
    end if;
293
  end process;
294
 
295
end architecture;

powered by: WebSVN 2.1.0

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