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. ...
随机推荐
- Java多线程系列--“JUC锁”10之 CyclicBarrier原理和示例
概要 本章介绍JUC包中的CyclicBarrier锁.内容包括:CyclicBarrier简介CyclicBarrier数据结构CyclicBarrier源码分析(基于JDK1.7.0_40)Cyc ...
- MySQL Dll语句
标签:MYSQL数据库/DBA/删除数据库表 概述 因为遇到一些事情,从发表上一篇文章到现在中间间隔了好几个月时间:在接下来的时间里会陆续发表关于mysql的一些文章,从基础到优化最后到管理,欢迎关注 ...
- Socket programing(make a chat software) summary 1:How to accsess LAN from WAN
First we should know some basic conceptions about network: 1.Every PC is supposed to have its own IP ...
- Java this的一两点使用
Java this的一两点使用 之前的文章都是关于Android的使用,这次想写一些关于Java的知识,总结一下Java的使用.这次写的是关于Java this的使用,介绍以下内容: this的概念 ...
- Xcode升级 Alcatraz 无法使用
Alcatraz 主要是可以管理xcode 插件 随着 Xcode 的更新 Alcatraz 有可能无法使用 以下是解决办法: 1,关闭Xcode 2,如果已经安装过 Alcatraz,先卸载掉,然后 ...
- Atitit sql计划任务与查询优化器--统计信息模块
Atitit sql计划任务与查询优化器--统计信息模块 每一个统计信息的内容都包含以上三部分的内容. 我们依次来分析下,通过这三部分内容SQL Server如何了解该列数据的内容分布的. a.统计信 ...
- WPF入门教程系列二十二——DataGrid示例(二)
DataGrid示例的后台代码 1) 通过Entity Framework 6.1 从数据库(本地数据库(local)/Test中的S_City表中读取城市信息数据,从S_ Province表中读取 ...
- Uiautomator 2.0之Configrator类学习小记
1. Configration类介绍 1.1. Configrator用于设置脚本动作的默认延时 1.2 Configrator功能: 1.2.1 可调节两个模拟动作之间的默认间隔 1.2.2 可调 ...
- 【源码】谷歌代理~WPF简单小软件-2015-10-15首发 (2016-03-01已更新源)
蛋疼,昨天把代理去了后才发现,原来咱们连谷歌应用都访问不了,,,用别人的总觉得不怎么安全,然后今天早上就编了个小软件干掉他这限制==> GoogleProxy.exe [主要目的:为了能在线安 ...
- ClickOnce部署(1):一些发布方式
ClickOnce是什么玩意儿,这个问题嘛,在21世纪的互联网严重发达的时代,估计也没有必要大费奏章去介绍了,弄不好的话,还有抄袭之嫌.因此,有关ClickOnce的介绍,各位朋友可以直接查找MSDN ...