Project

General

Profile

Download (3.07 KB) Statistics
| Branch: | Tag: | Revision:
1 c62f5734 Christian Daniel
---------------------------------------------------------------------------------------------------
2
-- Filename    : usbrx_pwm.vhd
3
-- Project     : OsmoSDR FPGA Firmware
4
-- Purpose     : PWM Generator
5
---------------------------------------------------------------------------------------------------
6
7
-----------------------------------------------------------------------------------
8
-- Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany --
9
-- written by Matthias Kleffel                                                   --
10
--                                                                               --
11
-- This program is free software; you can redistribute it and/or modify          --
12
-- it under the terms of the GNU General Public License as published by          --
13
-- the Free Software Foundation as version 3 of the License, or                  --
14
--                                                                               --
15
-- This program is distributed in the hope that it will be useful,               --
16
-- but WITHOUT ANY WARRANTY; without even the implied warranty of                --
17
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  --
18
-- GNU General Public License V3 for more details.                               --
19
--                                                                               --
20
-- You should have received a copy of the GNU General Public License             --
21
-- along with this program. If not, see <http://www.gnu.org/licenses/>.          --
22
-----------------------------------------------------------------------------------
23
24
library ieee;
25
	use ieee.std_logic_1164.all;
26
	use ieee.numeric_std.all;
27
library work;
28
	use work.all;
29
	use work.mt_toolbox.all;
30
	use work.usbrx.all;
31
32
entity usbrx_pwm is
33
	port(
34
		-- common
35
		clk       : in  std_logic;
36
		reset     : in  std_logic;
37
38
		-- config
39
		config    : in  usbrx_pwm_config_t;
40
		
41
		-- PWM output
42
		pwm0      : out std_logic;
43
		pwm1      : out std_logic
44
	);
45
end usbrx_pwm;
46
47
architecture rtl of usbrx_pwm is
48
49
	-- status
50
	signal counter0 : unsigned(15 downto 0);
51
	signal counter1 : unsigned(15 downto 0);
52
	signal out0     : std_logic;
53
	signal out1     : std_logic;
54
	
55
begin
56
	
57
	process(clk)
58
	begin
59
		if rising_edge(clk) then
60
			-- update counter #0
61
			counter0 <= counter0 - 1;
62
			if counter0 = 0 then
63
				counter0 <= config.freq0;
64
			end if;
65
			
66
			-- update counter #1
67
			counter1 <= counter1 - 1;
68
			if counter1 = 0 then
69
				counter1 <= config.freq1;
70
			end if;
71
			
72
			-- update output #0
73
			if counter0 < config.duty0
74
				then out0 <= '1';
75
				else out0 <= '0';
76
			end if;
77
			
78
			-- update output #1
79
			if counter1 < config.duty1
80
				then out1 <= '1';
81
				else out1 <= '0';
82
			end if;
83
			
84
			-- output register
85
			pwm0 <= out0;
86
			pwm1 <= out1;
87
				
88
			-- handle reset
89
			if reset='1' then
90
				counter0 <= (others=>'0');
91
				counter1 <= (others=>'0');
92
				out0     <= '0';
93
				out1     <= '0';
94
				pwm0     <= '0';
95
				pwm1     <= '0';
96
			end if;
97
		end if;
98
	end process;
99
	
100
end rtl;
Add picture from clipboard (Maximum size: 48.8 MB)