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

Subversion Repositories signal_waveform_generator

[/] [signal_waveform_generator/] [trunk/] [hw/] [sources/] [SignalGenerator.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ldalmasso
------------------------------------------------------------------------
2
-- Engineer:    Dalmasso Loic
3
-- Create Date: 30/01/2025
4
-- Module Name: SignalGenerator
5
-- Description:
6
--      Simple ROM-based Signal Generator Module with PWM. Selector allows to switch to several signal types:
7
--          - Sine
8
--          - Triangle
9
--          - Sawtooth
10
--          - Square
11
--      User specifies the signal waveform accuracy (depth & size of ROM) in bits, the expected frequency output and a frequence error range in Hz.
12
--
13
-- Generics
14
--      sys_clock: System Input Clock Frequency (Hz)
15
--      waveform_addr_bits: ROM Address Bits length
16
--      waveform_data_bits: ROM Data Bits length
17
--              signal_output_freq: Signal Output Frequency (Hz)
18
--              signal_output_freq_error: Range of Signal Output Error Range (Hz)
19
-- Ports
20
--              Input   -       i_sys_clock: System Input Clock
21
--              Input   -       i_reset: Reset ('0': No Reset, '1': Reset)
22
--              Input   -       i_waveform_select: Waveform Generator Type Selector ("00": Sine, "01": Triangle, "10": Sawtooth, "11": Square)
23
--              Output  -       o_signal: Signal Ouput Value
24
------------------------------------------------------------------------
25
 
26
LIBRARY IEEE;
27
USE IEEE.STD_LOGIC_1164.ALL;
28
USE IEEE.NUMERIC_STD.ALL;
29
 
30
ENTITY SignalGenerator is
31
 
32
GENERIC(
33
        sys_clock: INTEGER := 100_000_000;
34
    waveform_addr_bits: INTEGER range 1 to 30 := 8;
35
        waveform_data_bits: INTEGER range 1 to 31 := 8;
36
        signal_output_freq: INTEGER := 7;
37
        signal_output_freq_error: INTEGER := 1
38
);
39
 
40
PORT(
41
    i_sys_clock: IN STD_LOGIC;
42
    i_reset: IN STD_LOGIC;
43
    i_waveform_select: IN STD_LOGIC_VECTOR (1 downto 0);
44
    o_signal: OUT STD_LOGIC
45
);
46
 
47
END SignalGenerator;
48
 
49
ARCHITECTURE Behavioral of SignalGenerator is
50
 
51
------------------------------------------------------------------------
52
-- Component Declarations
53
------------------------------------------------------------------------
54
COMPONENT WaveformGenerator is
55
 
56
    GENERIC(
57
        rom_addr_bits: INTEGER range 1 to 30 := 8;
58
        rom_data_bits: INTEGER range 1 to 31 := 8
59
    );
60
 
61
    PORT(
62
        i_sys_clock: IN STD_LOGIC;
63
        i_waveform_select: IN STD_LOGIC_VECTOR(1 downto 0);
64
        i_waveform_step: IN UNSIGNED(rom_addr_bits-1 downto 0);
65
        o_waveform: OUT UNSIGNED(rom_data_bits-1 downto 0)
66
    );
67
 
68
END COMPONENT;
69
 
70
COMPONENT PwmController is
71
 
72
    GENERIC(
73
        sys_clock: INTEGER := 100_000_000;
74
        pwm_resolution: INTEGER := 8;
75
        signal_output_freq: INTEGER := 7;
76
        signal_output_freq_error: INTEGER := 1
77
    );
78
 
79
    PORT(
80
        i_sys_clock: IN STD_LOGIC;
81
        i_reset: IN STD_LOGIC;
82
        i_duty_cycle: IN UNSIGNED(pwm_resolution downto 0);
83
        o_next_duty_cycle_trigger: OUT STD_LOGIC;
84
        o_pwm: OUT STD_LOGIC
85
    );
86
 
87
END COMPONENT;
88
 
89
------------------------------------------------------------------------
90
-- Constant Declarations
91
------------------------------------------------------------------------
92
signal WAVEFORM_OUT_MAX: UNSIGNED(waveform_data_bits-1 downto 0) := (others => '1');
93
 
94
------------------------------------------------------------------------
95
-- Signal Declarations
96
------------------------------------------------------------------------
97
-- Waveform Step Counter (No initial value to allow ROM primitives mapping)
98
signal waveform_step_counter: UNSIGNED(waveform_addr_bits -1 downto 0);
99
 
100
-- Waveform Generator Output
101
signal waveform_out: UNSIGNED(waveform_data_bits-1 downto 0) := (others => '0');
102
 
103
-- PWM Duty Cycle
104
signal pwm_duty_cycle: UNSIGNED(waveform_data_bits downto 0) := (others => '0');
105
 
106
-- Next PWN Duty Cycle Trigger
107
signal next_duty_cycle_trigger: STD_LOGIC := '0';
108
 
109
------------------------------------------------------------------------
110
-- Module Implementation
111
------------------------------------------------------------------------
112
begin
113
 
114
        ---------------------------
115
        -- Waveform Step Handler --
116
        ---------------------------
117
        process(i_sys_clock)
118
        begin
119
                if rising_edge(i_sys_clock) then
120
 
121
                        -- Reset Waveform Step Counter
122
                        if (i_reset = '1') then
123
                                waveform_step_counter <= (others => '0');
124
 
125
                        -- Increment Waveform Step Counter (only when PWM Next Duty Cycle is Ready)
126
                        elsif (next_duty_cycle_trigger = '1') then
127
                waveform_step_counter <= waveform_step_counter +1;
128
                        end if;
129
                end if;
130
        end process;
131
 
132
        ------------------------
133
        -- Waveform Generator --
134
        ------------------------
135
    inst_waveform_generator: WaveformGenerator
136
        generic map (
137
            rom_addr_bits => waveform_addr_bits,
138
            rom_data_bits => waveform_data_bits)
139
 
140
        port map (
141
            i_sys_clock => i_sys_clock,
142
            i_waveform_select => i_waveform_select,
143
            i_waveform_step => waveform_step_counter,
144
            o_waveform => waveform_out);
145
 
146
        ------------------------------
147
        -- PWM Duty Cycle Formatter --
148
        ------------------------------
149
    process(i_sys_clock)
150
        begin
151
                if rising_edge(i_sys_clock) then
152
 
153
            -- Apply PWM Duty Cycle
154
            pwm_duty_cycle <= '0' & waveform_out;
155
 
156
                        -- 1-Bit Waveform Generator Output Extender
157
            if (waveform_out = WAVEFORM_OUT_MAX) then
158
                pwm_duty_cycle(waveform_data_bits) <= '1';
159
            end if;
160
                end if;
161
        end process;
162
 
163
        --------------------
164
        -- PWM Controller --
165
        --------------------
166
    inst_pwm_controller: PwmController
167
        generic map (
168
            sys_clock => sys_clock,
169
            pwm_resolution => waveform_data_bits,
170
            signal_output_freq => signal_output_freq,
171
            signal_output_freq_error => signal_output_freq_error)
172
 
173
        PORT map(
174
            i_sys_clock => i_sys_clock,
175
            i_reset => i_reset,
176
            i_duty_cycle=> pwm_duty_cycle,
177
            o_next_duty_cycle_trigger => next_duty_cycle_trigger,
178
            o_pwm => o_signal);
179
 
180
end Behavioral;

powered by: WebSVN 2.1.0

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