2020年1月31日 星期五

DE2-115 Varying an LED intensity ( LED on off ,LED half-lit , Fine-tuning LED intensity)

DE2-115 Varying an LED intensity

參考來源 https://www.fpga4fun.com/Opto2.html

PWM_input=SW[3:0] 控制LED的亮度

//需 Import  pin assignments  DE2_115_pin_assignments




//==============================================
/*
//Turning an 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


//Making an LED half-lit
module LEDhalflit(clk, LED);
input clk;     // clk should be at least 200Hz.
                // Anything above is fine (most FPGA boards have adequate clocks, running at a few 10's of MHz)
output LED;

reg toggle;
always @(posedge clk) toggle <= ~toggle;     // toggles at half the clk frequency (at least 100Hz)

assign LED = toggle;
endmodule


//Fine-tuning the LED intensity

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
*/

//需 Import  pin assignments  DE2_115_pin_assignments
module LED_onoff_halflit(
  input  CLOCK_50, // 50 MHz clock
  input  [3:0] KEY,      // Pushbutton[3:0]
  input  [17:0] SW, // Toggle Switch[17:0]
  output [6:0] HEX0,HEX1,HEX2,HEX3,HEX4,HEX5,HEX6,HEX7,  // Seven Segment Digits
  output [8:0] LEDG,  // LED Green
  output [17:0] LEDR,  // LED Red
  inout  [35:0] GPIO_0,GPIO_1, // GPIO Connections
// LCD Module 16X2
  output LCD_ON, // LCD Power ON/OFF
  output LCD_BLON, // LCD Back Light ON/OFF
  output LCD_RW, // LCD Read/Write Select, 0 = Write, 1 = Read
  output LCD_EN, // LCD Enable
  output LCD_RS, // LCD Command/Data Select, 0 = Command, 1 = Data
  inout [7:0] LCD_DATA, // LCD Data bus 8 bits
  input [2:0] mess, // MESSAGE STATUS (see lcd_test)
  input [1:0] isServer // SERVER STATUS (see lcd_test)
);

// All inout port turn to tri-state
assign GPIO_0 = 36'hzzzzzzzzz;
assign GPIO_1 = 36'hzzzzzzzzz;

// turn LCD ON
assign LCD_ON = 1'b1;
assign LCD_BLON = 1'b1;

// blank unused 7-segment digits
assign HEX0 = 7'b111_1111;
assign HEX1 = 7'b111_1111;
assign HEX2 = 7'b111_1111;
assign HEX3 = 7'b111_1111;
assign HEX4 = 7'b111_1111;
assign HEX5 = 7'b111_1111;
assign HEX6 = 7'b111_1111;
assign HEX7 = 7'b111_1111;

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

//Turning an LED on and off
assign LEDG[0] = cnt[25];    // blink the LED at a few Hz (using the 23th bit of the counter, use a different bit to modify the blinking rate)

//-----------------------------------------------
//Making an LED half-lit
reg toggle;
always @(posedge CLOCK_50) toggle <= ~toggle;     // toggles at half the clk frequency (at least 100Hz)
assign LEDG[1] = toggle;
//-----------------------------------------------
//Fine-tuning the LED intensity
wire [3:0] PWM_input;     // 16 intensity levels
assign PWM_input=SW[3:0];

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

assign LEDG[2] = PWM[4];
endmodule

https://www.youtube.com/watch?v=00Yucb7bbwY

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...