25M时钟的梁祝演奏
module liangzhu(clk_50M,rst,speaker);
input clk_50M,rst;
output speaker;
reg speaker;
//分频计数器
parameter wide=15;
reg[7:0] cnt; //音名数
reg[3:0] cnt1; //5MHz基频
reg[23:0] cnt2;//节拍频率5Hz
reg[wide-1:0] origin;//预置数寄存器
reg[wide-1:0] drive;
reg[1:0] count;
reg carrier;
//分频产生5MHz和5Hz的频率
always @(posedge clk_50M,negedge rst)
begin
if(!rst)
begin
cnt1<=4'd0;
cnt2<=24'd0;
end
else
begin
cnt1<=cnt1+1'b1;
cnt2<=cnt2+1'b1;
if(cnt1==4'd4)
cnt1<=4'd0;
if(cnt2==4999999)
cnt2<=24'd0;
end
end
always @(posedge clk_50M,negedge rst)
begin
if(!rst)
drive<=15'h0;
else if(cnt1==4'd4)
begin
if(drive==15'h3fff)
begin
drive<=origin;
carrier<=1'b1;
end
else begin drive<=drive+1'b1;carrier<=1'b0; end
end
end
//carrier的频率是每个音阶的频率 音乐里面的节拍
always @(posedge carrier)
begin
count<=count+1'b1;
if(count==4'd0)
speaker<=1'b1;
else speaker<=1'b0;
end
always @(posedge clk_50M,negedge rst)
begin
if(!rst)
begin
origin<=15'h0;
cnt<=8'd0;
end
else if(cnt2==24'h98967F/2)
begin
if(cnt==8'd139)
cnt<=8'd0;
else
cnt<=cnt+1'b1;
case (cnt)
8'd0:origin<=15'h625F/2; //中音3,4个节拍
8'd1:origin<=15'h625F/2;
8'd2:origin<=15'h625F/2;
8'd3:origin<=15'h625F/2;
8'd4:origin<=15'h6715/2; //中音5,3个节拍
8'd5:origin<=15'h6715/2;
8'd6:origin<=15'h6715/2;
8'd7:origin<=15'h69cd/2;//中音6
8'd8:origin<=15'h6d55/2; //高音1,3个节拍
8'd9:origin<=15'h6d55/2;
8'd10:origin<=15'h6d55/2;
8'd11:origin<=15'h6f5f/2; //高音2
8'd12:origin<=15'h69cd/2; //中音6
8'd13:origin<=15'h6d55/2; //高音1
8'd14:origin<=15'h6715/2; //中音5
8'd15:origin<=15'h6715/2;
8'd16:origin<=15'h738a/2; //高音5
8'd17:origin<=15'h738a/2;
8'd18:origin<=15'h738a/2;
8'd19:origin<=15'h76aa/2; //倍高音1
8'd20:origin<=15'h69cd/2; //高音6
8'd21:origin<=15'h6715/2;//高音5
8'd22:origin<=15'h712f/2;//高音3
8'd23:origin<=15'h6715/2;//高音5
8'd24:origin<=15'h6f5f/2; //高音2
8'd25:origin<=15'h6f5f/2;
8'd26:origin<=15'h6f5f/2;
8'd27:origin<=15'h6f5f/2;
8'd28:origin<=15'h6f5f/2;
8'd29:origin<=15'h6f5f/2;
8'd30:origin<=15'h6f5f/2;
8'd31:origin<=15'h6f5f/2;
8'd32:origin<=15'h6f5f/2;
8'd33:origin<=15'h6f5f/2;
8'd34:origin<=15'h6f5f/2;
8'd35:origin<=15'h712f/2;//高音3
8'd36:origin<=15'h6c39/2; //中音7
8'd37:origin<=15'h6c39/2;
8'd38:origin<=15'h69cd/2;//中音6
8'd39:origin<=15'h69cd/2;
8'd40:origin<=15'h6715/2; //中音5
8'd41:origin<=15'h6715/2;
8'd42:origin<=15'h6715/2;
8'd43:origin<=15'h69cd/2;//中音6
8'd44:origin<=15'h6d55/2;//高音1
8'd45:origin<=15'h6d55;
8'd46:origin<=15'h6f5f/2;//高音2
8'd47:origin<=15'h6f5f/2;
8'd48:origin<=15'h625f/2;//中音3
8'd49:origin<=15'h625f/2;
8'd50:origin<=15'h6d55/2; //高音1
8'd51:origin<=15'h6d55/2;
8'd52:origin<=15'h69cd/2;//中音6
8'd53:origin<=15'h6715/2;//中音5
8'd54:origin<=15'h69cd/2; //中音6
8'd55:origin<=15'h6d55/2;//高音1
8'd56:origin<=15'h6715/2;//中音5
8'd57:origin<=15'h6715/2;
8'd58:origin<=15'h6715/2;
8'd59:origin<=15'h6715/2;
8'd60:origin<=15'h6715/2;
8'd61:origin<=15'h6715/2;
8'd62:origin<=15'h6715/2;
8'd63:origin<=15'h6715/2;
8'd64:origin<=15'h712f/2;//高音3
8'd65:origin<=15'h712f/2;
8'd66:origin<=15'h712f/2;
8'd67:origin<=15'h738a/2;//高音5
8'd68:origin<=15'h6c39/2;//中音7
8'd69:origin<=15'h6c39/2;
8'd70:origin<=15'h6f5f/2;//高音2
8'd71:origin<=15'h6f5f/2;
8'd72:origin<=15'h69cd/2; //中音6
8'd73:origin<=15'h6d55/2;//高音1
8'd74:origin<=15'h6715/2;//中音5
8'd75:origin<=15'h6715/2;
8'd76:origin<=15'h6715/2;
8'd77:origin<=15'h6715/2;
8'd78:origin<=15'h6715/2;
8'd79:origin<=15'h6715;
8'd80:origin<=15'h625f/2; //中音3
8'd81:origin<=15'h6715/2;//中音5
8'd82:origin<=15'h625f/2;//中音3
8'd83:origin<=15'h625f/2;
8'd84:origin<=15'h6715/2;//中音5
8'd85:origin<=15'h69cd/2;//中音6
8'd86:origin<=15'h6c39/2;//中音7
8'd87:origin<=15'h6f5f/2;//高音2
8'd88:origin<=15'h69cd/2;//中音6
8'd89:origin<=15'h69cd/2;
8'd90:origin<=15'h69cd/2;
8'd91:origin<=15'h69cd/2;
8'd92:origin<=15'h69cd/2;
8'd93:origin<=15'h69cd/2;
8'd94:origin<=15'h6715/2;//中音5
8'd95:origin<=15'h69cd/2;//中音6
8'd96:origin<=15'h6d55/2;//高音1
8'd97:origin<=15'h6d55/2;
8'd98:origin<=15'h6d55/2;
8'd99:origin<=15'h6f5f/2;////高音2
8'd100:origin<=15'h738a/2; //高音5
8'd101:origin<=15'h738a/2;
8'd102:origin<=15'h738a/2;
8'd103:origin<=15'h712f/2;//高音3
8'd104:origin<=15'h6f5f/2;//高音2
8'd105:origin<=15'h6f5f/2;
8'd106:origin<=15'h712f/2;//高音3
8'd107:origin<=15'h6f5f/2;//高音2
8'd108:origin<=15'h6d55/2;//高音1
8'd109:origin<=15'h6d55/2;
8'd110:origin<=15'h69cd/2;//中音6
8'd111:origin<=15'h6715/2;//中音5
8'd112:origin<=15'h625f/2;//中音3
8'd113:origin<=15'h625f;
8'd114:origin<=15'h625f/2;
8'd115:origin<=15'h625f/2;
8'd116:origin<=15'h6d55/2;//高音1
8'd117:origin<=15'h6d55/2;
8'd118:origin<=15'h69cd/2;//中音6
8'd119:origin<=15'h6d55/2;//高音1
8'd120:origin<=15'h69cd/2;//中音6
8'd121:origin<=15'h625f/2;//中音3
8'd122:origin<=15'h625f/2;
8'd123:origin<=15'h6f5f/2;//高音2
8'd124:origin<=15'h625f/2;//中音3
8'd125:origin<=15'h6715/2;//中音5
8'd126:origin<=15'h69cd/2;//中音6
8'd127:origin<=15'h6d55/2;//高音1
8'd128:origin<=15'h6715/2;//中音5
8'd129:origin<=15'h6715/2;
8'd130:origin<=15'h6715/2;
8'd131:origin<=15'h6715/2;
8'd132:origin<=15'h6715/2;
8'd133:origin<=15'h6715/2;
8'd134:origin<=15'h6715/2;
8'd135:origin<=15'h6715/2;
8'd136:origin<=15'h3fff/2;
8'd137:origin<=15'h3fff/2;
8'd138:origin<=15'h3fff/2;
8'd139:origin<=15'h3fff/2;
default:origin<=15'h3fff/2;
endcase
end
end
endmodule
25M时钟的梁祝演奏的更多相关文章
- 基于FPGA的飞机的小游戏
基于FPGA的飞机的小游戏 实验原理 该实验主要分为4个模块,采用至上而下的设计方法进行设计.由50M的晶振电路提供时钟源,VGA显示控制模块.图形显示控制模块.移动模块的时钟为25M,由时钟分频电路 ...
- 【lattice软核】ROM的使用
=======================>>>>> 一.ROM核调用:==================>>>>> ======== ...
- S3C2416裸机开发系列十六_sd卡驱动实现
S3C2416裸机开发系列十六 sd卡驱动实现 象棋小子 1048272975 SD卡(Secure Digital Memory Card)具有体积小.容量大.传输数据快.可插拔.安全性好等长 ...
- 关于VGA显示实验的问题
今天做了一个关于VGA的显示实验,但是由于产生的25M时钟不正确所以一直没有图像产生.刚开始的程序如下 虽然仿真的时候出现了时序,但是在下载到硬件的时候不正确. 后来改成 结果就正确了. 另外之前关于 ...
- 解析stm32的时钟
STM32 时钟系统 http://blog.chinaunix.net/uid-24219701-id-4081961.html STM32的时钟系统 *** http://www.cnblo ...
- STM32F2系列系统时钟默认配置
新到一家公司后,有个项目要用到STM32F207Vx单片机,找到网上的例子照猫画虎的写了几个例子,比如ADC,可是到了ADC多通道转换的时候就有点傻眼了,这里面的时钟跑的到底是多少M呢?单片机外挂的时 ...
- LPC2478时钟模块详解
时钟框图如上图,系统时钟来源分别是内部4M的RC振荡器和外置晶振,RTC模块在某些情况下也可以作为主时钟,经过系统时钟选择s\de时钟需要经过PLL倍频(或者不倍频),处理过的PLL输出USB时钟分频 ...
- HDMI ip中的时钟 vid_clk与ls_clk
由TMDS_Bit_clock_Ratio.TMDS_clk和色彩深度,就可以确定出tmds_clk,cdr_clk,vid_clk和ls_clk之间的关系. 1.Tmds_clk时钟频率的确定: 原 ...
- 第15章 RCC—使用HSE/HSI配置时钟
第15章 RCC—使用HSE/HSI配置时钟 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku. ...
随机推荐
- .NET事件监听机制的局限与扩展
.NET中把“事件”看作一个基本的编程概念,并提供了非常优美的语法支持,对比如下C#和Java代码可以看出两种语言设计思想之间的差异. // C#someButton.Click += OnSomeB ...
- 允许Sublime编辑器在Ubuntu上输入中文
Sublime Text是一款功能非常强大的轻量级代码编辑器,有关功能介绍和使用可以看我另一篇文章的描述http://www.cnblogs.com/jaxu/p/5037547.html 不过,在U ...
- 《Entity Framework 6 Recipes》中文翻译系列 (29) ------ 第五章 加载实体和导航属性之过滤预先加载的实体集合和修改外键关联
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 5-13 过滤预先加载的实体集合 问题 你想过滤预先加载的实体集合,另外,你想使用 ...
- JDK下载、安装、配置环境变量笔记
自己总是在下载.安装.配置JDK的环境变量,但是这些需要的专业知识并不难,但有很多细节很重要,总是记不住,而且这些细节一旦出错影响还是很严重的,在网上查到的信息很多都比较零散,而且讲解得也不是很详细, ...
- Atitit常见的标准化组织与规范数量jcp ecma iso
Atitit常见的标准化组织与规范数量jcp ecma iso 1. 常见的标准化组织1 1.1. 重要的基金会apache1 1.2. 美国国家标准学会(American NationalStand ...
- easyui 日期显示
{ field: 'UpdateDatetime', title: '更新时间', width: 100, align: 'left', sortable: true , formatter: fun ...
- 【Win10 应用开发】OCR识别
OCR,即Optical Character Recognition,光学字符识别.以下介绍来自搜索: OCR(Optical Character Recognition,光学字符识别)是指电子设备( ...
- WinForm最小化到托盘以及托盘右键菜单
首先,先拖一个NotifyIcon到主窗体,然后设置NotifyIcon的图标,不然等下最小化后,都找不到那个程序了,还有那个Text也是,不写名字,就默认是NotifyIcon了..如下图: 然后双 ...
- MySQL基于时间字段进行分区的方案总结
MySQL支持的分区类型一共有四种:RANGE,LIST,HASH,KEY.其中,RANGE又可分为原生RANGE和RANGE COLUMNS,LIST分为原生LIST和LIST COLUMNS,HA ...
- 辗转相除法求最大公约数,非goto
#include<iostream> using namespace std; //不推荐用goto,当然用它更快 //辗转相除法求两数的最大公约数 int gcd(long int a, ...