Skip to content

Commit 2dd5f96

Browse files
committed
lib/axi_pwm_gen: Update axi_pwm_gen logic to support non-load_confib-based synchronization
New mode: External synchronization using a signal that is based on a faster clock than the one of the axi_pwm_gen logic + without using the load_config register (continous offset-related synchronization - e.g. synchronization at 1 s by using a 1 Hz sync signal) Signed-off-by: Alin-Tudor Sferle <Alin-Tudor.Sferle@analog.com>
1 parent d4f33da commit 2dd5f96

File tree

8 files changed

+81
-17
lines changed

8 files changed

+81
-17
lines changed

library/axi_pwm_gen/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
####################################################################################
2-
## Copyright (c) 2018 - 2023 Analog Devices, Inc.
2+
## Copyright (c) 2018 - 2024 Analog Devices, Inc.
33
### SPDX short identifier: BSD-1-Clause
44
## Auto-generated, do not modify!
55
####################################################################################
@@ -21,6 +21,7 @@ XILINX_LIB_DEPS += util_cdc
2121
INTEL_DEPS += ../intel/common/up_rst_constr.sdc
2222
INTEL_DEPS += ../util_cdc/sync_bits.v
2323
INTEL_DEPS += ../util_cdc/sync_data.v
24+
INTEL_DEPS += ../util_cdc/sync_event.v
2425
INTEL_DEPS += axi_pwm_gen_constr.sdc
2526
INTEL_DEPS += axi_pwm_gen_hw.tcl
2627

library/axi_pwm_gen/axi_pwm_gen.sv

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ***************************************************************************
22
// ***************************************************************************
3-
// Copyright (C) 2021-2023 Analog Devices, Inc. All rights reserved.
3+
// Copyright (C) 2021-2024 Analog Devices, Inc. All rights reserved.
44
//
55
// In this HDL repository, there are many different and unique modules, consisting
66
// of various HDL (Verilog or VHDL) components. The individual modules are
@@ -26,7 +26,7 @@
2626
//
2727
// 2. An ADI specific BSD license, which can be found in the top level directory
2828
// of this repository (LICENSE_ADIBSD), and also on-line at:
29-
// https://github.com/analogdevicesinc/hdl/blob/master/LICENSE_ADIBSD
29+
// https://github.com/analogdevicesinc/hdl/blob/main/LICENSE_ADIBSD
3030
// This will allow to generate bit files and not release the source code,
3131
// as long as it attaches to an ADI device.
3232
//
@@ -41,6 +41,8 @@ module axi_pwm_gen #(
4141
parameter N_PWMS = 1,
4242
parameter PWM_EXT_SYNC = 0,
4343
parameter EXT_ASYNC_SYNC = 0,
44+
parameter EXT_SYNC_NO_LOAD_CONFIG = 0,
45+
parameter EXT_SYNC_FASTER_CLK = 0,
4446
parameter PULSE_0_WIDTH = 7,
4547
parameter PULSE_1_WIDTH = 7,
4648
parameter PULSE_2_WIDTH = 7,
@@ -117,6 +119,9 @@ module axi_pwm_gen #(
117119
input ext_clk,
118120
input ext_sync,
119121

122+
input ext_sync_faster_clk,
123+
input clk_ext_sync,
124+
120125
output pwm_0,
121126
output pwm_1,
122127
output pwm_2,
@@ -222,6 +227,7 @@ module axi_pwm_gen #(
222227
wire pwm_gen_resetn;
223228
wire ext_sync_s;
224229
wire pause_cnt;
230+
wire sync_event_o;
225231

226232
assign up_clk = s_axi_aclk;
227233
assign up_rstn = s_axi_aresetn;
@@ -281,20 +287,34 @@ module axi_pwm_gen #(
281287
// offset counter
282288

283289
always @(posedge clk) begin
284-
if (offset_alignment == 1'b1 || pwm_gen_resetn == 1'b0) begin
285-
offset_cnt <= 32'd0;
290+
if (EXT_SYNC_NO_LOAD_CONFIG) begin
291+
if (offset_alignment == 1'b1 || pwm_gen_resetn == 1'b0 || sync_event_o == 1'b1) begin
292+
offset_cnt <= 32'd0;
293+
end else begin
294+
offset_cnt <= offset_cnt + 1'b1;
295+
end
286296
end else begin
287-
offset_cnt <= offset_cnt + 1'b1;
297+
if (offset_alignment == 1'b1 || pwm_gen_resetn == 1'b0) begin
298+
offset_cnt <= 32'd0;
299+
end else begin
300+
offset_cnt <= offset_cnt + 1'b1;
301+
end
288302
end
289303

290304
if (pwm_gen_resetn == 1'b0) begin
291305
offset_alignment <= 1'b0;
292306
end else begin
307+
// case with no required load_config for the offset_alignment using the
308+
// captured ext_sync
309+
if (EXT_SYNC_NO_LOAD_CONFIG) begin
310+
offset_alignment <= (load_config_s == 1'b1) ? 1'b1 : (offset_alignment & !pause_cnt);
293311
// when using external sync an offset alignment can be done only
294312
// after all pwm counters are paused(load_config)/reseated
295-
offset_alignment <= (load_config_s == 1'b1) ? 1'b1 :
296-
offset_alignment &
297-
(ext_sync_s ? 1'b1 : !pause_cnt);
313+
end else begin
314+
offset_alignment <= (load_config_s == 1'b1) ? 1'b1 :
315+
offset_alignment &
316+
(ext_sync_s ? 1'b1 : !pause_cnt);
317+
end
298318
end
299319
end
300320

@@ -318,6 +338,7 @@ module axi_pwm_gen #(
318338
for (i = 0; i <= 15; i = i + 1) begin: pwm_cnt
319339
if (i <= PWMS) begin
320340
axi_pwm_gen_1 #(
341+
.EXT_SYNC_NO_LOAD_CONFIG (EXT_SYNC_NO_LOAD_CONFIG),
321342
.PULSE_WIDTH (PULSE_WIDTH_G[i]),
322343
.PULSE_PERIOD (PULSE_PERIOD_G[i])
323344
) i_axi_pwm_gen_1 (
@@ -326,6 +347,7 @@ module axi_pwm_gen #(
326347
.pulse_width (pwm_width_s[i]),
327348
.pulse_period (pwm_period_s[i]),
328349
.load_config (load_config_s),
350+
.ext_sync_edge (sync_event_o),
329351
.sync (sync[i]),
330352
.pulse (pwm[i]),
331353
.pulse_armed (pwm_armed[i]));
@@ -360,6 +382,16 @@ module axi_pwm_gen #(
360382
assign pwm_14 = pwm[14];
361383
assign pwm_15 = pwm[15];
362384

385+
generate
386+
if (EXT_SYNC_FASTER_CLK) begin
387+
sync_event sync_ext_sync_faster_clk (
388+
.in_clk (clk_ext_sync),
389+
.out_clk (ext_clk),
390+
.in_event (ext_sync_faster_clk),
391+
.out_event (sync_event_o));
392+
end
393+
endgenerate
394+
363395
up_axi #(
364396
.AXI_ADDRESS_WIDTH(16)
365397
) i_up_axi (

library/axi_pwm_gen/axi_pwm_gen_1.v

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ***************************************************************************
22
// ***************************************************************************
3-
// Copyright (C) 2021-2023 Analog Devices, Inc. All rights reserved.
3+
// Copyright (C) 2021-2024 Analog Devices, Inc. All rights reserved.
44
//
55
// In this HDL repository, there are many different and unique modules, consisting
66
// of various HDL (Verilog or VHDL) components. The individual modules are
@@ -26,7 +26,7 @@
2626
//
2727
// 2. An ADI specific BSD license, which can be found in the top level directory
2828
// of this repository (LICENSE_ADIBSD), and also on-line at:
29-
// https://github.com/analogdevicesinc/hdl/blob/master/LICENSE_ADIBSD
29+
// https://github.com/analogdevicesinc/hdl/blob/main/LICENSE_ADIBSD
3030
// This will allow to generate bit files and not release the source code,
3131
// as long as it attaches to an ADI device.
3232
//
@@ -35,6 +35,7 @@
3535
`timescale 1ns/1ps
3636

3737
module axi_pwm_gen_1 #(
38+
parameter EXT_SYNC_NO_LOAD_CONFIG = 0,
3839
// the width and period are defined in number of clock cycles
3940
parameter PULSE_WIDTH = 7,
4041
parameter PULSE_PERIOD = 100000000
@@ -45,6 +46,7 @@ module axi_pwm_gen_1 #(
4546
input [31:0] pulse_width,
4647
input [31:0] pulse_period,
4748
input load_config,
49+
input ext_sync_edge,
4850
input sync,
4951

5052
output pulse,
@@ -64,6 +66,7 @@ module axi_pwm_gen_1 #(
6466

6567
// internal wires
6668

69+
wire ext_sync_load_cfg;
6770
wire phase_align;
6871
wire end_of_period;
6972
wire end_of_pulse;
@@ -73,6 +76,8 @@ module axi_pwm_gen_1 #(
7376

7477
assign pulse_enable = (pulse_period_d != 32'd0) ? 1'b1 : 1'b0;
7578

79+
assign ext_sync_load_config = (EXT_SYNC_NO_LOAD_CONFIG) ? ext_sync_edge : 1'b0;
80+
7681
// flop the desired period
7782

7883
always @(posedge clk) begin
@@ -103,6 +108,8 @@ module axi_pwm_gen_1 #(
103108
end else begin
104109
if (load_config == 1'b1) begin
105110
phase_align_armed <= sync;
111+
end else if (ext_sync_edge == 1'b1) begin
112+
phase_align_armed <= sync;
106113
end else begin
107114
phase_align_armed <= phase_align_armed & sync;
108115
end

library/axi_pwm_gen/axi_pwm_gen_constr.sdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
## Copyright (C) 2021-2023 Analog Devices, Inc. All rights reserved.
2+
## Copyright (C) 2021-2024 Analog Devices, Inc. All rights reserved.
33
### SPDX short identifier: ADIBSD
44
###############################################################################
55

library/axi_pwm_gen/axi_pwm_gen_constr.ttcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
## Copyright (C) 2021-2023 Analog Devices, Inc. All rights reserved.
2+
## Copyright (C) 2021-2024 Analog Devices, Inc. All rights reserved.
33
# SPDX short identifier: ADIBSD
44
###############################################################################
55

library/axi_pwm_gen/axi_pwm_gen_hw.tcl

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
## Copyright (C) 2023 Analog Devices, Inc. All rights reserved.
2+
## Copyright (C) 2023-2024 Analog Devices, Inc. All rights reserved.
33
### SPDX short identifier: ADIBSD
44
###############################################################################
55

@@ -30,6 +30,8 @@ ad_ip_parameter ASYNC_CLK_EN INTEGER 1
3030
ad_ip_parameter N_PWMS INTEGER 1
3131
ad_ip_parameter PWM_EXT_SYNC INTEGER 0
3232
ad_ip_parameter EXT_ASYNC_SYNC INTEGER 0
33+
ad_ip_parameter EXT_SYNC_FASTER_CLK 0
34+
ad_ip_parameter EXT_SYNC_NO_LOAD_CONFIG 0
3335
ad_ip_parameter PULSE_0_WIDTH INTEGER 7
3436
ad_ip_parameter PULSE_1_WIDTH INTEGER 7
3537
ad_ip_parameter PULSE_2_WIDTH INTEGER 7
@@ -87,6 +89,8 @@ ad_ip_intf_s_axi s_axi_aclk s_axi_aresetn 16
8789
# external clock and external sync
8890
ad_interface clock ext_clk input 1
8991
ad_interface signal ext_sync input 1
92+
ad_interface clock clk_ext_sync input 1
93+
ad_interface signal ext_sync_faster_clk input 1
9094

9195
# output signals
9296
for {set i 0} {$i < 16} {incr i} {

library/axi_pwm_gen/axi_pwm_gen_ip.tcl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
## Copyright (C) 2021-2023 Analog Devices, Inc. All rights reserved.
2+
## Copyright (C) 2021-2024 Analog Devices, Inc. All rights reserved.
33
### SPDX short identifier: ADIBSD
44
###############################################################################
55

@@ -100,6 +100,20 @@ set_property -dict [list \
100100
"widget" "checkBox" \
101101
] [ipgui::get_guiparamspec -name "EXT_ASYNC_SYNC" -component $cc]
102102

103+
ipgui::add_param -name "EXT_SYNC_NO_LOAD_CONFIG" -component $cc -parent $page0
104+
set_property -dict [list \
105+
"display_name" "External synchronization without load_config" \
106+
"tooltip" "NOTE: If active the external synchronization would be made without load_config." \
107+
"widget" "checkBox" \
108+
] [ipgui::get_guiparamspec -name "EXT_SYNC_NO_LOAD_CONFIG" -component $cc]
109+
110+
ipgui::add_param -name "EXT_SYNC_FASTER_CLK" -component $cc -parent $page0
111+
set_property -dict [list \
112+
"display_name" "External sync based on a faster clock" \
113+
"tooltip" "NOTE: If active the external sync would be based on a faster clock than the pwm_gen logic." \
114+
"widget" "checkBox" \
115+
] [ipgui::get_guiparamspec -name "EXT_SYNC_FASTER_CLK" -component $cc]
116+
103117
# Maximum 16 pwms
104118
for {set i 0} {$i < 16} {incr i} {
105119
ipgui::add_param -name "PULSE_${i}_WIDTH" -component $cc -parent $page0
@@ -150,6 +164,12 @@ for {set i 0} {$i < 16} {incr i} {
150164
adi_set_ports_dependency "ext_sync" \
151165
"(spirit:decode(id('MODELPARAM_VALUE.PWM_EXT_SYNC')) == 1)"
152166

167+
adi_set_ports_dependency "ext_sync_faster_clk" \
168+
"(spirit:decode(id('MODELPARAM_VALUE.EXT_SYNC_FASTER_CLK')) == 1)"
169+
170+
adi_set_ports_dependency "clk_ext_sync" \
171+
"(spirit:decode(id('MODELPARAM_VALUE.EXT_SYNC_FASTER_CLK')) == 1)"
172+
153173
set_property driver_value 0 [ipx::get_ports -filter "direction==in" -of_objects $cc]
154174

155175
## Save the modifications

library/axi_pwm_gen/axi_pwm_gen_regmap.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ***************************************************************************
22
// ***************************************************************************
3-
// Copyright (C) 2021-2023 Analog Devices, Inc. All rights reserved.
3+
// Copyright (C) 2021-2024 Analog Devices, Inc. All rights reserved.
44
//
55
// In this HDL repository, there are many different and unique modules, consisting
66
// of various HDL (Verilog or VHDL) components. The individual modules are
@@ -26,7 +26,7 @@
2626
//
2727
// 2. An ADI specific BSD license, which can be found in the top level directory
2828
// of this repository (LICENSE_ADIBSD), and also on-line at:
29-
// https://github.com/analogdevicesinc/hdl/blob/master/LICENSE_ADIBSD
29+
// https://github.com/analogdevicesinc/hdl/blob/main/LICENSE_ADIBSD
3030
// This will allow to generate bit files and not release the source code,
3131
// as long as it attaches to an ADI device.
3232
//

0 commit comments

Comments
 (0)