3signal.v 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /*
  2. * 3signal.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2025 Krzysztof Skrzynecki, Jakub Duchniewicz <j.duchniewicz@gmail.com>
  7. * SPDX-License-Identifier: TODO:
  8. */
  9. `default_nettype none
  10. module compare_eq#(
  11. parameter WIDTH = 16
  12. )(
  13. input wire clk,
  14. input wire [WIDTH-1:0] A,
  15. input wire [WIDTH-1:0] B,
  16. output reg [0:0] was_eq //1 if A and B were equal 2 ticks ago
  17. );
  18. parameter WIDTH_DIV4 = (WIDTH+3)/4;
  19. parameter WIDTH_REM = WIDTH - WIDTH_DIV4*3;
  20. wire [WIDTH_DIV4-1:0] A0_pt0, A0_pt1, A0_pt2;
  21. wire [WIDTH_REM-1:0] A0_pt3;
  22. wire [WIDTH_DIV4-1:0] B0_pt0, B0_pt1, B0_pt2;
  23. wire [WIDTH_REM-1:0] B0_pt3;
  24. assign {A0_pt3, A0_pt2, A0_pt1, A0_pt0} = A;
  25. assign {B0_pt3, B0_pt2, B0_pt1, B0_pt0} = B;
  26. reg pt0_eq, pt1_eq, pt2_eq, pt3_eq;
  27. always @(posedge clk) begin
  28. pt0_eq <= A0_pt0==B0_pt0;
  29. pt1_eq <= A0_pt1==B0_pt1;
  30. pt2_eq <= A0_pt2==B0_pt2;
  31. pt3_eq <= A0_pt3==B0_pt3;
  32. was_eq <= pt0_eq & pt1_eq & pt2_eq & pt3_eq;
  33. end
  34. endmodule
  35. /*
  36. module add#(
  37. parameter WIDTH = 16
  38. )(
  39. input wire clk,
  40. input wire [WIDTH-1:0] A,
  41. input wire [WIDTH-1:0] B,
  42. output reg [WIDTH-1:0] sum
  43. );
  44. parameter WIDTH_DIV2 = (WIDTH+1)/2;
  45. parameter WIDTH_REM = WIDTH - WIDTH_DIV2;
  46. wire [WIDTH_DIV2-1:0] A0_pt0;
  47. wire [WIDTH_REM-1:0] A0_pt1;
  48. wire [WIDTH_DIV2-1:0] B0_pt0;
  49. wire [WIDTH_REM-1:0] B0_pt1;
  50. assign {A0_pt1, A0_pt0} = A;
  51. assign {B0_pt1, B0_pt0} = B;
  52. reg [WIDTH_DIV2:0] C0_pt0;
  53. reg [WIDTH_REM-1:0] C0_pt1;
  54. always @(posedge clk) begin
  55. C0_pt0 <= {1'b0, A0_pt0} + {1'b0, B0_pt0};
  56. C0_pt1 <= A0_pt1 + B0_pt1;
  57. sum <= {C0_pt1+{6'b0, C0_pt0[WIDTH_DIV2]}, C0_pt0[WIDTH_DIV2-1:0]};
  58. end
  59. endmodule
  60. */
  61. module compare_gt #(
  62. parameter WIDTH = 16
  63. ) (
  64. input wire clk,
  65. input wire [WIDTH-1:0] A,
  66. input wire [WIDTH-1:0] B,
  67. output reg was_gt,
  68. output reg was_eq
  69. );
  70. generate
  71. if (WIDTH <= 2) begin : base_case
  72. // Base case: direct 2-bit comparison
  73. always @(posedge clk) begin
  74. was_gt <= A > B;
  75. was_eq <= A == B;
  76. end
  77. end else begin : recursive_case
  78. // Recursive submodules for upper & lower halves
  79. reg gt_upper, eq_upper, gt_lower, eq_lower;
  80. compare_gt #(WIDTH-WIDTH/2) upper (
  81. .clk(clk),
  82. .A(A[WIDTH-1:WIDTH/2]),
  83. .B(B[WIDTH-1:WIDTH/2]),
  84. .was_gt(gt_upper),
  85. .was_eq(eq_upper)
  86. );
  87. compare_gt #(WIDTH/2) lower (
  88. .clk(clk),
  89. .A(A[WIDTH/2-1:0]),
  90. .B(B[WIDTH/2-1:0]),
  91. .was_gt(gt_lower),
  92. .was_eq(eq_lower)
  93. );
  94. always @(posedge clk) begin
  95. was_gt <= gt_upper | (eq_upper & gt_lower);
  96. was_eq <= eq_upper & eq_lower;
  97. end
  98. end
  99. endgenerate
  100. endmodule
  101. //module compare_gt#(
  102. // parameter WIDTH = 16
  103. //)(
  104. // input wire clk,
  105. //
  106. // input wire [WIDTH-1:0] A,
  107. // input wire [WIDTH-1:0] B,
  108. //
  109. // output reg [0:0] was_gt //1 if A was greater than B 3 ticks ago
  110. //);
  111. // parameter WIDTH_DIV4 = (WIDTH+3)/4;
  112. // parameter WIDTH_REM = WIDTH - WIDTH_DIV4*3;
  113. //
  114. // reg [WIDTH_DIV4-1:0] A0_pt0x, A0_pt1x, A0_pt2x;
  115. // reg [WIDTH_REM-1:0] A0_pt3x;
  116. //
  117. // reg [WIDTH_DIV4-1:0] B0_pt0x, B0_pt1x, B0_pt2x;
  118. // reg [WIDTH_REM-1:0] B0_pt3x;
  119. //
  120. // reg [WIDTH_DIV4-1:0] A0_pt0y, A0_pt1y, A0_pt2y;
  121. // reg [WIDTH_REM-1:0] A0_pt3y;
  122. //
  123. // reg [WIDTH_DIV4-1:0] B0_pt0y, B0_pt1y, B0_pt2y;
  124. // reg [WIDTH_REM-1:0] B0_pt3y;
  125. //
  126. // //assign {A0_pt3, A0_pt2, A0_pt1, A0_pt0} = Ab;
  127. // //assign {B0_pt3, B0_pt2, B0_pt1, B0_pt0} = Bb;
  128. //
  129. // reg pt0_gt, pt1_gt, pt2_gt, pt3_gt;
  130. // reg pt0_eq, pt1_eq, pt2_eq, pt3_eq;
  131. //
  132. // reg pt01_eq, pt23_eq;
  133. // reg pt01_gt, pt23_gt;
  134. //
  135. // reg [WIDTH-1:0] Ab, Bb; // buffer regs for shorter wires
  136. //
  137. // always @(posedge clk) begin
  138. // Ab <= A;
  139. // Bb <= B;
  140. //
  141. // {A0_pt3x, A0_pt2x, A0_pt1x, A0_pt0x} <= Ab;
  142. // {B0_pt3x, B0_pt2x, B0_pt1x, B0_pt0x} <= Bb;
  143. //
  144. // {A0_pt3y, A0_pt2y, A0_pt1y, A0_pt0y} <= Ab;
  145. // {B0_pt3y, B0_pt2y, B0_pt1y, B0_pt0y} <= Bb;
  146. //
  147. // pt0_gt <= A0_pt0x>B0_pt0x;
  148. // pt1_gt <= A0_pt1x>B0_pt1x;
  149. // pt2_gt <= A0_pt2x>B0_pt2x;
  150. // pt3_gt <= A0_pt3x>B0_pt3x;
  151. //
  152. // pt0_eq <= A0_pt0y==B0_pt0y;
  153. // pt1_eq <= A0_pt1y==B0_pt1y;
  154. // pt2_eq <= A0_pt2y==B0_pt2y;
  155. // pt3_eq <= A0_pt3y==B0_pt3y;
  156. //
  157. // pt01_eq <= pt0_eq & pt1_eq;
  158. // pt01_gt <= pt1_gt | (pt1_eq & pt0_gt);
  159. //
  160. // pt23_eq <= pt2_eq & pt3_eq;
  161. // pt23_gt <= pt3_gt | (pt3_eq & pt2_gt);
  162. //
  163. // was_gt <= pt23_gt | (pt23_eq & pt01_gt);
  164. // end
  165. //
  166. //endmodule
  167. module cycle_trigger#(
  168. parameter WIDTH = 16
  169. ) (
  170. input wire /*nrst,*/ clk,
  171. input wire [WIDTH-1:0] period,
  172. output reg [0:0] start_cycle,
  173. output reg [0:0] half_cycle,
  174. output reg [2:0] trig_out
  175. );
  176. reg [WIDTH-1:0] counter;
  177. reg [WIDTH-1:0] counter_delayed;// just to make placement easier - less branches from counter
  178. reg [WIDTH-1:0] period_div2;
  179. reg [WIDTH-1:0] period_shadow;
  180. wire zero;
  181. always @(posedge clk /*or negedge nrst*/) begin
  182. /*if (!nrst) begin
  183. counter <= 0;
  184. //period_div2 <= 16'h0;
  185. high_match_a <= 0;
  186. high_match_b <= 0;
  187. half_match_a <= 0;
  188. half_match_b <= 0;
  189. start_cycle <= 0;
  190. half_cycle <= 0;
  191. trig_out <= 0;
  192. end else begin*/
  193. if(zero) begin
  194. start_cycle <= 1;
  195. period_div2 <= period>>1;
  196. period_shadow <= period;
  197. end else begin
  198. start_cycle <= 0;
  199. end
  200. if (start_cycle) begin
  201. counter <= period_shadow;
  202. end else begin
  203. counter <= counter-1;
  204. end
  205. counter_delayed <= counter;
  206. //end //nrst
  207. end
  208. compare_eq#(.WIDTH(WIDTH))cmp_zero(
  209. .clk(clk),
  210. .A(counter_delayed),
  211. .B(0),
  212. .was_eq(zero)
  213. );
  214. compare_eq#(.WIDTH(WIDTH))cmp_half(
  215. .clk(clk),
  216. .A(counter_delayed),
  217. .B(period_div2),
  218. .was_eq(half_cycle)
  219. );
  220. compare_eq#(.WIDTH(WIDTH))cmp0(
  221. .clk(clk),
  222. .A(counter_delayed),
  223. .B(3),
  224. .was_eq(trig_out[0])
  225. );
  226. compare_eq#(.WIDTH(WIDTH))cmp1(
  227. .clk(clk),
  228. .A(counter_delayed),
  229. .B(3),
  230. .was_eq(trig_out[1])
  231. );
  232. compare_eq#(.WIDTH(WIDTH))cmp2(
  233. .clk(clk),
  234. .A(counter_delayed),
  235. .B(9),
  236. .was_eq(trig_out[2])
  237. );
  238. endmodule
  239. /*module continous_pwm_gen#(
  240. parameter WIDTH = 16
  241. ) (
  242. input wire nrst, clk,
  243. input wire [WIDTH-1:0] period,
  244. input wire [WIDTH-1:0] delay,
  245. output reg [0:0] pwm_out
  246. );
  247. reg [WIDTH-1:0] counter;
  248. reg [WIDTH-1:0] _period;
  249. reg [WIDTH-1:0] _delay;
  250. reg [0:0] next_out;
  251. reg [0:0] is_last_tick;
  252. reg [0:0] is_last_tickA;
  253. reg [0:0] is_last_tickB;
  254. reg [0:0] is_mid_tick;
  255. // Counter logic
  256. always @(posedge clk or negedge nrst) begin
  257. if (!nrst) begin
  258. counter <= 0;
  259. pwm_out <= 0;
  260. next_out <= 0;
  261. _period <= 0;
  262. _delay <= 0;
  263. is_last_tick <= 0;
  264. is_last_tickA <= 0;
  265. is_last_tickB <= 0;
  266. end else begin
  267. _period <= period;
  268. _delay <= delay;
  269. is_last_tickA <= counter[WIDTH-1:8]==0;
  270. is_last_tickB <= counter[7:0]==2;
  271. is_last_tick <= is_last_tickA&is_last_tickB;
  272. if (is_last_tick) begin
  273. counter <= _period;
  274. end else begin
  275. counter <= counter-1;
  276. end
  277. next_out <= is_last_tick;
  278. pwm_out <= next_out;
  279. end
  280. end
  281. endmodule*/
  282. module single_shot_gen#(
  283. parameter WIDTH = 16
  284. )(
  285. input wire nrst,clk,
  286. input wire trigger,
  287. input [WIDTH-1:0] delay,
  288. input [WIDTH-1:0] period,
  289. output reg pwm_out
  290. );
  291. reg [WIDTH-1:0] counter;
  292. reg [WIDTH-1:0] counter2; // Buffer register for better timing
  293. wire pwm_gt;
  294. always @(posedge clk) begin
  295. if (trigger) begin
  296. counter <= period; //########TODO WARNING: counter will underflow which may trigger unwanted pulses. Add logic to fix that.
  297. end else begin
  298. counter <= counter - 1;
  299. end
  300. // Buffer register to reduce timing pressure
  301. counter2 <= counter;
  302. // Output register to reduce delay
  303. pwm_out <= pwm_gt;
  304. end
  305. // Parallel comparison with buffered counter
  306. wire unused;
  307. compare_gt #(.WIDTH(WIDTH)) cmp_out (
  308. .clk(clk),
  309. .A(delay),
  310. .B(counter2),
  311. .was_gt(pwm_gt),
  312. .was_eq(unused)
  313. );
  314. endmodule
  315. /*module phase_delay#(
  316. parameter WIDTH = 16,
  317. parameter FORWARD_DATA_WIDTH = 16
  318. )(
  319. input wire nrst, clk,
  320. input wire in_trig,
  321. input [WIDTH-1:0] delay,
  322. input [FORWARD_DATA_WIDTH-1:0] in_data_fwd,
  323. output wire out_trig,
  324. output reg [FORWARD_DATA_WIDTH-1:0] out_data_fwd
  325. );
  326. reg [WIDTH-1:0] counter;
  327. reg [0:0] is_counting;
  328. reg [WIDTH-1:0] delay_latched;
  329. always @(posedge clk or negedge nrst) begin
  330. if (!nrst) begin
  331. counter <= 0;
  332. is_counting <=0;
  333. delay_latched <=0;
  334. end else begin
  335. if (is_counting) begin
  336. if ((counter+1) >= delay_latched) begin
  337. counter <= 0;
  338. is_counting <= 0;
  339. end else begin
  340. counter <= counter+1;
  341. end
  342. end else begin
  343. if (in_trig) begin
  344. is_counting <= 1;
  345. out_data_fwd <= in_data_fwd;
  346. delay_latched <= delay;
  347. end
  348. end
  349. end
  350. end
  351. assign out_trig=((counter+1)>=delay) && is_counting;
  352. endmodule*/
  353. module simple_counter#(
  354. parameter WIDTH = 14
  355. )(
  356. input wire clk,
  357. input wire trigger,
  358. input wire if_counting,
  359. output reg [WIDTH-1:0] cnt_out
  360. );
  361. parameter HALF_WIDTH=7;
  362. reg [HALF_WIDTH-1:0] cnt1, cnt0;
  363. reg cnt0f;
  364. always @(posedge clk /*or negedge nrst*/) begin
  365. if (trigger) begin
  366. cnt1 <= 0;
  367. cnt0 <= 0;
  368. cnt0f <= 0;
  369. end else begin
  370. //cnt1f <= &cnt1;
  371. cnt0f <= &cnt0;
  372. if(if_counting) begin
  373. cnt0 <= cnt0+1;
  374. if(cnt0f) begin
  375. cnt1 <= cnt1+1;
  376. end
  377. end
  378. cnt_out <= {cnt1, cnt0};
  379. end
  380. end
  381. endmodule
  382. module pulse_train_gen#(
  383. parameter TOTAL_PERIOD_WIDTH = 14,
  384. parameter SINGLE_CYCLE_WIDTH = 8,
  385. parameter PULSE_COUNTER_WIDTH = 8
  386. )(
  387. input wire nrst, clk,
  388. input wire trigger,
  389. input [PULSE_COUNTER_WIDTH-1:0] npuls,
  390. input [SINGLE_CYCLE_WIDTH-1:0] period,
  391. input [SINGLE_CYCLE_WIDTH-1:0] duty,
  392. output reg [0:0] pwm_out
  393. );
  394. reg [TOTAL_PERIOD_WIDTH-1:0] counter;//total waveform counter
  395. reg [TOTAL_PERIOD_WIDTH-1:0] counter2;
  396. reg [TOTAL_PERIOD_WIDTH-1:0] cycle_threshold;
  397. reg [TOTAL_PERIOD_WIDTH-1:0] cycle_threshold2;
  398. reg [TOTAL_PERIOD_WIDTH-1:0] next_cycle_threshold;
  399. reg [PULSE_COUNTER_WIDTH-1:0] cycle_counter;
  400. reg [PULSE_COUNTER_WIDTH-1:0] next_cycle_counter;
  401. reg [SINGLE_CYCLE_WIDTH-1:0] _period;
  402. reg if_next_cycle;
  403. reg is_counting;
  404. reg is_counting2;
  405. always @(posedge clk /*or negedge nrst*/) begin
  406. /*if (!nrst) begin
  407. is_counting <= 0;
  408. end else begin*/
  409. if(trigger) begin
  410. //counter <= 0;
  411. cycle_threshold <= {6'b0, _period};
  412. cycle_counter <= npuls;
  413. end else begin
  414. //counter <= counter + is_counting2;
  415. end
  416. counter2 <= counter;
  417. _period <= period;
  418. if(if_next_cycle & is_counting2) begin
  419. cycle_counter <= next_cycle_counter;
  420. cycle_threshold <= next_cycle_threshold;
  421. end
  422. next_cycle_counter <= cycle_counter-1;
  423. is_counting <= |next_cycle_counter;
  424. is_counting2 <= is_counting;
  425. pwm_out <= if_next_cycle;
  426. cycle_threshold2 <= cycle_threshold;
  427. //end
  428. end
  429. simple_counter cnt(
  430. .clk(clk),
  431. .trigger(trigger),
  432. .if_counting(is_counting2),
  433. .cnt_out(counter)
  434. );
  435. compare_eq#(.WIDTH(TOTAL_PERIOD_WIDTH))cmp_cycle(
  436. .clk(clk),
  437. .A(counter2),
  438. .B(cycle_threshold2),
  439. .was_eq(if_next_cycle)
  440. );
  441. /*add#(
  442. .WIDTH(TOTAL_PERIOD_WIDTH)
  443. )cycle_th(
  444. .clk(clk),
  445. .A(cycle_threshold2),
  446. .B({6'b0, _period}),
  447. .sum(next_cycle_threshold)
  448. );*/
  449. endmodule
  450. module pulse_extender(
  451. input wire clk,
  452. input wire trigger,
  453. output reg out
  454. );
  455. reg [3:0] cnt;
  456. reg [3:0] next_cnt;
  457. reg is_counting;
  458. always @(posedge clk) begin
  459. is_counting <= (cnt>0) & is_counting;
  460. //next_cnt <= cnt-1;
  461. if(trigger) begin
  462. cnt <= 15;
  463. //next_cnt <= 15;
  464. is_counting <= 1;
  465. end else begin
  466. if(is_counting) begin
  467. cnt <= cnt-1;//next_cnt;
  468. end
  469. end
  470. out <= is_counting;
  471. end
  472. endmodule
  473. parameter [1:0] ODD_TRAIN_FORCE_OFF = 2'b00;
  474. parameter [1:0] ODD_TRAIN_ENA_CONTROL = 2'b01;
  475. parameter [1:0] ODD_TRAIN_FORCE_ON = 2'b10;
  476. module three_signal#(
  477. parameter FAST_PWM_WIDTH=8,
  478. parameter PULSE_COUNTER_WIDTH=8,
  479. parameter SLOW_PWM_WIDTH=14
  480. )(
  481. input wire nrst, clk,
  482. input [SLOW_PWM_WIDTH-1:0] period1,
  483. input [SLOW_PWM_WIDTH-1:0] delay1,
  484. input [SLOW_PWM_WIDTH-1:0] period2,
  485. input [SLOW_PWM_WIDTH-1:0] delay2,
  486. input [FAST_PWM_WIDTH-1:0] period3,
  487. input [FAST_PWM_WIDTH-1:0] duty3,
  488. input [SLOW_PWM_WIDTH-1:0] delay3,//delay is wrt slow pwm, thus longer bit length
  489. input [PULSE_COUNTER_WIDTH-1:0] npuls3,
  490. input /*odd_train_flag_t*/ wire [1:0] odd_train_flag,
  491. input wire ena_odd_out3,
  492. output reg Out1,
  493. output reg Out2,
  494. output reg Out3
  495. );
  496. reg [SLOW_PWM_WIDTH-1:0] _period1;
  497. reg [SLOW_PWM_WIDTH-1:0] _delay1;
  498. reg [SLOW_PWM_WIDTH-1:0] _duty1;
  499. reg [SLOW_PWM_WIDTH-1:0] _period2;
  500. reg [SLOW_PWM_WIDTH-1:0] _delay2;
  501. reg [FAST_PWM_WIDTH-1:0] _period3;
  502. reg [FAST_PWM_WIDTH-1:0] _duty3;
  503. reg [SLOW_PWM_WIDTH-1:0] _delay3;//delay is wrt slow pwm, thus longer bit length
  504. reg [PULSE_COUNTER_WIDTH-1:0] _npuls3;
  505. reg /*odd_train_flag_t*/ [1:0] _odd_train_flag;
  506. reg _ena_odd_out3;
  507. wire _Out1;
  508. wire _Out2;
  509. wire _Out3;
  510. always @(posedge clk) begin
  511. _period1 <= period1 ;
  512. _delay1 <= delay1 ;
  513. _period2 <= period2 ;
  514. _delay2 <= delay2 ;
  515. _period3 <= period3 ;
  516. _duty3 <= duty3 ;
  517. _delay3 <= delay3 ;
  518. _npuls3 <= npuls3 ;
  519. _odd_train_flag <= odd_train_flag;
  520. _ena_odd_out3 <= ena_odd_out3 ;
  521. //TODO - output already as reg; no additional latency needed?
  522. Out1 <= _Out1;
  523. Out2 <= _Out2;
  524. Out3 <= _Out3;
  525. end
  526. //wire trigger_next_cycle;
  527. //wire trigger_even_cycle;
  528. //wire trigger_odd_cycle;
  529. //wire [SLOW_PWM_WIDTH-1:0] delay3_part1;
  530. //wire [SLOW_PWM_WIDTH-1:0] delay3_part234;
  531. //assign delay3_part234 = delay3>>2;
  532. //assign delay3_part1 = (delay3<4) ? 0 : (delay3 - (delay3_part234*3));
  533. wire [0:0] start_cycle;
  534. wire [0:0] half_cycle;
  535. wire [2:0] trig_out;
  536. cycle_trigger #(.WIDTH(SLOW_PWM_WIDTH)) cyc_trig(
  537. //.nrst(nrst),
  538. .clk(clk),
  539. .period(_period1),
  540. .start_cycle(start_cycle),
  541. .half_cycle(half_cycle),
  542. .trig_out(trig_out)
  543. );
  544. single_shot_gen #(.WIDTH(SLOW_PWM_WIDTH)) pwm1(
  545. .nrst(nrst),
  546. .clk(clk),
  547. .trigger(trig_out[0]),
  548. .delay(_delay1),
  549. .period(_period1),
  550. .pwm_out(_Out1)
  551. );
  552. single_shot_gen #(.WIDTH(SLOW_PWM_WIDTH)) pwm2(
  553. .nrst(nrst),
  554. .clk(clk),
  555. .trigger(trig_out[1]),
  556. .delay(_delay2),
  557. .period(_period2),
  558. .pwm_out(_Out2)
  559. );
  560. wire out3_tmp;
  561. pulse_train_gen#(
  562. .TOTAL_PERIOD_WIDTH(SLOW_PWM_WIDTH),
  563. .SINGLE_CYCLE_WIDTH(FAST_PWM_WIDTH),
  564. .PULSE_COUNTER_WIDTH(PULSE_COUNTER_WIDTH)
  565. )pwm3(
  566. .nrst(nrst),
  567. .clk(clk),
  568. .trigger(trig_out[2]),
  569. .npuls(_npuls3),
  570. .period(_period3),
  571. .duty(_duty3),
  572. .pwm_out(out3_tmp)
  573. );
  574. pulse_extender pext1(
  575. .clk(clk),
  576. .trigger(trig_out[0]),
  577. .out(_Out3)
  578. );
  579. /*wire trigger_delay_1_to_2;
  580. wire trigger_delay_2_to_3;
  581. wire trigger_delay_3_to_4;
  582. wire trigger_delay_4_to_pulse_train;
  583. localparam FORWARD_DATA_WIDTH = SLOW_PWM_WIDTH + PULSE_COUNTER_WIDTH + FAST_PWM_WIDTH + FAST_PWM_WIDTH;
  584. localparam DELAY_BITS_POS = PULSE_COUNTER_WIDTH + FAST_PWM_WIDTH + FAST_PWM_WIDTH;
  585. wire [FORWARD_DATA_WIDTH-1:0] data_1_to_2;
  586. wire [FORWARD_DATA_WIDTH-1:0] data_2_to_3;
  587. wire [FORWARD_DATA_WIDTH-1:0] data_3_to_4;
  588. wire [FORWARD_DATA_WIDTH-1:0] data_4_to_gen;
  589. assign trigger_odd_cycle =
  590. (odd_train_flag == ODD_TRAIN_ENA_CONTROL) ? trigger_next_cycle && ena_odd_out3 :
  591. (odd_train_flag == ODD_TRAIN_FORCE_ON) ? trigger_next_cycle :
  592. 0;
  593. wire [FAST_PWM_WIDTH-1:0] period3_gen;
  594. wire [FAST_PWM_WIDTH-1:0] duty3_gen;
  595. wire [PULSE_COUNTER_WIDTH-1:0] npuls3_gen;
  596. assign duty3_gen = data_4_to_gen[FAST_PWM_WIDTH-1:0];
  597. assign period3_gen = data_4_to_gen[FAST_PWM_WIDTH+FAST_PWM_WIDTH-1:FAST_PWM_WIDTH];
  598. assign npuls3_gen = data_4_to_gen[FAST_PWM_WIDTH+FAST_PWM_WIDTH+PULSE_COUNTER_WIDTH-1:FAST_PWM_WIDTH+FAST_PWM_WIDTH];*/
  599. endmodule