I am designing the FPGA-based control for a power-electronic AC/DC converter. This converter has five output voltage levels, so it has 8 switching instances. The levels are given by h, mh, z, ml, l
, for high, mid-high, zero, mid-low, and low, respectively. I am using a time-limited counter as the theta
input to reset every 0.02-s, for a 50-Hz reset (so for the 1e-8-s time-step, there are 2e6 time-steps for the 50-Hz cycle). So, these 8 switching instances are also in terms of time-steps. Moreover, I am using 3 toggle-switch inputs to determine the AC voltage amplitude, i.e., lvl_select
. Therefore, there are 2^3=8 total operating modes, each requiring the 8 switching instances. These switching angles are labelled angle1, angle2,.., angle8
Sorry for the background, as it isn't quite necessary for my question.
The way I have implemented this code (in short-hand) is:
input [31:0] theta;
input [2:0] lvl_select;
wire [31:0] angle1, angle2, ..., angle8 [0:7];
output reg h, mh, z, ml, l;
integer i;
assign angle1[0] = 95549;
assign angle2[0] = 904451;
.
.
.
assign angle8[0] = 1914451;
.
.
.
assign angle1[7] = 72345;
assign angle2[7] = 186932;
.
.
.
assign angle8[7] = 1574124;
always @ (posedge clk)
begin
h = 0;
mh = 0;
z = 0;
ml = 0;
l = 0;
for(i = 0; i < 8; i = i+1)
begin
if (i == lvl_select)
begin
if(theta < angle1[i])
z = 1;
else if (theta < angle2[i])
mh = 1;
else if (theta < angle3[i])
h = 1;
else if (theta < angle4[i])
mh = 1;
else if (theta < angle5[i])
z = 1;
else if (theta < angle6[i])
ml = 1;
else if (theta < angle7[i])
l = 1;
else if (theta < angle8[i])
ml = 1;
else
z = 1;
end
end
end
This is the code in a nutshell. I haven't verified that it works yet, but I think it should (unless you can see why it shouldn't?).
My question is: is there a way to add all of the 64 angle
values in a smarter way? Right now there are 64 inputs, which I may want to expand in the future. I have the values in an excel sheet/MATLAB array right now. Please let me know if you have dealt with similar things in the past, thanks a lot!