Шукати в цьому блозі

пʼятниця, 6 січня 2012 р.

Verilog code counter by 7 mouse click. Using Quartus II and MegaWizard Plug-in Manger with LPM_COUNTER

            При проектуванні складних цифрових схем і опису їх на Verilog коді, від проектувальника вимагається не тільки хорошого знання та розуміння проектування цифрових схем а також хорошого рівня знань стандарту Verilog а також різного роду тонкощів при описі проекту. При цьому час на розробку та тестування проекту збільшується. В цій темі ми розглянемо як генерувати Verilog код використовуючи при цьому можливості  MegaWizard Plug-in Manger.





























Відкриємо згенерований файл counter_syn.v в блокноті і отримаємо код який введений нижче. Частину коду яка підкреслена фоном ми можемо викоритсовувати як код лічильника на Verilog для проектування в інших системах.
// megafunction wizard: %LPM_COUNTER%


// GENERATION: STANDARD

// VERSION: WM1.0
// MODULE: LPM_COUNTER

// ============================================================
// File Name: counter.v
// Megafunction Name(s):
// LPM_COUNTER
//
// Simulation Library Files(s):
// lpm
// ============================================================
// ************************************************************
// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
//
// 11.0 Build 157 04/27/2011 SJ Web Edition
// ************************************************************


//Copyright (C) 1991-2011 Altera Corporation
//Your use of Altera Corporation's design tools, logic functions
//and other software and tools, and its AMPP partner logic
//functions, and any output files from any of the foregoing
//(including device programming or simulation files), and any
//associated documentation or information are expressly subject
//to the terms and conditions of the Altera Program License
//Subscription Agreement, Altera MegaCore Function License
//Agreement, or other applicable license agreement, including,
//without limitation, that your use is for the sole purpose of
//programming logic devices manufactured by Altera and sold by
//Altera or its authorized distributors. Please refer to the
//applicable agreement for further details.


//lpm_counter DEVICE_FAMILY="MAX3000A" lpm_modulus=13 lpm_port_updown="PORT_USED" lpm_width=4 aclr clk_en clock cnt_en q updown
//VERSION_BEGIN 11.0 cbx_cycloneii 2011:04:27:21:07:09:SJ cbx_lpm_add_sub 2011:04:27:21:07:09:SJ cbx_lpm_compare 2011:04:27:21:07:09:SJ cbx_lpm_counter 2011:04:27:21:07:09:SJ cbx_lpm_decode 2011:04:27:21:07:09:SJ cbx_mgl 2011:04:27:21:08:59:SJ cbx_stratix 2011:04:27:21:07:09:SJ cbx_stratixii 2011:04:27:21:07:09:SJ VERSION_END
// synthesis VERILOG_INPUT_VERSION VERILOG_2001
// altera message_off 10463


//synthesis_resources =
//synopsys translate_off
`timescale 1 ps / 1 ps
//synopsys translate_on
module counter_cntr
(
aclr,
clk_en,
clock,
cnt_en,
q,
updown) /* synthesis synthesis_clearbox=1 */;
input aclr;
input clk_en;
input clock;
input cnt_en;
output [3:0] q;
input updown;
`ifndef ALTERA_RESERVED_QIS
// synopsys translate_off
`endif
tri0 aclr;
tri1 clk_en;
tri1 cnt_en;
tri1 updown;
`ifndef ALTERA_RESERVED_QIS
// synopsys translate_on
`endif

reg [4:0] wire_q_int;

// synopsys translate_off
initial
wire_q_int = 0;
// synopsys translate_on
always @(posedge clock or posedge aclr)
if (aclr == 1'b1) wire_q_int <= 5'b0;
else
if ( clk_en == 1'b1)
if (cnt_en == 1'b1)
if (updown == 1'b1)
if (wire_q_int[3:0] == 4'd12)
wire_q_int <= 4'b0;
else
wire_q_int <= wire_q_int[3:0] + 1'b1;
else
if (wire_q_int[3:0] == 4'b0)
wire_q_int <= 4'd12;
else
wire_q_int <= wire_q_int[3:0] - 1'b1;
assign
q = wire_q_int[3:0];
endmodule //counter_cntr

//VALID FILE


// synopsys translate_off
`timescale 1 ps / 1 ps
// synopsys translate_on
module counter (
aclr,
clk_en,
clock,
cnt_en,
updown,
q)/* synthesis synthesis_clearbox = 1 */;

input aclr;
input clk_en;
input clock;
input cnt_en;
input updown;
output [3:0] q;

wire [3:0] sub_wire0;
wire [3:0] q = sub_wire0[3:0];

counter_cntr counter_cntr_component (
.aclr (aclr),
.clk_en (clk_en),
.clock (clock),
.cnt_en (cnt_en),
.updown (updown),
.q (sub_wire0));

endmodule

// ============================================================
// CNX file retrieval info
// ============================================================
// Retrieval info: PRIVATE: ACLR NUMERIC "1"
// Retrieval info: PRIVATE: ALOAD NUMERIC "0"
// Retrieval info: PRIVATE: ASET NUMERIC "0"
// Retrieval info: PRIVATE: ASET_ALL1 NUMERIC "1"
// Retrieval info: PRIVATE: CLK_EN NUMERIC "1"
// Retrieval info: PRIVATE: CNT_EN NUMERIC "1"
// Retrieval info: PRIVATE: CarryIn NUMERIC "0"
// Retrieval info: PRIVATE: CarryOut NUMERIC "0"
// Retrieval info: PRIVATE: Direction NUMERIC "2"
// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "MAX3000A"
// Retrieval info: PRIVATE: ModulusCounter NUMERIC "1"
// Retrieval info: PRIVATE: ModulusValue NUMERIC "13"
// Retrieval info: PRIVATE: SCLR NUMERIC "0"
// Retrieval info: PRIVATE: SLOAD NUMERIC "0"
// Retrieval info: PRIVATE: SSET NUMERIC "0"
// Retrieval info: PRIVATE: SSET_ALL1 NUMERIC "1"
// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "1"
// Retrieval info: PRIVATE: nBit NUMERIC "4"
// Retrieval info: PRIVATE: new_diagram STRING "1"
// Retrieval info: LIBRARY: lpm lpm.lpm_components.all
// Retrieval info: CONSTANT: LPM_DIRECTION STRING "UNUSED"
// Retrieval info: CONSTANT: LPM_MODULUS NUMERIC "13"
// Retrieval info: CONSTANT: LPM_PORT_UPDOWN STRING "PORT_USED"
// Retrieval info: CONSTANT: LPM_TYPE STRING "LPM_COUNTER"
// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC "4"
// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT NODEFVAL "aclr"
// Retrieval info: USED_PORT: clk_en 0 0 0 0 INPUT NODEFVAL "clk_en"
// Retrieval info: USED_PORT: clock 0 0 0 0 INPUT NODEFVAL "clock"
// Retrieval info: USED_PORT: cnt_en 0 0 0 0 INPUT NODEFVAL "cnt_en"
// Retrieval info: USED_PORT: q 0 0 4 0 OUTPUT NODEFVAL "q[3..0]"
// Retrieval info: USED_PORT: updown 0 0 0 0 INPUT NODEFVAL "updown"
// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0
// Retrieval info: CONNECT: @clk_en 0 0 0 0 clk_en 0 0 0 0
// Retrieval info: CONNECT: @clock 0 0 0 0 clock 0 0 0 0
// Retrieval info: CONNECT: @cnt_en 0 0 0 0 cnt_en 0 0 0 0
// Retrieval info: CONNECT: @updown 0 0 0 0 updown 0 0 0 0
// Retrieval info: CONNECT: q 0 0 4 0 @q 0 0 4 0
// Retrieval info: GEN_FILE: TYPE_NORMAL counter.v TRUE
// Retrieval info: GEN_FILE: TYPE_NORMAL counter.inc FALSE
// Retrieval info: GEN_FILE: TYPE_NORMAL counter.cmp FALSE
// Retrieval info: GEN_FILE: TYPE_NORMAL counter.bsf TRUE
// Retrieval info: GEN_FILE: TYPE_NORMAL counter_inst.v TRUE
// Retrieval info: GEN_FILE: TYPE_NORMAL counter_bb.v TRUE
// Retrieval info: GEN_FILE: TYPE_NORMAL counter_syn.v TRUE
// Retrieval info: LIB_FILE: lpm

 Якщо порівняти наш згенерований код із кодом який Altera пропонує при кодингу для своїх систем на Verilog по цій ссилці

module behav_counter( d, clk, clear, load, up_down, qd);

// Port Declaration

input [7:0] d;
input clk;
input clear;
input load;
input up_down;
output [7:0] qd;

reg [7:0] cnt;


assign qd = cnt;


always @ (posedge clk)
begin
if (!clear)
cnt = 8'h00;
else if (load)
cnt = d;
else if (up_down)
cnt = cnt + 1;
else
cnt = cnt - 1;
end

endmodule

 Можемо побачити, що поведінкова частина кодів якщо не схожа то ідентична. 
Такий підхід в проектуванні схем дає певну гнучкість в проектуванні і переносі спроектованих частин схеми в інші середовища розробки які підтримують Verilog. Крім того  MegaWizard Plug-in містить дуже багато різноманітних бібліотек якими можна і генерувати код зменшуючи при цьому час до кінцевої розробки.