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 191

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

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

powered by: WebSVN 2.1.0

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