fpga4fun—发光二极管

发光二极管电子基础知识

LED(发光二极管)是一种半导体器件,当电流通过它时会产生光。
LED 符号看起来像一个二极管,带有阳极 (+) 和阴极 (-)。

  • LED 的作用类似于二极管 - 单向导电,以另一种方式阻挡电力。 像所有二极管一样,它具有阈值电压。普通红色LED的阈值电压约为2.0V。低于2.0V,不发光(没有电流通过LED)。 高于2.0V, LED导电, 光强取决于通过LED的电流.
  • LED有两个物理限制,不能超过: 最大正向电流(因此是最大光强度)。最大值通常为几十分之一的mA。 最大反向电压(即使 LED反向偏置时没有电流通过,也不要反向偏置太多)。反向电压限值通常为 5V…比普通二极管低得多!

打开和关闭LED 灯

使用时钟的方法打开的关闭LED灯,以时钟产生不同频率的方波,方波的 0,1控制LED的亮灭

module LEDblink(clk, LED);
input clk;     // clock typically from 10MHz to 50MHz
output LED;

// create a binary counter
reg [31:0] cnt;
always @(posedge clk) cnt <= cnt+1;

assign LED = cnt[22];    // blink the LED at a few Hz (using the 23th bit of the counter, use a different bit to modify the blinking rate)
endmodule

产生频率为25000000/2^22 hz的方波,使得LED闪烁。

PWM调整LED强度

module LEDglow(clk, LED);
input clk;
output LED;

reg [23:0] cnt;
always @(posedge clk) cnt <= cnt+1;

reg [4:0] PWM;
wire [3:0] intensity = cnt[23] ? cnt[22:19] : ~cnt[22:19];    // ramp the intensity up and down
always @(posedge clk) PWM <= PWM[3:0] + intensity;

assign LED = PWM[4];
endmodule

通过设置24位计数器来调整LED亮度。
采用计数器22-19四位信号,设置16个亮度等级,利用cnt[23]控制亮度是升高还是降低,当cnt[23]为1时,亮度从0-15,当cnt[23]为0时,亮度从15-0,因为~cnt[22:19]的数值为15-cnt[22:19],随着计数器增加,取反则逐渐减小。
此代码实现了LED灯“呼吸”,因为pwm在16个数之间来回顺序切换。

按键调节LED亮度

module LED_PWM(clk, PWM_input, LED);
input clk;
input [3:0] PWM_input;     // 16 intensity levels
output LED;

reg [4:0] PWM;
always @(posedge clk) PWM <= PWM[3:0] + PWM_input;

assign LED = PWM[4];
endmodule

通过开关1,2,3,4调节亮度,按下开关表示接通二极管,设置LED7位输出LED信号。
请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述

猜你喜欢

转载自blog.csdn.net/weixin_49574391/article/details/131825079