DE0-CVで(大げさな)Lチカ

動作確認、さぁ行ってみようかぁ。

  • Quartus Primeを起動、"File" -> "New Project Wizard"を選択、プロジェクト名は"LEDBlink"、詳細設定はこちらの中で参照しているこちらを参照、"Family & Device Setting"を"5CEBA4F23C7"にするのを忘れずに。
  • "File" -> "New..."で"Verilog HDL"を選択、以下の通りに実装、"LEDBlink.v"で保存
module LEDBlink(
	input wire in_clk, 
	input wire [9:0] in_switch, 
	input wire [3:0] in_button,
	output wire [9:0] out_led, 
	output wire [6:0] seven_segment_0, 
	output wire [6:0] seven_segment_1, 
	output wire [6:0] seven_segment_2, 
	output wire [6:0] seven_segment_3, 
	output wire [6:0] seven_segment_4, 
	output wire [6:0] seven_segment_5);
	//
	wire reset = ~in_button[0];
	//
	// clock divder for 1 sec
	//
	reg [25:0] _26bit_counter;
	wire _26bit_counter_expired;
	assign _26bit_counter_expired = (_26bit_counter == 26'd49_999_999)? 1'b1: 1'b0;
	//
	always @(posedge in_clk or posedge reset)
	begin
		if (reset)
			_26bit_counter <= 26'd0;
		else
		begin
			if (_26bit_counter_expired)
				_26bit_counter <= 26'd0;
			else
				_26bit_counter <= _26bit_counter + 26'd1;
		end
	end
	//
	// LED blink latch
	//
	reg led_latch;
	//
	always @(posedge in_clk or posedge reset)
	begin
		if (reset)
			led_latch <= 1'd0;
		else
			if (_26bit_counter_expired)
				led_latch <= ~led_latch;
	end
	//
	// counter for 7 segment LED 
	//
	reg [3:0] _4bit_counter;
	//
	always @(posedge in_clk or posedge reset)
	begin
		if (reset)
			_4bit_counter <= 4'd0;
		else
			if (_26bit_counter_expired)
				_4bit_counter  <= _4bit_counter + 4'd1;
	end
	
	//assign LEDs
	seven_segment_decoder seven_segment_decoder_0(
	.in_4bit(_4bit_counter + 4'd5), 
	.out_seven_segment(seven_segment_0));
	seven_segment_decoder seven_segment_decoder_1(
	.in_4bit(_4bit_counter + 4'd4), 
	.out_seven_segment(seven_segment_1));
	seven_segment_decoder seven_segment_decoder_2(
	.in_4bit(_4bit_counter + 4'd3), 
	.out_seven_segment(seven_segment_2));
	seven_segment_decoder seven_segment_decoder_3(
	.in_4bit(_4bit_counter + 4'd2),
	.out_seven_segment(seven_segment_3));
	seven_segment_decoder seven_segment_decoder_4(
	.in_4bit(_4bit_counter + 4'd1), 
	.out_seven_segment(seven_segment_4));
	seven_segment_decoder seven_segment_decoder_5(
	.in_4bit(_4bit_counter), 
	.out_seven_segment(seven_segment_5));
	//
	assign out_led = (led_latch)? 10'b11_1111_1111: 10'b00_0000_0000;
endmodule
  • "File" -> "New..."で"Verilog HDL"を選択、以下の通りに実装、こちらは"seven_segment_decoder.v"で保存
module seven_segment_decoder(
	input wire [3:0] in_4bit, 
	output wire [6:0] out_seven_segment);
	//
	function [6:0] led_decoder;
		//
		input [3:0] in_number;
		//
		begin
			case (in_number)
				4'h0:
					led_decoder = 7'b1000000;
				4'h1:
					led_decoder = 7'b1111001;
				4'h2:
					led_decoder = 7'b0100100;
				4'h3:
					led_decoder = 7'b0110000;
				4'h4:
					led_decoder = 7'b0011001;
				4'h5:
					led_decoder = 7'b0010010;
				4'h6:
					led_decoder = 7'b0000010;
				4'h7:
					led_decoder = 7'b1111000;
				4'h8:
					led_decoder = 7'b0000000;
				4'h9:
					led_decoder = 7'b0011000;
				4'ha:
					led_decoder = 7'b0001000;
				4'hb:
					led_decoder = 7'b0000011;
				4'hc:
					led_decoder = 7'b0100111;
				4'hd:
					led_decoder = 7'b0100001;
				4'he:
					led_decoder = 7'b0000110;
				4'hf:
					led_decoder = 7'b0001110;
				default:
					led_decoder = 7'b1111111;
			endcase
		end
	endfunction
	//
	assign out_seven_segment[6:0] = led_decoder(in_4bit);
	//
endmodule
  • 一度、Quartus Primeを終了、プロジェクトフォルダー下の"(project名).qsf"をテキストエディターで開き、以下をコピペ。
set_location_assignment PIN_M6 -to in_button[3]
set_location_assignment PIN_M7 -to in_button[2]
set_location_assignment PIN_U7 -to in_button[0]
set_location_assignment PIN_W9 -to in_button[1]
set_location_assignment PIN_U13 -to in_switch[0]
set_location_assignment PIN_V13 -to in_switch[1]
set_location_assignment PIN_T13 -to in_switch[2]
set_location_assignment PIN_T12 -to in_switch[3]
set_location_assignment PIN_AA15 -to in_switch[4]
set_location_assignment PIN_AB15 -to in_switch[5]
set_location_assignment PIN_AA14 -to in_switch[6]
set_location_assignment PIN_AA13 -to in_switch[7]
set_location_assignment PIN_AB13 -to in_switch[8]
set_location_assignment PIN_AB12 -to in_switch[9]
set_location_assignment PIN_AA2 -to out_led[0]
set_location_assignment PIN_AA1 -to out_led[1]
set_location_assignment PIN_W2 -to out_led[2]
set_location_assignment PIN_Y3 -to out_led[3]
set_location_assignment PIN_N2 -to out_led[4]
set_location_assignment PIN_N1 -to out_led[5]
set_location_assignment PIN_U2 -to out_led[6]
set_location_assignment PIN_U1 -to out_led[7]
set_location_assignment PIN_L2 -to out_led[8]
set_location_assignment PIN_L1 -to out_led[9]
set_location_assignment PIN_U21 -to seven_segment_0[0]
set_location_assignment PIN_V21 -to seven_segment_0[1]
set_location_assignment PIN_W22 -to seven_segment_0[2]
set_location_assignment PIN_W21 -to seven_segment_0[3]
set_location_assignment PIN_Y22 -to seven_segment_0[4]
set_location_assignment PIN_Y21 -to seven_segment_0[5]
set_location_assignment PIN_AA22 -to seven_segment_0[6]
set_location_assignment PIN_AA20 -to seven_segment_1[0]
set_location_assignment PIN_AB20 -to seven_segment_1[1]
set_location_assignment PIN_AA19 -to seven_segment_1[2]
set_location_assignment PIN_AA18 -to seven_segment_1[3]
set_location_assignment PIN_AB18 -to seven_segment_1[4]
set_location_assignment PIN_AA17 -to seven_segment_1[5]
set_location_assignment PIN_U22 -to seven_segment_1[6]
set_location_assignment PIN_Y19 -to seven_segment_2[0]
set_location_assignment PIN_AB17 -to seven_segment_2[1]
set_location_assignment PIN_AA10 -to seven_segment_2[2]
set_location_assignment PIN_Y14 -to seven_segment_2[3]
set_location_assignment PIN_V14 -to seven_segment_2[4]
set_location_assignment PIN_AB22 -to seven_segment_2[5]
set_location_assignment PIN_AB21 -to seven_segment_2[6]
set_location_assignment PIN_Y16 -to seven_segment_3[0]
set_location_assignment PIN_W16 -to seven_segment_3[1]
set_location_assignment PIN_Y17 -to seven_segment_3[2]
set_location_assignment PIN_V16 -to seven_segment_3[3]
set_location_assignment PIN_U17 -to seven_segment_3[4]
set_location_assignment PIN_V18 -to seven_segment_3[5]
set_location_assignment PIN_V19 -to seven_segment_3[6]
set_location_assignment PIN_U20 -to seven_segment_4[0]
set_location_assignment PIN_Y20 -to seven_segment_4[1]
set_location_assignment PIN_V20 -to seven_segment_4[2]
set_location_assignment PIN_U16 -to seven_segment_4[3]
set_location_assignment PIN_U15 -to seven_segment_4[4]
set_location_assignment PIN_Y15 -to seven_segment_4[5]
set_location_assignment PIN_P9 -to seven_segment_4[6]
set_location_assignment PIN_N9 -to seven_segment_5[0]
set_location_assignment PIN_M8 -to seven_segment_5[1]
set_location_assignment PIN_T14 -to seven_segment_5[2]
set_location_assignment PIN_P14 -to seven_segment_5[3]
set_location_assignment PIN_C1 -to seven_segment_5[4]
set_location_assignment PIN_C2 -to seven_segment_5[5]
set_location_assignment PIN_W19 -to seven_segment_5[6]
set_location_assignment PIN_M9 -to in_clk

これでDE0-CVボード上の部品との接続ができる。
このピンアサインメントはよく使うので、"Assignments" -> "Export Assignments"を選択し、どこかに保存して置くと他のプロジェクトでインポートできる。