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

Subversion Repositories signal_waveform_generator

[/] [signal_waveform_generator/] [trunk/] [hw/] [sources/] [PwmController/] [simulations/] [Testbench_PwmController.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: 28/01/2025
4
-- Module Name: PwmController
5
-- Description:
6
--      PWM Controller with configurable PWM Resolution (in bits), PWM Signal Output Frequency (Hz) and PWM Signal Output Frequency Error Range (Hz).
7
--              The size of the Duty Cycle input is 1-bit greater than the PWM Resolution to handle 100% Duty Cycle.
8
--              The Duty Cyle value is dynamic but the new value will be applied only at the end of the PWM Duty Cycle Period (when Next Duty Cycle Trigger is enable).
9
--              User MUST carefully select generic parameters to satisfy PWM Output Frequency & Accuracy. Otherwise, assertion will be throw.
10
--              User can fix a Range of valid PWM Frequency Output.
11
--
12
-- Generics
13
--              sys_clock: System Input Clock Frequency (Hz)
14
--              pwm_resolution: PWM Resolution (Bits)
15
--              signal_output_freq: PWM Signal Output Frequency (Hz)
16
--              signal_output_freq_error: Range of PWM Signal Output Error Range (Hz)
17
-- Ports
18
--              Input   -       i_sys_clock: System Input Clock
19
--              Input   -       i_reset: Reset ('0': No Reset, '1': Reset)
20
--              Input   -       i_duty_cycle: Duty Cycle to apply (Value Range: [0;2^pwm_resolution])
21
--              Output  -       o_next_duty_cycle_trigger: Next Duty Cycle Trigger ('0': No Trigger, '1': Trigger Enable)
22
--              Output  -       o_pwm: PWM Output
23
------------------------------------------------------------------------
24
 
25
LIBRARY IEEE;
26
USE IEEE.STD_LOGIC_1164.ALL;
27
USE IEEE.NUMERIC_STD.ALL;
28
 
29
ENTITY Testbench_PwmController is
30
END Testbench_PwmController;
31
 
32
ARCHITECTURE Behavioral of Testbench_PwmController is
33
 
34
COMPONENT PwmController is
35
 
36
GENERIC(
37
        sys_clock: INTEGER := 100_000_000;
38
        pwm_resolution: INTEGER := 8;
39
        signal_output_freq: INTEGER := 20_000;
40
        signal_output_freq_error: INTEGER := 500
41
);
42
 
43
PORT(
44
        i_sys_clock: IN STD_LOGIC;
45
    i_reset: IN STD_LOGIC;
46
        i_duty_cycle: IN UNSIGNED(pwm_resolution downto 0);
47
        o_next_duty_cycle_trigger: OUT STD_LOGIC;
48
        o_pwm: OUT STD_LOGIC
49
);
50
 
51
END COMPONENT;
52
 
53
signal sys_clock: STD_LOGIC := '0';
54
signal reset: STD_LOGIC := '0';
55
signal duty_cycle: unsigned(8 downto 0) := (others => '0');
56
signal next_duty_cycle_trigger: STD_LOGIC := '0';
57
signal pwm_out: STD_LOGIC := '0';
58
 
59
begin
60
 
61
-- Clock 100 MHz
62
sys_clock <= not(sys_clock) after 5 ns;
63
 
64
-- Reset
65
reset <= '1', '0' after 145 ns;
66
 
67
-- Duty Cycle
68
duty_cycle <= "000000111", "000000000" after 496 us, "011111111" after 800 us, "100000000" after 1300 us;
69
 
70
uut: PwmController
71
    GENERIC map(
72
        sys_clock => 100_000_000,
73
        pwm_resolution => 8,
74
        signal_output_freq => 7,
75
        signal_output_freq_error => 1
76
    )
77
    PORT map(
78
        i_sys_clock => sys_clock,
79
        i_reset => reset,
80
        i_duty_cycle=> duty_cycle,
81
        o_next_duty_cycle_trigger => next_duty_cycle_trigger,
82
        o_pwm => pwm_out);
83
 
84
end Behavioral;

powered by: WebSVN 2.1.0

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