呼吸燈程式差最後一步 懇請指導
时间:10-02
整理:3721RD
点击:
data是輸出到LED燈上
down和down2是兩個按鈕,用來做出4種速度變化的呼吸燈
小弟我做出來的功能是 從暗到最亮後 LED整顆滅掉 然後就繼續從暗到亮
但我想做的是 亮到最亮點後 它再慢慢的變暗 然後又繼續慢慢變亮
有些人跟我說是 RespirationRate <= -(RespirationRate); 這裡出問題 在verilog裡 正負交換似乎有特別的打法
但網上的討論 不是草草幾筆到我這個初新者完全看不懂 不然就是 在長篇大論的討論 1補數與2補數0.0 看不懂啦ˊˋ
還請各位前輩指導指導 我這個呼吸燈應該要怎打才對 感恩!
module BreathingLight(clk,rst,data,down,down2);
input clk,rst,down,down2;
output reg data;
reg [24:0] cnt;
reg [19:0] number;
reg [19:0] RespirationRate;
always@(posedge clk, negedge rst)begin
if (rst ==0) begin
cnt <= 0 ;
end
else begin
if(cnt == 1000000) begin //週期20mS
if(cnt <= number) begin
RespirationRate <= -(RespirationRate);
end
else if(number < 0) begin
RespirationRate <= -(RespirationRate);
end
cnt<=0;
number <= number + RespirationRate;
end
else begin
if(cnt <= number) begin
data<=1;
cnt<=cnt+1;
end
else begin
data<=0;
cnt<=cnt+1;
end
end
case ({!down,!down2})
0: RespirationRate <= 1250 ;//呼吸段數
1: RespirationRate <= 2500 ;//呼吸段數
2: RespirationRate <= 5000 ;//呼吸段數
3: RespirationRate <= 10000 ;//呼吸段數
endcase
end
end
endmodule
自己頂一下
拜託別沉阿
