⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lin.v

📁 verilog HDL 编写的PWM
💻 V
字号:
module lin(clock,pwm);
input clock;
output pwm;              //接到LED上
reg pwm;
reg[7:0] base;           //对比的基数
reg[7:0] count;          //对时钟记数,将时间长河分为若干个8位时间段
reg[23:0] count1;        //主要得到肉眼可分辨的时间,这里为1秒
reg[8:0]  count2;        //进行奇偶数秒控制
always@(negedge clock )
begin
    count=count+1;
    if(count==8'b11111111)
    begin
        count=8'b00000000;
        count1=count1+1;
    end
    if(count>base)
        pwm=1'b1;
    else
        pwm=1'b0;
    if(count1==16'b1001100100101111)      //也就是达到了1秒左右
    begin
        count2=count2+1;
        count1=1'b0;
        if((count2%2)==1'b1)
            base=8'b11100000;             //变换基准
        else
            base=8'b00000000;
        if(count2==8'b11111111)
            count2=8'b00000001;        
    end
end
endmodule


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -