Programming/Verilog2018. 1. 20. 14:20

베릴로그 언어적 특성에 대해서 혼동을 하고 있었네..


Gate Level Modeling

- primitives 를 이용한 게이트 레벨 설계방법

- and, or, nand, nor, xor, xnor

- buf, not

- bufif1, bufif0, notif1, notif0 (tri-state)

일종의 변수 처럼 사용하여 인스턴스를 생성, 변수들을 서로 엮어 회로 구성

module and_from_nand(X, Y, F);

input X, Y;

output F;

wire W;

// Two instantiations of the module NAND

nand U1(W, X, Y);

nand U2(F, WW);

endmodule 


Dataflow Modeling 

- assign 키워드 사용

- net에 특정 논리값을 지정함으로서 데이터의 흐름을 통해(routing?) 회로 구성

- 각종 연산자들 사용가능

아래와 같이 wire로 net 끼리 연결하거나, wire로 선언 후 assign을 통해서 연결

wire out = in1 & in2 ;


wire out;

assign out = in1 & in2 ; 


Behavioral Modeling 

- always 키워드 이용

- always 내부의 내용은 시퀀셜 하게 작동. always들 끼리는 병렬로 작동

- alwyas 는 항상 작동하므로, 절차적 언어의 무한반복문과 유사한 개념

- 절차적(always) 에서는 블러킹과 넌블러킹이 존재

(즉, dataflow나 gate level에서는 해당 개념이 존재하지 않음. 이녀석이 혼동의 원인)

- 블러킹 '=' 라인 순서대로 수행

- 넌블러킹 '<=' 넌블러킹 끼리는 동시 수행

- C언어 같은 느낌으로 if, switch-case등을 지원

- for 문은 합성툴에 따라 반복횟수 제한되거나, 지원하지 않음


블러킹과 넌블러킹으로 인해서 경쟁상태 발생이 가능함.

race condition 발생시에는 어떤 값이 있을지 알 수 없으므로 오작동 유발

- always들 끼리 같은 값에 쓰지 않도록 하며

- 써야 한다면 넌 블러킹으로 할당하면 값이 변동되지 않음

// illustration 1 : blocking

always @(posegde clk)

a = b ;

always @(posedge clk)

b = a;


// illustration 2 : nonblocking

always @(posegde clk)

a <= b ;

always @(posedge clk)

b <= a; 

자료 괜찮은거 같은데.. 이거 상위 페이지에서 한번에 받기는 못 찾음..

[링크 : https://cms3.koreatech.ac.kr/sites/yjjang/down/dsys07/01VerilogHDL.pdf]

'Programming > Verilog' 카테고리의 다른 글

verilog module instantiate  (0) 2018.01.26
verliog module 선언  (0) 2018.01.25
verilog Concatenation, Replication operator  (0) 2018.01.19
verilog unary reduction operator와 bitwise operator  (0) 2018.01.19
베릴로그 순차적 구조적  (2) 2018.01.18
Posted by 구차니
Programming/Verilog2018. 1. 19. 08:46

베릴로그 프리젠테이션 파일 보다 신기한거 발견


concatenation operator는 말그대로 합체! 하는 연산자 인데

일반적인 프로그래밍 언어라면 불가능하지만

하드웨어 배선으로는 너무나 쉬운 데이터끼리 붙이는 연산자이다.

가장 쉬운 활용예로는 Adder에서 Carry bit


r_VAL_1을 MSB 쪽으로 r_VAL_2를 LSB 쪽으로 붙여서 01111100 으로 만드는 연산자이다.

단, 부족한(?) 선은 0으로 대체 하는 듯

근데.. 이거 몇개 까지 붙일 수 있을지 궁금하네?

reg [3:0]  r_VAL_1 = 4'b0111;

reg [3:0]  r_VAL_2 = 4'b1100;

wire [7:0] w_CAT;


assign w_CAT = {r_VAL_1, r_VAL_2}; 

[링크 : https://www.nandland.com/verilog/examples/example-concatenation-operator.html]


Relication operator는 복제하는 녀석인데

비트 연산으로 이걸 하려면 참 토나오는데,

하드웨어로는 배선을 분기쳐서 이어주면 되니 간편하게 쓸 수 있겠네

문법 자체는 정규표현식 같은 느낌

앞의 숫자 만큼 순서대로 붙인다 011101110111

reg [3:0]  r_VAL_1 = 4'b0111;

{3{r_VAL_1}};


# Replication of 0x7, 3 times is 0x777

[링크 : https://www.nandland.com/verilog/examples/example-replication-operator.html]

'Programming > Verilog' 카테고리의 다른 글

verliog module 선언  (0) 2018.01.25
verilog 모델링 유형  (0) 2018.01.20
verilog unary reduction operator와 bitwise operator  (0) 2018.01.19
베릴로그 순차적 구조적  (2) 2018.01.18
structural vs behavioral verilog  (0) 2018.01.12
Posted by 구차니
Programming/Verilog2018. 1. 19. 07:51

reduction operator는

벡터에 대해서 1개의 bit로 연산을 해준다.

가장 편리한(?) 예제로는 parity 계산

bitwise and를 비트별로 계산할걸 reduction을 쓰면 한번에 끝난다.

근데 bitwise 연산자랑 일항 축약 연산자랑 어떻게 구분하지?


unary reduction operator

reg r_C;

&4'b1101;

r_C = |4'b0010;

[링크 : https://www.nandland.com/verilog/examples/example-reduction-operators.html]


bitwise operator

reg r_A = 1'b1;

reg r_B = 1'b0;

assign w_AND_SCALAR = r_A & r_B;

[링크 : https://www.nandland.com/verilog/examples/example-bitwise-operators.html]



+

아.. 그래서 unary 연산자 였군..

어떻게 보면 포인터와 비슷한 방식으로 단항으로 사용이 되고

항이 두개면 무조건 bitwise로 연산이 되려나?

즉, reduction은 무조건 변환 후 대입 정도만 허용되고

bitwise는 두항을 계산하고 2다른 걸 연속적으로 하는 식이 가능 할 것으로 보인다.


+

https://www.utdallas.edu/~akshay.sridharan/index_files/Page5212.htm

'Programming > Verilog' 카테고리의 다른 글

verilog 모델링 유형  (0) 2018.01.20
verilog Concatenation, Replication operator  (0) 2018.01.19
베릴로그 순차적 구조적  (2) 2018.01.18
structural vs behavioral verilog  (0) 2018.01.12
verilog vector instance  (0) 2018.01.09
Posted by 구차니
Programming/Verilog2018. 1. 18. 20:46

blocking /non-blocking 

= 이냐 <= 이냐 차이인데

대입순서에 따라 최적화 하면 중간 결과가 사라지거나 클럭에 따라 쉬프트로 구현됨


[링크 : http://multilab.jbnu.ac.kr/2915]

[링크 : https://blog.naver.com/mikael2010/130094384689]

[링크 : http://www.sutherland-hdl.com/papers/1996-CUG-presentation_nonblocking_assigns.pdf]




+

여전히 프로그래밍 모델을 확실히 파악한게 아니라

behavioral 이라던가 procedural이라던가 

non-blocking이라던가 blocking이라던가

여러개가 혼재되서 무진장 혼동된다.

'Programming > Verilog' 카테고리의 다른 글

verilog Concatenation, Replication operator  (0) 2018.01.19
verilog unary reduction operator와 bitwise operator  (0) 2018.01.19
structural vs behavioral verilog  (0) 2018.01.12
verilog vector instance  (0) 2018.01.09
verilog always  (0) 2018.01.01
Posted by 구차니
Programming/Verilog2018. 1. 12. 13:28

함수 만들듯 verilog module을 만들어서

KEY 누르면 LED에 AND OR 연산해서 보여주려고 했더니

이상한 오류들이 뿜뿜하는 바람에 찾아 봤더니

module로 해서 구조적(함수 콜하듯)으로 사용할 때에는 wire로 된 값을 넘겨 주어야 하는 듯?

[링크 : https://blog.naver.com/bungkun1349/220337637928]

[링크 : https://blog.naver.com/specialist0/220777659022]


There is no strict definition of these terms, according to the IEEE Std. However, customarily, structural refers to describing a design using module instances (especially for the lower-level building blocks such as AND gates and flip-flops), whereas behavioral refers to describing a design using always blocks.

Gate netlists are always structural, and RTL code is typically behavioral. It is common for RTL to have instances of clock gates and synchronizer cells. 

[링크 : https://stackoverflow.com/.../what-is-the-difference-between-structural-verilog-and-behavioural-verilog]


11. Structural vs. Behavioral Verilog

To clarify the difference between structural and behavioral verilog: 
Structural verilog is composed of module instances and their interconnections (by wires) only.  The use of regs, explicit time delays, arithmetic expressions, procedural assignments, or other verilog control flow structures are considered behavioral verilog.

As stated earlier, your project code will consist primarily of structural verilog.  You will use behavioral statements for debugging purposes only.  In fact, you will probably only instantiate two regs in your whole design: one for the clock and one for a RESET signal that is asserted at the beginning of your simulation.

This section has described all of the Verilog functionality you will need for your final project.   If you want more information on behavioral Verilog, try reading the Bucknell CSCI Verilog Manual or the verilog manual at The University of Edinburgh. 

[링크 : http://users.ece.utexas.edu/~patt/04s.382N/tutorial/verilog_manual.html#11. Behavioral Verilog]

'Programming > Verilog' 카테고리의 다른 글

verilog unary reduction operator와 bitwise operator  (0) 2018.01.19
베릴로그 순차적 구조적  (2) 2018.01.18
verilog vector instance  (0) 2018.01.09
verilog always  (0) 2018.01.01
verilog 2001 ** 연산자  (0) 2018.01.01
Posted by 구차니
Programming/Verilog2018. 1. 9. 20:52

verilog 언어로 된 모듈을 여러개 어떻게 생성하나

일일이 이름 바꾸어서 해야 하나 고민을 했는데

동일 이름으로 생성도 가능하고

벡터로 모듈 생성이 가능하다고 한다

(그러니까 SHA256 모듈을 벡터로 생성하는 꽁수를!)


Example 4


module my_module (a, b, c);

input a, b;

output c;

  assign c = a & b ;

endmodule

 

module top (a, b, c) ;

input [3:0] a, b;

output [3:0] c;

  my_module inst [3:0] (a, b, c);

endmodule 

[링크 : http://verilog.renerta.com/mobile/source/vrg00027.htm]


genvar k;

generate for (k = 1; k <`wordsize - 1; k = k + 1)

 begin

    I2S_dff instance (.d(sd), .q(q_out[i]), .r(wsp), .en(dec_out[i]), .sck(clk));

    datareg_in = |q_out;

 end

endgenerate 

[링크 : https://electronics.stackexchange.com/.../how-to-use-generate-for-multiple-module-instantiation-in-verilog]


From Verilog-95 you can have a vector of instances:

d_flipflop ff[7:0] (A, Q, reset clk); 

[링크 : https://stackoverflow.com/questions/21615210/instantiating-multiple-modules-in-verilog]

'Programming > Verilog' 카테고리의 다른 글

베릴로그 순차적 구조적  (2) 2018.01.18
structural vs behavioral verilog  (0) 2018.01.12
verilog always  (0) 2018.01.01
verilog 2001 ** 연산자  (0) 2018.01.01
verilog 코드 분석  (0) 2018.01.01
Posted by 구차니
Programming/C Win32 MFC2018. 1. 8. 11:29

eclipse에서 하려니 먼가 잘 안되고

(한줄에 여러개 있는게 되는게 있고 안되는게 있고 그러네..)

jindent 라는 플러그인 하니 라인길이 제한이 걸려있어서 유료 사야하고


notepad++에는

tidy 플러그인 깔아야 한다는데, 플러그인 매니저가 이상해져서 깔기 빡세고


웹에서 하는 것도 있지만

외부로 코드 유출되는거 아닌가 걱정되서 쓰기 그렇고..

그리고 파일단위가 아닌 복/붙해야 하니 귀찮...

[링크 : https://codebeautify.org/c-formatter-beautifier]


리눅스에서 툴을 이용하는것들 발견.. 해봐야 할 듯

[링크 : https://askubuntu.com/questions/448497/source-code-formatter-indenter]


clang-format 쓸만하긴 한데 하위 디렉토리 자동으로 뒤져서 하는건 없다고..

[링크 : https://stackoverflow.com/questions/28896909/how-to-call-clang-format-over-a-cpp-project-folder]

'Programming > C Win32 MFC' 카테고리의 다른 글

엔디안 급 멘붕..  (0) 2018.05.29
const char *과 char * const 차이  (0) 2018.01.31
win32 시리얼 통신 LPCTSTR / LPCSTR  (0) 2017.12.07
MFC CList 선택항목 인덱스 얻기  (0) 2017.11.28
MFC CSdlierCtrl 에서 SetPos()  (0) 2017.11.28
Posted by 구차니
Programming/Verilog2018. 1. 1. 09:51

always @ (posedge

이런식으로 많이 쓰이는데

always 자체는 패러럴 구문이지만 @와 결합해서 시퀀셜 하게 쓰이는 듯 하고,

@는 event에 대한 기술이다.


3. PARALLEL STATEMENTS 

always sequential_statement


5. SEQUENTIAL STATEMENTS

@ (event [{or event}]) sequential_statement

[링크 : http://www.ece.uvic.ca/~fayez/courses/ceng465/vlogref.pdf]


다만 =는 블럭킹(sequential, block) 으로

<=는 넌블러킹(parallel, non-blocking)으로 작동하게 되는데

[링크 : https://courses.cs.washington.edu/courses/cse467/03wi/Verilog3.pdf]

[링크 : https://class.ee.washington.edu/371/peckol/doc/Always@.pdf]


always 내에서 블럭킹으로 할 경우 race condition의 위험이 있다고 한다.

[링크 : https://www.nandland.com/vhdl/tutorials/tutorial-process-part1.html]

[링크 : http://aboutmadlife.blogspot.kr/2015/01/verilog-blocking-non-blocking.html]

'Programming > Verilog' 카테고리의 다른 글

베릴로그 순차적 구조적  (2) 2018.01.18
structural vs behavioral verilog  (0) 2018.01.12
verilog vector instance  (0) 2018.01.09
verilog 2001 ** 연산자  (0) 2018.01.01
verilog 코드 분석  (0) 2018.01.01
Posted by 구차니
Programming/Verilog2018. 1. 1. 09:37

VHDL 에서는 기본으로 있었던거 같은데

** 연산자는 지수승에 대한(밑이 2) 연산자로

Verilog 2001 부터 추가되었다고 한다.

지금에 와서는 거의 모든 개발 툴에서 2001을 지원하겠지?


[링크 : http://www.asic-world.com/verilog/verilog2k1.html]

'Programming > Verilog' 카테고리의 다른 글

베릴로그 순차적 구조적  (2) 2018.01.18
structural vs behavioral verilog  (0) 2018.01.12
verilog vector instance  (0) 2018.01.09
verilog always  (0) 2018.01.01
verilog 코드 분석  (0) 2018.01.01
Posted by 구차니
Programming/Verilog2018. 1. 1. 08:24

de0-nano 가속도 센서 예제 

예제가 죄다 verilog네 -_- VHDL을 공부하려는 나의 계획은 이렇게 날아 가는건가!!!


// -------------------------------------------------------------------- // Copyright (c) 2011 by Terasic Technologies Inc. // -------------------------------------------------------------------- // // Permission: // // Terasic grants permission to use and modify this code for use // in synthesis for all Terasic Development Boards and Altera Development // Kits made by Terasic. Other use of this code, including the selling // ,duplication, or modification of any portion is strictly prohibited. // // Disclaimer: // // This VHDL/Verilog or C/C++ source code is intended as a design reference // which illustrates how these types of functions can be implemented. // It is the user's responsibility to verify their design for // consistency and functionality through the use of formal // verification methods. Terasic provides no warranty regarding the use // or functionality of this code. // // -------------------------------------------------------------------- // // Terasic Technologies Inc // 356 Fu-Shin E. Rd Sec. 1. JhuBei City, // HsinChu County, Taiwan // 302 // // web: http://www.terasic.com/ // email: support@terasic.com // // -------------------------------------------------------------------- // // Major Functions: G Sensor utilization // // -------------------------------------------------------------------- // // Revision History : // -------------------------------------------------------------------- // Ver :| Author :| Mod. Date :| Changes Made: // V1.0 :| Rosaline Lin :| 02/16/2011 :| Initial Revision // -------------------------------------------------------------------- //======================================================= // This code is generated by Terasic System Builder //======================================================= module DE0_NANO_G_Sensor( //////////// CLOCK ////////// CLOCK_50, //////////// LED ////////// LED, //////////// KEY ////////// KEY, //////////// Accelerometer and EEPROM ////////// G_SENSOR_CS_N, G_SENSOR_INT, I2C_SCLK, I2C_SDAT ); //======================================================= // PARAMETER declarations //======================================================= //======================================================= // PORT declarations //======================================================= //////////// CLOCK ////////// input CLOCK_50; //////////// LED ////////// output [7:0] LED; //////////// KEY ////////// input [1:0] KEY; //////////// Accelerometer and EEPROM ////////// output G_SENSOR_CS_N; input G_SENSOR_INT; output I2C_SCLK; inout I2C_SDAT; //======================================================= // REG/WIRE declarations //======================================================= wire dly_rst; wire spi_clk, spi_clk_out; wire [15:0] data_x; //======================================================= // Structural coding //======================================================= // Reset reset_delay u_reset_delay ( .iRSTN(KEY[0]), .iCLK(CLOCK_50), .oRST(dly_rst)); // PLL spipll u_spipll ( .areset(dly_rst), .inclk0(CLOCK_50), .c0(spi_clk), // 2MHz .c1(spi_clk_out)); // 2MHz phase shift // Initial Setting and Data Read Back spi_ee_config u_spi_ee_config ( .iRSTN(!dly_rst), .iSPI_CLK(spi_clk), .iSPI_CLK_OUT(spi_clk_out), .iG_INT2(G_SENSOR_INT), .oDATA_L(data_x[7:0]), .oDATA_H(data_x[15:8]), .SPI_SDIO(I2C_SDAT), .oSPI_CSN(G_SENSOR_CS_N), .oSPI_CLK(I2C_SCLK)); // LED led_driver u_led_driver ( .iRSTN(!dly_rst), .iCLK(CLOCK_50), .iDIG(data_x[9:0]), .iG_INT2(G_SENSOR_INT), .oLED(LED));  

endmodule 

D:\de-nano\DE0-Nano_v.1.2.3_SystemCD\Demonstration\DE0_NANO_GSensor\DE0_NANO_G_Sensor.v

D:\de-nano\DE0-Nano_v.1.2.3_SystemCD\Demonstration\DE0_NANO_GSensor\v\led_driver.v


module module_name(module_in_outs);

// 일종의 입출력 변수들 정의(타입은 아직 정의하지 않고 이름만 정의


    // module의 핀(?)에 대한 입출력 방향과 타입을 정의

    input pin_name;

    output pin_name2;

    inout pin_name3;


    // 방향 지시자 없는 내부변수 선언

    wire pin_nam4;

    reg [1:0] count;


    // 행위를 정의함 - structural coding 라고 써있음

    assign out = in;


    // 조사필요

   always@(posedge iCLK or negedge iRSTN)

   submodule sub_module_name

   (

      .sub_module_pin(main_module_pin),

   );

// module의 끝

endmodule 


wire랑 reg도 변수 타입이고 그 외에는 int, real 등의 타입도 있다고..

[링크 : http://wiki.vctec.co.kr/devboard/fpga/spartan-3a-fpga-gaebalbodeu--elbert/module]

'Programming > Verilog' 카테고리의 다른 글

베릴로그 순차적 구조적  (2) 2018.01.18
structural vs behavioral verilog  (0) 2018.01.12
verilog vector instance  (0) 2018.01.09
verilog always  (0) 2018.01.01
verilog 2001 ** 연산자  (0) 2018.01.01
Posted by 구차니