05-24-2018 11:50 PM - edited 05-24-2018 11:56 PM
I'm trying to co-simulate the verilog mppt with photovoltaic system in simulink using system generator 2018
but i'm getting NAN output anyway.
here's my code:
module m2(
input [23:0] v,
input [23:0] i,
output reg [23:0] d,
input clk,
input ce,
input enable
);
localparam dinit =24'b000000000000_100000000000;
localparam dmax =24'b000000000000_100001010001;
localparam dmin =24'b000000000000_011010111000;
localparam deltad=24'b000000000000_000000000001 ;
wire [47:0] p;
reg [47:0] pold;
reg [23:0] vold;
reg [23:0] iold;
reg [23:0] dold;
assign p=v*i;
// assign v=v*2**12;
// assign d=d/(2**12);
always@(posedge clk)
begin
if (v!=0 & i!=0 & enable!=0 & d<dmax & d>dmin)
begin
if(p<pold && v<vold)
d<=d-deltad;
if(p<pold && v>vold)
d<=d+deltad;
if(p>pold && v<vold)
d<=d+deltad;
if(p>pold && v>vold)
d<=d-deltad;
end
if (enable==1)
begin
vold<=v;
iold<=i;
pold<=p;
dold<=d;
end
else
begin
vold<=0;
pold<=0;
iold<=0;
dold<=dinit;
end
end
endmodule
tnx
05-29-2018 05:48 AM
Hi @mkhezeli,
You output d is not initialized. So you are doing computation something which does not have a value.
It might be the issue.