[NET-EVM] 확장 테스트 보드에는 PWM제어 LED가 연결되어 있으므로 PWM테스트 하기에 유용하다.
FPGA에서 PWM출력 테스트를 해 보았다. 아무래도 FPGA를 이용하면 PWM 주파수나 채널을 원하는데로(게이트가 충분해야 겠지만) 간단히 추가 할 수 있기 때문에 유용하게 사용할 수 있다.
PWM 출력 Verilog 소스
module f_pwm(iClk, iRst, iFreq, iPeriod, oOut);
input iClk;
input iRst;
input [7:0] iFreq;
input [7:0] iPeriod;
output oOut;
reg [7:0] pwmcnt;
reg out_pwm;
reg oOut;
always @ (posedge iClk or negedge iRst)
if (!iRst)
begin
pwmcnt <= 0;
oOut <= 0;
end
else
begin
pwmcnt = pwmcnt + 1;
if (pwmcnt <= iPeriod)oOut=1;
else oOut = 0;
if(pwmcnt >= iFreq)pwmcnt=0;
end
endmodule
input iClk;
input iRst;
input [7:0] iFreq;
input [7:0] iPeriod;
output oOut;
reg [7:0] pwmcnt;
reg out_pwm;
reg oOut;
always @ (posedge iClk or negedge iRst)
if (!iRst)
begin
pwmcnt <= 0;
oOut <= 0;
end
else
begin
pwmcnt = pwmcnt + 1;
if (pwmcnt <= iPeriod)oOut=1;
else oOut = 0;
if(pwmcnt >= iFreq)pwmcnt=0;
end
endmodule
EP1C3T EVM FPGA에서 PWM구현 동영상
EP1C3T PWM Test Verilog 소스
module altera_evm(reset, clk, led3);
input reset;
input clk;
output [7:0] led3;
//클럭 분주
//clk 50ns
wire clk_100us;
f_devider divider1(
.iClk(clk),
.iRst(reset),
.iDevide(2000),
.oOut(clk_100us)
);
wire clk_10ms;
f_devider divider2(
.iClk(clk),
.iRst(reset),
.iDevide(200000),
.oOut(clk_10ms)
);
wire out_pwm;
reg [7:0] pwm_period = 10;
reg flag;
always @(posedge clk_10ms)
if (!reset)
begin
pwm_period <= 1;
flag = 0;
end
else
begin
if(pwm_period == 100)flag = 1;
if(pwm_period == 0)flag=0;
if(flag == 0)
pwm_period <= pwm_period+2;
else
pwm_period <= pwm_period-2;
end
f_pwm pwm1(
.iClk(clk_100us),
.iRst(reset),
.iFreq(100),
.iPeriod(pwm_period),
.oOut(out_pwm)
);
//PWM 출력
assign led3[0] = (out_pwm );
assign led3[1] = (out_pwm );
assign led3[2] = (out_pwm );
assign led3[3] = (out_pwm );
assign led3[4] = ~(out_pwm );
assign led3[5] = ~(out_pwm );
assign led3[6] = ~(out_pwm );
assign led3[7] = ~(out_pwm );
endmodule
input reset;
input clk;
output [7:0] led3;
//클럭 분주
//clk 50ns
wire clk_100us;
f_devider divider1(
.iClk(clk),
.iRst(reset),
.iDevide(2000),
.oOut(clk_100us)
);
wire clk_10ms;
f_devider divider2(
.iClk(clk),
.iRst(reset),
.iDevide(200000),
.oOut(clk_10ms)
);
wire out_pwm;
reg [7:0] pwm_period = 10;
reg flag;
always @(posedge clk_10ms)
if (!reset)
begin
pwm_period <= 1;
flag = 0;
end
else
begin
if(pwm_period == 100)flag = 1;
if(pwm_period == 0)flag=0;
if(flag == 0)
pwm_period <= pwm_period+2;
else
pwm_period <= pwm_period-2;
end
f_pwm pwm1(
.iClk(clk_100us),
.iRst(reset),
.iFreq(100),
.iPeriod(pwm_period),
.oOut(out_pwm)
);
//PWM 출력
assign led3[0] = (out_pwm );
assign led3[1] = (out_pwm );
assign led3[2] = (out_pwm );
assign led3[3] = (out_pwm );
assign led3[4] = ~(out_pwm );
assign led3[5] = ~(out_pwm );
assign led3[6] = ~(out_pwm );
assign led3[7] = ~(out_pwm );
endmodule
반응형