fpga4fun - Light Emitting Diodes

Light Emitting Diode Electronics Basics

An LED (Light Emitting Diode) is a semiconductor device that produces light when electricity is passed through it.
The LED symbol looks like a diode with an anode (+) and cathode (-).

  • LEDs act like diodes - conduct electricity one way, block power the other way. Like all diodes it has a threshold voltage. A normal red LED has a threshold voltage of about 2.0V. Below 2.0V, no light is emitted (no current flows through the LED). Above 2.0V, the LED conducts electricity, and the light intensity depends on the current passing through the LED.
  • LEDs have two physical limits that cannot be exceeded: Maximum forward current (and thus maximum light intensity). The maximum value is typically a few tenths of mA. Maximum reverse voltage (don't reverse bias too much even if no current flows when the LED is reverse biased). The reverse voltage limit is typically 5V...much lower than normal diodes!

Turn LED lights on and off

Use the clock method to turn on and off the LED light, and use the clock to generate square waves of different frequencies. The 0 and 1 of the square wave control the LED on and off.

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

Generate a square wave with a frequency of 25000000/2^22 hz, causing the LED to blink.

PWM to adjust LED intensity

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

LED brightness is adjusted by setting a 24-bit counter.
Use the counter 22-19 four-bit signal to set 16 brightness levels, and use cnt[23] to control whether the brightness is increased or decreased. When cnt[23] is 1, the brightness is from 0-15. When cnt[23] is 0, the brightness is from 15-0, because the value of ~cnt[22:19] is 15-cnt[22:19]. As the counter increases, it will gradually decrease when it is reversed.
This code enables the LED light to "breathe" as the pwm sequentially switches back and forth between 16 numbers.

Button to adjust LED brightness

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

Adjust the brightness through switches 1, 2, 3, 4, press the switch to turn on the diode, and set the LED 7 bit to output the LED signal.
Please add a picture description

Please add a picture description
Please add a picture description
Please add a picture description

Je suppose que tu aimes

Origine blog.csdn.net/weixin_49574391/article/details/131825079
conseillé
Classement