Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `timescale 1ns / 1ps
- // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
- // Company:
- // Engineer:
- //
- // Create Date: 09/29/2020 04:11:34 PM
- // Design Name:
- // Module Name: blink_led_hardware
- // Project Name:
- // Target Devices:
- // Tool Versions:
- // Description:
- //
- // Dependencies:
- //
- // Revision:
- // Revision 0.01 - File Created
- // Additional Comments:
- //
- // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
- module blink_led_hardware(input wire ACLK,
- input wire control_strobe,
- input wire [1:0] control_blinkmode1,
- input wire [1:0] control_blinkmode2,
- input wire [1:0] control_blinkmode3,
- input wire [1:0] control_blinkmode4,
- input wire frequency_strobe,
- input wire [31:0] frequency_frequency,
- output reg [3:0] led);
- // Signals
- reg slow, fast;
- reg [32:0] fast_counter;
- reg [1:0] slow_counter;
- // Combine blinkmodes into blinkmode array
- wire [1:0] modes [0:3];
- assign modes[0] = control_blinkmode1;
- assign modes[1] = control_blinkmode2;
- assign modes[2] = control_blinkmode3;
- assign modes[3] = control_blinkmode4;
- // Loop counters
- integer j;
- // Drive leds according to modes
- always @(*) begin
- for (j = 0; j < 4; j = j+1) begin
- case(modes[j])
- 2'd0: led[j] = 0;
- 2'd1: led[j] = 1;
- 2'd2: led[j] = slow;
- 2'd3: led[j] = fast;
- default: led[j] = 0;
- endcase
- end
- end
- // Generate slow and fast signals
- always @(posedge ACLK, posedge frequency_strobe) begin
- if (frequency_strobe) begin
- fast <= 0;
- slow <= 0;
- fast_counter <= 0;
- slow_counter <= 0;
- end
- else begin
- // The higher the frequency the faster the counter goes up
- fast_counter <= fast_counter + frequency_frequency;
- // Assign the carrybit to fast
- fast <= fast_counter[32];
- // Detect changes in fast
- if (fast != fast_counter[32]) begin
- // Every time fast changes
- if (slow_counter >= 2) begin
- // Toggle slow every 3 changes
- slow <= !slow;
- slow_counter <= 0;
- end
- else begin
- // Or increment the counter
- slow_counter <= slow_counter + 1;
- end
- end
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement