Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
pwm_device.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief PWM device
4 -------------------------------------------------------------------------------
5 
6 --! Using IEEE library
7 LIBRARY ieee;
8 
9 --! Using IEEE standard logic components
10 USE ieee.std_logic_1164.ALL;
11 
12 --! Using IEE standard numeric components
13 USE ieee.numeric_std.ALL;
14 
15 --! @brief PWM device entity
16 --!
17 --! @image html pwm_device_entity.png "PWM Device Entity"
18 --!
19 --! This entity manages four PWM devices. The write register contains the
20 --! four 8-bit PWM duty cycles. The read register contains the current four
21 --! 8-bit PWM duty cycles.
22 ENTITY pwm_device IS
23  PORT (
24  clk_in : IN std_logic; --! Clock
25  rst_in : IN std_logic; --! Asynchronous reset
26  dat_wr_done_in : IN std_logic; --! Device Write Done flag
27  dat_wr_reg_in : IN std_logic_vector(31 DOWNTO 0); --! Device Write Register value
28  dat_rd_reg_out : OUT std_logic_vector(31 DOWNTO 0); --! Device Read Register value
29  pwm_adv_in : IN std_logic; --! PWM Advance flag
30  pwm_out : OUT std_logic_vector(3 DOWNTO 0) --! PWM outputs
31  );
32 END ENTITY pwm_device;
33 
34 --! Architecture rtl of pwm_device entity
35 ARCHITECTURE rtl OF pwm_device IS
36 
37  --! Array type of four duty-cycles
38  TYPE pwm_duty_set IS ARRAY (3 DOWNTO 0) OF std_logic_vector(7 DOWNTO 0);
39 
40  --! Duty cycles array
42 
43 BEGIN
44 
45  --! Generate four PWMs
46  g_pwm : FOR i IN 0 TO 3 GENERATE
47 
48  --! Generate PWM instance
49  i_pwm : ENTITY work.pwm(rtl)
50  GENERIC MAP (
51  bit_width => 8
52  )
53  PORT MAP (
54  clk_in => clk_in,
55  rst_in => rst_in,
57  pwm_duty_in => pwm_duty(i),
58  pwm_out => pwm_out(i)
59  );
60 
61  END GENERATE g_pwm;
62 
63  --! @brief Process to handle writes and resets
64  pr_write : PROCESS (clk_in, rst_in) IS
65  BEGIN
66 
67  IF (rst_in = '1') THEN
68  -- Reset duty cycles
69  pwm_duty(3) <= (OTHERS => '0');
70  pwm_duty(2) <= (OTHERS => '0');
71  pwm_duty(1) <= (OTHERS => '0');
72  pwm_duty(0) <= (OTHERS => '0');
73  ELSIF (rising_edge(clk_in)) THEN
74  IF (dat_wr_done_in = '1') THEN
75  -- Set duty cycles from write register
76  pwm_duty(3) <= dat_wr_reg_in(31 DOWNTO 24);
77  pwm_duty(2) <= dat_wr_reg_in(23 DOWNTO 16);
78  pwm_duty(1) <= dat_wr_reg_in(15 DOWNTO 8);
79  pwm_duty(0) <= dat_wr_reg_in(7 DOWNTO 0);
80  END IF;
81  END IF;
82 
83  END PROCESS pr_write;
84 
85  --! @brief Process to handle reads
86  pr_read : PROCESS (clk_in) IS
87  BEGIN
88 
89  IF (rising_edge(clk_in)) THEN
90  -- Populate read register with duty cycles
91  dat_rd_reg_out <= pwm_duty(3) &
92  pwm_duty(2) &
93  pwm_duty(1) &
94  pwm_duty(0);
95  END IF;
96 
97  END PROCESS pr_read;
98 
99 END ARCHITECTURE rtl;
in rst_instd_logic
Asynchronous reset.
Definition: pwm.vhd:31
in clk_instd_logic
Clock.
Definition: pwm_device.vhd:24
in rst_instd_logic
Asynchronous reset.
Definition: pwm_device.vhd:25
pwm_duty_set pwm_duty
Duty cycles array.
Definition: pwm_device.vhd:41
in dat_wr_reg_instd_logic_vector( 31 DOWNTO 0)
Device Write Register value.
Definition: pwm_device.vhd:27
out dat_rd_reg_outstd_logic_vector( 31 DOWNTO 0)
Device Read Register value.
Definition: pwm_device.vhd:28
PWM entity.
Definition: pwm.vhd:25
in pwm_adv_instd_logic
PWM Advance flag.
Definition: pwm_device.vhd:29
in pwm_duty_instd_logic_vector( bit_width- 1 DOWNTO 0)
PWM duty cycle.
Definition: pwm.vhd:33
bit_widthnatural range 2 TO 32:= 8
PWM width.
Definition: pwm.vhd:28
in pwm_adv_instd_logic
PWM Advance flag.
Definition: pwm.vhd:32
( 3 DOWNTO 0) std_logic_vector( 7 DOWNTO 0) pwm_duty_set
Array type of four duty-cycles.
Definition: pwm_device.vhd:38
in clk_instd_logic
Clock.
Definition: pwm.vhd:30
PWM device entity.
Definition: pwm_device.vhd:22
out pwm_outstd_logic_vector( 3 DOWNTO 0)
PWM outputs.
Definition: pwm_device.vhd:31
out pwm_outstd_logic
PWM output.
Definition: pwm.vhd:35
_library_ ieeeieee
Using IEEE library.
Definition: gpio_device.vhd:7
in dat_wr_done_instd_logic
Device Write Done flag.
Definition: pwm_device.vhd:26