summaryrefslogtreecommitdiff
path: root/Examples/Mixed_Mode/custom_mixed_mode/customblock.vhdl
blob: afe2c4dd31c468b5cb00aa51dd275ecf8646a844 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity customblock is
port(C : in std_logic;
     D : in std_logic;
     Q : out std_logic);
end customblock;


architecture bhv of customblock is
       signal count:  integer:=1;       --counts number of CLOCK cycles
       signal period: integer:=10;      --PWM signal period is 10 times of clock period
       signal boost  : integer:=9;      --number of clock pulses during T_ON
       signal buck : integer:=1;        --number of clock pulses during T_OFF
begin
	process (C,D)

       begin

          if(C='1' and C'event) then 
            count<=count+1;      
            if(count=period)then -- resets count for period
              count<=1;
            end if;
            if(D='1') then --boost duty cycle when compartor output is high--
              if(count<=boost)then 
                Q<='1';
              elsif(count>boost) then
                Q<='0';     
              end if; 
            end if;
            if(D='0')then --buck duty cycle when compartor output is low--
              if(count<=buck)then --
                Q<='1';
              elsif(count>buck)then
                Q<='0';  
              end if;
            end if;    
        end if;
  end process;
end bhv;