Hi to all, I try to generate two synchronous PWM signals however I missing something. I'll be grateful if you could assist me. 1. Two signals should start at the same time. 2. When PWM_1 is rising edge the PWM_2 should be start either. 3. PWM_1 is 1us period , 0.5 uS high ('1') and 0.5 uS low ('0'). 50% Duty cycle. 4. PWM_2 is 1uS period , 0.3uS high ('1') and 0.7 us low ('0'). 30% Duty cycle. Code and simulation attached . Simulation : Attached image of simulation Sim.PNG CODE :
1 | LIBRARY IEEE; |
2 | USE IEEE.STD_LOGIC_1164.ALL; |
3 | |
4 | ENTITY clk1 IS |
5 | PORT ( |
6 | clk : IN STD_LOGIC; |
7 | reset : IN STD_LOGIC; |
8 | clk_out : OUT STD_LOGIC; |
9 | pwm_1 : OUT STD_LOGIC; |
10 | pwm_2 : OUT STD_LOGIC |
11 | ); |
12 | END clk1; |
13 | |
14 | ARCHITECTURE Behavioral OF clk1 IS |
15 | SIGNAL temporal_1 : STD_LOGIC; |
16 | SIGNAL temporal_2 : STD_LOGIC; |
17 | SIGNAL temporal_4 : STD_LOGIC; |
18 | SIGNAL counter_1 : INTEGER RANGE 0 TO 4 := 0;--780 original |
19 | SIGNAL counter_2 : INTEGER RANGE 0 TO 4 := 0;--780 original |
20 | SIGNAL counter_3 : INTEGER RANGE 0 TO 4 := 0;--780 original |
21 | SIGNAL counter_4 : INTEGER RANGE 0 TO 4 := 0;--780 original |
22 | BEGIN |
23 | freq_divider_1 : PROCESS (reset, clk) |
24 | BEGIN |
25 | |
26 | IF rising_edge(clk) THEN |
27 | counter_3 <=counter_3+1; |
28 | --counter_4 <=counter_3+1; |
29 | END IF; |
30 | |
31 | IF (reset = '1') THEN |
32 | temporal_1 <= '0'; |
33 | counter_1 <= 0; |
34 | ELSIF rising_edge(clk) THEN |
35 | |
36 | IF (counter_1 = 4) THEN |
37 | |
38 | temporal_1 <= NOT(temporal_1); |
39 | |
40 | counter_1 <= 0; |
41 | ELSE |
42 | counter_1 <= counter_1 + 1; |
43 | END IF; |
44 | |
45 | END IF; |
46 | |
47 | |
48 | IF (reset = '1') THEN |
49 | temporal_2 <= '0'; |
50 | counter_2 <= 0; |
51 | ELSIF rising_edge(clk) THEN |
52 | |
53 | IF (counter_2 = 3) THEN |
54 | |
55 | temporal_2 <= NOT(temporal_2); |
56 | counter_2 <= 0; |
57 | ELSE |
58 | counter_2 <= counter_2 + 1; |
59 | IF counter_2 = 2 THEN |
60 | temporal_2 <= '0'; |
61 | ELSE |
62 | temporal_2 <=temporal_2; |
63 | END IF; |
64 | END IF; |
65 | |
66 | END IF; |
67 | |
68 | END PROCESS; |
69 | |
70 | clk_out <= temporal_1; |
71 | pwm_1 <= temporal_1; |
72 | pwm_2 <= temporal_2; |
73 | |
74 | END Behavioral; |
Thanks. Stas.