随笔分类 -  Verilog

1 2 3 下一页

HDL
握手通信
摘要:module handshack( input clk, input rst_n, input req, input [7:0] datain, output ack, output [7:0] dataout);reg reqr1,reqr2,reqr3;reg [7:0] dataoutr;reg ackr;always @ (posedge clk,negedge rst_n)if(!rst_n) {reqr3,reqr2,reqr1} <= 3'b111;else {reqr3,reqr2,reqr1} <= {reqr2,reqr1,r... 阅读全文

posted @ 2011-09-17 09:58 齐威王 阅读(3123) 评论(1) 推荐(2)

异步fifo
摘要:这个是基于RAM的异步FIFO代码,个人认为代码结构简单易懂,非常适合于考试中填写。与同步fifo相比增加了读写控制信号的跨时钟域的同步。此外,判空与判满的也稍有不同。module fifo#( parameter DSIZE = 8, ASIZE = 4)( input [DSIZE-1:0] wdata, input winc, wclk, wrst_n, input rinc, rclk, rrst_n, output [DSIZE-1:0] rdata, output reg wfull, output reg rempty); reg [ASIZE:0] wptr, r... 阅读全文

posted @ 2011-09-16 16:48 齐威王 阅读(3568) 评论(2) 推荐(1)

序列检测器二
摘要:101101序列检测器module seqdet( input wire x, input wire clk, input wire rst_n, output reg z);//用verilog设计一个 101101 序列的检测器reg [4:0] cs,ns;localparam [4:0] IDLE =5'd0, A =5'd1, B =5'd2, C =5'd3, D =5'd4, E =5'd5, F =5'd6;//状态转移always @ (posedge clk,n... 阅读全文

posted @ 2011-09-12 12:18 齐威王 阅读(3135) 评论(3) 推荐(1)

色彩空间转换 YCbCr---RGB
摘要:YCbCr转RGB的公式如下:R=1.164(Y-16)+1.596(Cr-128);G=1.164(Y-16)-0.391(Cb-128)-0.813(Cr-128);B=1.164(Y-16)+2.018(Cb-128);其中的系数可以表示成1.164=1+1/2^3+1/2^5+1/2^7;1.596=1+1/2+1/2^4+1/2^5;0.391=1/2^2+1/2^3+1/2^6;0.813=1/2+1/2^2+1/2^4;2.018=2+1/2^6;故而,上述公式可以转化成没有乘法的公式,大大提高了运算的效率。参考文献:http://www.cnblogs.com/oomus 阅读全文

posted @ 2011-07-07 09:21 齐威王 阅读(2152) 评论(0) 推荐(0)

PS2鼠标解码
摘要:鼠标的数据包格式鼠标的初始化PS2发送数据 The t r i - c and t r i - d signals are enable signals that control the tri-state buffers.When they are asserted, the corresponding ps2c-out and ps2d-out signals will be routed to the output ports.滤波和下降沿检测程序:// body //================================================= // filter 阅读全文

posted @ 2011-04-19 11:33 齐威王 阅读(2606) 评论(0) 推荐(0)

序列检测器
摘要:功能描述:序列检测器就是将一个指定序列从数字码流中识别出来。本例中将设计一个“10010”序列的检测器。设X为数字码流的输入,Z为检测出标记输出,高电平表示发现指定的序列10010.考虑码流为110010010000100101....则,如表有:用FSM实现module seqdet( input wire x, input wire clk, input wire rst, output wire z);reg [2:0] state;localparam IDLE = 3'd0, A = 3'd1, B = 3'd2, C = 3'd3, D = 3 阅读全文

posted @ 2011-04-18 15:51 齐威王 阅读(13109) 评论(0) 推荐(4)

除法器设计
摘要:基于FSMD的除法器设计在http://www.cnblogs.com/qiweiwang/archive/2011/04/13/2014502.html中已经有了一篇除法器的设计实例,本文对该除法器修改如下// Listing 7.11module div_combined #( parameter W = 8, CBIT = 4 // CBIT=log2(W)+1 ) ( input wire clk, reset, input wire start, input wire [W-1:0] dvsr, dvnd, output wire ready, done_tick, output w 阅读全文

posted @ 2011-04-13 21:48 齐威王 阅读(1117) 评论(2) 推荐(1)

FPGA Prototyping By Verilog Examples第七章 阻塞和非阻塞赋值
摘要:阻塞和非阻塞赋值// Listing 7.1module and_block ( input wire a, b, c, output reg y ); always @* begin y = a; y = y & b; y = y & c; endendmodule// Listing 7.2module and_nonblock ( input wire a, b, c, output reg y ); always @* begin // y$_{entry}$ = y y <= a; // y$_{exit}$ = a y <= y & b; // 阅读全文

posted @ 2011-04-13 17:47 齐威王 阅读(1104) 评论(0) 推荐(1)

FPGA Prototyping By Verilog Examples第六章 状态机FSMD设计
摘要:FSMD(带数据通道的有限状态机)是FSM和常规时序电路的结合。基于RT methodology的消抖电路设计本设计中主要的数据通道是一个用户自定制的21位递减计数器,其作用为:1:可初始化为一个指定的值;2:具有递减计数和暂停计数的功能;3:当计数器计数为0的时候,输出一个状态信号。module debounce_explicit ( input wire clk, reset, input wire sw, output reg db_level, db_tick ); // symbolic state declaration localparam [1:0] zero = 2' 阅读全文

posted @ 2011-04-13 10:46 齐威王 阅读(2887) 评论(0) 推荐(1)

FPGA Prototyping By Verilog Examples第五章 状态机FSM设计
摘要:上升沿检测电路之Moore型FSM// Listing 5.3module edge_detect_moore ( input wire clk, reset, input wire level, output reg tick ); // symbolic state declaration localparam [1:0] zero = 2'b00, edg = 2'b01, one = 2'b10; // signal declaration reg [1:0] state_reg, state_next; // state register always @(p 阅读全文

posted @ 2011-04-12 11:04 齐威王 阅读(1209) 评论(0) 推荐(1)

FPGA Prototyping By Verilog Examples第四章 常用时序电路设计
摘要:通用移位寄存器通用移位寄存器可以载入并行数据,左移,右移,保持;它能够实现并-串功能(先载入并行数据后移位),也可实现串并功能(先移位后并行输出)。// Listing 4.8module univ_shift_reg #(parameter N=8) ( input wire clk, reset, input wire [1:0] ctrl, input wire [N-1:0] d, output wire [N-1:0] q ); //signal declaration reg [N-1:0] r_reg, r_next; // body // register always @(p 阅读全文

posted @ 2011-04-09 16:32 齐威王 阅读(2270) 评论(1) 推荐(0)

FPGA Prototyping By Verilog Examples第三章
摘要:// Listing 3.1module eq1_always ( input wire i0, i1, output reg eq // eq declared as reg ); // p0 and p1 declared as reg reg p0, p1; always @(i0, i1) // i0 an i1 must be in sensitivity list begin // the order of statements is important p0 = ~i0 & ~i1; p1 = i0 & i1; eq = p0 | p1; endendmodule 阅读全文

posted @ 2011-04-08 11:45 齐威王 阅读(1112) 评论(0) 推荐(0)

组合逻辑中容易综合出锁存器的几种电路和解决方法
摘要:环境QuartusII8.1在组合逻辑中,容易综合出锁存器的语句是if和case,其实只要配对使用if...else;case用default就基本上可以避免锁存器;case1(有锁存器):module mux_latch( input [3:0] data, input [1:0] valid, input flag, output reg valid_data);always @ (*) begin if(valid==2'd0) valid_data = data[3]; if(valid==2'd1) valid_data = data[2]; if(valid==2& 阅读全文

posted @ 2011-03-15 17:29 齐威王 阅读(3676) 评论(0) 推荐(1)

无符号数与有符合数的加法
摘要:首先,考虑一个问题,在Verilog中assign answer = i_a+i_b-i_c;assign answer_signed = $signed(i_a)+$signed(i_b)-$signed(i_c);assign answer_unsigned = $unsigned(i_a)+$unsigned(i_b)-$unsigned(i_c);这几种形式有什么区别?实验如下,建立源文件和测试文件`timescale 1ns/1nsmodule signed_test(i_a,i_b,i_c,i_mode,o_answer);input [7:0] i_a,i_b;input [31 阅读全文

posted @ 2011-03-15 16:41 齐威王 阅读(2925) 评论(0) 推荐(1)

线性移位寄存器LFSR电路设计
摘要:module LFSR ( input clk, input rst_n, output out);reg [9:0] q=10'b1010101010;wire tap = q[2]^q[9];assign out = q[9];always @ (posedge clk,negedge rst_n)if(!rst_n) q <= 10'b1010101010;else q <= {q[8:0],tap};endmodule将LFSR赋初始值1010101010,最低为q0=q2 xor q9,输出为最高位q9;测试程序如下:`timescale 1 ns/1 n 阅读全文

posted @ 2011-03-11 17:14 齐威王 阅读(2878) 评论(0) 推荐(0)

VGA汉字显示实验
摘要:参考特权同学的深入浅出玩转FPGA的VGA显示实验,分辨率1440×900@60[代码] 阅读全文

posted @ 2011-01-19 22:51 齐威王 阅读(2988) 评论(1) 推荐(1)

基于DE0的VGA测试
摘要:本次实验用的VGA是HPw17e电脑显示器,其分辨率为1440×900@60,系统时钟106.47MHZ时序如下: 同步脉冲FRONT 后沿SYNC 显示脉冲ACT 前沿BACK 帧长TOTAL行时序HSYNC 152 232 1440 80 1904列时序VSYNC 3 28 900 1 932Timequest约束vga.sdcCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->## Generated SDC file " 阅读全文

posted @ 2011-01-18 16:31 齐威王 阅读(910) 评论(1) 推荐(0)

边沿检测电路
摘要:边沿检测电路,包括上升沿、下降沿、双沿检测电路。在检测到所需要的边沿后产生一个高电平的脉冲。Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->module edge_detect( input clk, input rst_n, input data_in, output raising_edge_detect, output falling_edge_detect, output double_edge_detect);reg data_in 阅读全文

posted @ 2011-01-02 15:03 齐威王 阅读(2900) 评论(0) 推荐(0)

倍频电路设计
摘要:二倍频电路的FPGA设计,在半整数分频中可以用到 阅读全文

posted @ 2010-12-30 16:56 齐威王 阅读(1784) 评论(1) 推荐(0)

PS2解码
摘要:PS2键盘:明确接线关系,只需接4根线,VCC要+5V,刚刚又测试过,3.3V也可以用。时钟和数据线要用bidir双向口线,FPGA可以不用外接上拉电阻。另外,USB键盘也可以用,只要用一个转接头转成PS2即可。键值查表PS2键盘解码其中detect.v模块Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1 module detect 2 ( 3 input clk, 4 input rst_n, 5 input ps2_clk_pin_i 阅读全文

posted @ 2010-12-24 15:50 齐威王 阅读(1618) 评论(1) 推荐(0)

1 2 3 下一页

导航