基于小脚丫DDS 调频 调幅 调相 切换波形 AD5601输出模拟波形

先讲讲里面的矩阵键盘,矩阵键盘列有下拉电阻,默认全为0000,默认行输入为1111,当有按键按下的时候,列输入会被拉高,这时控制行的输出做行扫描,电子琴用key_flag_r0电平作为使能,这里用key_flag消抖后与键值进行按位与,作为相应按键的判断条件。

module juzhen
(
input clk,
input rst_n,
input [3:0] col_data,
output reg [3:0] row_data,
output key_flag, //the mark of key is pressed
output reg [3:0] key_value,

output reg key_flag_r0
);
parameter SCAN_IDLE = 3‘b000;
parameter SCAN_JITTER= 3‘b001;
parameter SCAN_COL0 = 3‘b011;
parameter SCAN_COL1 = 3‘b010;
parameter SCAN_COL2 = 3‘b110;
parameter SCAN_COL3 = 3‘b100;
parameter SCAN_READ = 3‘b101;
parameter SCAN_JTTTER2= 3‘b111;

reg [19:0] cnt;
reg [2:0] current_state;
reg [2:0] next_state;
always @(posedge clk or negedge rst_n)begin
if(!rst_n) begin cnt<=0; end
else
begin
if(cnt>=20‘h7ffff) begin cnt<=0;end
else cnt<=cnt+1;end
end
[email protected](posedge clk or negedge rst_n)
begin
if(!rst_n)
current_state <= SCAN_IDLE;
else if(cnt == 20‘h7ffff) current_state <= next_state;
end
[email protected]*
begin case(current_state)
SCAN_IDLE : //init
if(col_data != 4‘b0000) next_state = SCAN_JITTER; //初始化
else next_state = SCAN_IDLE;
SCAN_JITTER: //escape the jitter
if(col_data != 4‘b0000) next_state = SCAN_COL0;//消除抖动
else next_state = SCAN_IDLE;
SCAN_COL0 : //1th row
if(col_data != 4‘b0000) next_state = SCAN_READ;else next_state = SCAN_COL1;
SCAN_COL1 : //2th row
if(col_data != 4‘b0000) next_state = SCAN_READ;else next_state = SCAN_COL2;
SCAN_COL2 : //3th row
if(col_data != 4‘b0000) next_state = SCAN_READ;else next_state = SCAN_COL3;
SCAN_COL3 : //4th row
if(col_data != 4‘b0000) next_state = SCAN_READ;else next_state = SCAN_IDLE;
SCAN_READ : //lock the vaule
if(col_data != 4‘b0000) next_state = SCAN_JTTTER2;else next_state = SCAN_IDLE;
SCAN_JTTTER2: //when your hand is gone
if(col_data != 4‘b0000) next_state = SCAN_JTTTER2;else next_state = SCAN_IDLE;
endcase
end
reg [3:0] col_data_r;
reg [3:0] row_data_r;

[email protected](posedge clk or negedge rst_n)

begin if(!rst_n) begin row_data <= 4‘b1111;key_flag_r0 <= 0;end
else if(cnt == 20‘h7ffff)begin
case(next_state)
SCAN_IDLE : begin row_data <= 4‘b1111;key_flag_r0 <= 0;end //SCAN_JITTER:
SCAN_COL0 : row_data <= 4‘b0001;
SCAN_COL1 : row_data <= 4‘b0010;
SCAN_COL2 : row_data <= 4‘b0100;
SCAN_COL3 : row_data <= 4‘b1000;
SCAN_READ : begin
row_data_r <= row_data;
col_data_r <= col_data;
key_flag_r0 <= 1;
end
//SCAN_JTTTER2:
default:; //default vaule
endcase
end
end
always @(posedge clk or negedge rst_n)
begin if(!rst_n)key_value <= 0;
else if(cnt == 20‘h7fff)
begin
if(key_flag_r0 == 1‘b1) //the mark of key is pressed
begin
case ({row_data_r,col_data_r}) //row_data Row, col_data Col
8‘b0001_0001: key_value <= 4‘d0;
8‘b0010_0001: key_value <= 4‘d1;
8‘b0100_0001: key_value <= 4‘d2;
8‘b1000_0001: key_value <= 4‘d3;
8‘b0001_0010: key_value <= 4‘d4;
8‘b0010_0010: key_value <= 4‘d5;
8‘b0100_0010: key_value <= 4‘d6;
8‘b1000_0010: key_value <= 4‘d7;
8‘b0001_0100: key_value <= 4‘d8;
8‘b0010_0100: key_value <= 4‘d9;
8‘b0100_0100: key_value <= 4‘d10;
8‘b1000_0100: key_value <= 4‘d11;
8‘b0001_1000: key_value <= 4‘d12;
8‘b0010_1000: key_value <= 4‘d13;
8‘b0100_1000: key_value <= 4‘d14;
8‘b1000_1000: key_value <= 4‘d15;
default : key_value <= key_value;
endcase
end
else
key_value <= key_value;
end
end
//Capture the falling endge
reg key_flag_r2,key_flag_r1;
[email protected](posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
key_flag_r1 <= 0;
key_flag_r2 <= 0;
end
else
begin
key_flag_r1 <= key_flag_r0;
key_flag_r2 <= key_flag_r1;
end
end
assign key_flag = key_flag_r2 & ~key_flag_r1; //when your hand is gone
endmodule

幅度相位 波形选择频率控制模块

module ddsout
(
output reg [7:0]data,
input cs,
output [3:0] row,
input [3:0]col,
input sclk,
input rst_n,
input clk
);

wire [3:0] key_value;
juzhen xiaodou
(
.clk(clk),
.rst_n(rst_n),
.col_data(col),
.row_data(row),
.key_flag(key_flag),
.key_value(key_value)
);
reg [8:0] adress;
reg[3:0]cnt1,cnt2;
[email protected](posedge clk or negedge rst_n)
begin

if(!rst_n)begin cnt1<=1;end
else if(cnt1==15)cnt1<=1;
else if(key_value==2&key_flag==1) cnt1<=cnt1+1;

end
[email protected](posedge clk or negedge rst_n)
begin

if(!rst_n)begin cnt2<=1;end
else if(cnt2==15)cnt2<=1;
else if(key_value==6&key_flag==1) cnt2<=cnt2+1;

end

reg [15:0] adress_r;
[email protected](posedge sclk or negedge rst_n)
begin
if(!rst_n) adress_r<=0;
else adress_r<=adress_r+cnt1;频率控制字

end
always @(posedge sclk)
if(!rst_n)adress<=0;
else if(adress>511)adress=0;
else
adress<=adress_r[15:7]+cnt2;相位控制字

wire [7:0]sina_data,san_data,fang_data,ju_data;
sina sina_ut
(
.Address(adress),
.OutClock (sclk),
.OutClockEn(cs),
.Reset(0),
.Q(sina_data)
);

san san_ut
(
.Address(adress),
.OutClock (sclk),
.OutClockEn(cs),
.Reset(0),
.Q(san_data)
);
fang fang_ut
(
.Address(adress),
.OutClock (sclk),
.OutClockEn(cs),
.Reset(0),
.Q(fang_data)
);
ju ju_ut
(
.Address(adress),
.OutClock (sclk),
.OutClockEn(cs),
.Reset(0),
.Q(ju_data)
); //ROM模块调用,可以参考这位大神的调用http://www.cnblogs.com/tony-ning/p/4971053.html

reg [1:0]cnt3;//波形选择
reg[1:0]cnt4;//幅度调节
[email protected](posedge clk or negedge rst_n)
if(~rst_n)cnt3<=0;

else if(key_value==3&key_flag==1)
cnt3<=cnt3+1;
else if(cnt3>3)cnt3<=0;
else cnt3<=cnt3;
[email protected](posedge clk or negedge rst_n)
if(!rst_n)cnt4<=0;
else if(key_value==7&key_flag==1)
cnt4<=cnt4+1;
else if(cnt4>3)cnt4<=0;
else cnt4<=cnt4;
reg [7:0]data_reg;

always @(cnt3)

if(! rst_n) data_reg<=sina_data;
else begin
case(cnt3)
0:data_reg<=sina_data;
1:data_reg<=san_data;
2:data_reg<=fang_data;
3:data_reg<=ju_data;
default:data_reg<=sina_data;
endcase
end

[email protected](posedge sclk )
if( !rst_n)data=data_reg;
else begin
case(cnt4)
0:data=data_reg;
1:data=data_reg>>1;
2:data=data_reg>>2;
3:data=data_reg>>3;
default:data=data_reg;
endcase
end

endmodule

DAC输出模块

module ad5601spi//mode:cpol=1,cpha=0;
(
input [7:0] q,
input clk,
input rst_n,
output reg sclk,
output reg cs,
output reg sdin
);
reg [2:0] cnt;
reg[5:0]state;
[email protected](posedge clk or negedge rst_n)
begin
if(!rst_n)begin cnt<=0;sclk<=1;end
else if(cnt==4)begin cnt<=0;sclk<=1;end
else if(cnt<=2)begin cnt<=cnt+1;sclk<=1;end
else begin cnt<=cnt+1;sclk<=0;end
end
reg [15:0] data;

always @(posedge clk or negedge rst_n)
if(!rst_n)begin state<=0; cs=1;sdin=0;end
else begin
case(state)
0: begin if(cnt==1)begin cs<=0;data={2‘b00,q[7:0],6‘b000000};state<=state+1;end else begin state<=0;cs<=1;end end
1:if(cnt==2) begin sdin<=data[15];state<=state+1;end
2:if(cnt==2) begin sdin<=data[14];state<=state+1;end
3:if(cnt==2) begin sdin<=data[13];state<=state+1;end
4:if(cnt==2) begin sdin<=data[12];state<=state+1;end
5:if(cnt==2) begin sdin<=data[11];state<=state+1;end
6:if(cnt==2) begin sdin<=data[10];state<=state+1;end
7:if(cnt==2) begin sdin<=data[9];state<=state+1;end
8:if(cnt==2) begin sdin<=data[8];state<=state+1;end
9:if(cnt==2) begin sdin<=data[7];state<=state+1;end
10:if(cnt==2) begin sdin<=data[6];state<=state+1;end
11:if(cnt==2) begin sdin<=data[5];state<=state+1;end
12:if(cnt==2) begin sdin<=data[4];state<=state+1;end
13:if(cnt==2) begin sdin<=data[3];state<=state+1;end
14:if(cnt==2) begin sdin<=data[2];state<=state+1;end
15:if(cnt==2) begin sdin<=data[1];state<=state+1;end
16:if(cnt==2) begin sdin<=data[0];state<=state+1;end
17:if(cnt==2)begin state<=0;cs<=1;end
endcase
end

endmodule//spi下降沿准备数据 AD5601接受数据

时间: 2024-10-24 14:50:50

基于小脚丫DDS 调频 调幅 调相 切换波形 AD5601输出模拟波形的相关文章

一款基于jquery超炫的图片切换特效

今天为给大家介绍一款基于jquery超炫的图片切换特效.由百叶窗飞入显示图片.图片消息的时候也是百叶窗渐行渐远.用于图片展示,效果还是非常好,我们一起看下效果图: 在线预览   源码下载 来看下实现的代码.注意了,这里有引用jquery和underscore插件. html代码: <div class="wrap"> <div class="box active" style="background-image: url(img/1.jp

基于CSS3鼠标经过立体翻转切换特效

基于CSS3鼠标经过立体翻转切换特效.这是一款基于jQuery+CSS3实现的鼠标经过封面和详情3D翻转切换特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="wrapbox YaHei"> <div class="cont-box"> <div class="regularly-box"> <div class="regularly-head&qu

基于jQuery全屏焦点图切换插件responsiveslides

基于jQuery全屏焦点图切换插件responsiveslides是一款带左右箭头,索引按钮的自动轮播切换特效下载.效果图如下: 在线预览   源码下载 实现的代码. html代码: <script type="text/javascript"> $(function () { // Slideshow $("#slider").responsiveSlides({ auto: true, pager: false, nav: true, speed:

基于HTML5 SVG全屏滑块切换特效

基于HTML5 SVG全屏滑块切换特效是一款基于jQuery+HTML5实现的全屏动画切换特效代码.效果图如下: 在线预览   源码下载 实现的代码. html代码: <section class="cd-slider-wrapper"> <ul class="cd-slider"> <li class="visible"> <div style=" position:fixed; z-inde

基于jQuery左侧大图右侧小图切换代码

基于jQuery左侧大图右侧小图切换代码是一款带右侧缩略图选项卡的jQuery图片切换特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="examples_body"> <div class="examples_bg"> <div class="examples_image"> <img src="images/sample_banner1.jpg&

基于STM32F030F4P9和STM32 CUBEMX 输出PWM波形

STM32F030F4P9定时器功能比较丰富,在此记录项目中使用其自动输出PWM波形(频率:50HZ).CubeMX配置定时器如下图说明. 在此定时器基础时钟为48MHZ,配置中不做分频处理,预分频系数为48,定时器计数器寄存器为20000,可求得周期为: T = ( ( 1 / (48Mhz / 48) ) * 20000) = 20ms 在PWM输出配置选项中,改变Pulse可改变PWM的占空比.CH Polarity配置当计数器中的值小于Pulse时,输出高电平, CH Idle Stat

STM32F4_TIM输出PWM波形(可调频率、占空比)

Ⅰ.概述 上一篇文章关于STM32基本的计数原理明白之后,该文章是在其基础上进行拓展,讲述关于STM32比较输出的功能,以输出PWM波形为实例来讲述. 提供实例工程中比较实用的函数:只需要调用该函数,参数为频率和占空比 void TIM2_CH2_PWM(uint32_t Freq, uint16_t Dutycycle); 先看一下实例中1KHz.20%占空比波形图 TIM2_CH2_PWM(1000, 20); 关于本文的更多详情请往下看. Ⅱ.实例工程下载 笔者针对于初学者提供的例程都是去

STM32f103ZET6 TIM8输出PWM波形

定时器8属于高级定时器,只存在于大容量产品的103系列中,定时器8输出PWM波形时与通用定时器2.3.4.5不同,必须同时开启主输出(TIM8->BDTR|=0x8000;)才能产生PWM波,其配置如下: 1 /********************************************* 2 函数名称:void TIM4_PWM_Init(u16 arr,u16 psc) 3 功 能:通用TIM4 CH1(PB6) CH2(PB7)PWM输出初始化 4 入 参:arr:自动重装值.

Modelsim设置数据以模拟波形显示

选中希望以模拟波形显示的信号,右击选择format->Analog(automatic) 如果你的数据是用无符号数表示一个完整的波形的,那么可能显示出来的波形样子是下面的样子,不过不要紧,这是因为modelsim默认是按照有符号数据解析波形数据的缘故,我们可以再进行一次设置修改. 选中希望显示波形的信号,右击,选择Radix->Unsigned. 设置完成后,波形就如下所示了: 是不是发现虽然波形已经是完整的正弦波了,但是波形有部分却跑到其他信号的地盘去了呢?这也不要紧,是模拟波形的显示范围设