====呼吸灯设计文件==== // -------------------------------------------------------------------- // >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<< // -------------------------------------------------------------------- // Module: Breath_led // // Author: Step // // Description: PWM-Breath_led // // Web: www.ecbcamp.com // // -------------------------------------------------------------------- // Code Revision History : // -------------------------------------------------------------------- // Version: |Mod. Date: |Changes Made: // V1.0 |2015/11/11 |Initial ver // -------------------------------------------------------------------- module Breath_led # ( parameter CNT_NUM = 5000 //period = (5000^2)*2 = 50000000 = 2s ) ( input clk_in, //system clk input rst_n_in, //system reset output Breath_led //Breath led output ); reg [12:0] cnt1; //generate cnt1 signal always@(posedge clk_in or negedge rst_n_in) begin if(!rst_n_in) begin cnt1<=13'd0; end else begin if(cnt1>=CNT_NUM-1) cnt1<=1'b0; else cnt1<=cnt1+1'b1; end end reg flag; reg [12:0] cnt2; //generate cnt2 signal always@(posedge clk_in or negedge rst_n_in) begin if(!rst_n_in) begin cnt2<=13'd0; flag<=1'b0; end else begin if(cnt1==CNT_NUM-1) begin if(!flag) begin if(cnt2>=CNT_NUM-1) flag<=1'b1; else cnt2<=cnt2+1'b1; end else begin if(cnt2<=0) flag<=1'b0; else cnt2<=cnt2-1'b1; end end else cnt2<=cnt2; end end //Compare cnt1 and cnt2, generate PWM-Breath-led assign Breath_led = (cnt1