Verilog语言编写正弦波,锯齿波,余弦波程序实现数控振荡器_第1页
Verilog语言编写正弦波,锯齿波,余弦波程序实现数控振荡器_第2页
Verilog语言编写正弦波,锯齿波,余弦波程序实现数控振荡器_第3页
Verilog语言编写正弦波,锯齿波,余弦波程序实现数控振荡器_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、module sin(reset,clk,sync,freq,sin_out,cos_out; input reset; input clk; input sync; input 7:0 freq; output 7:0 sin_out; output 7:0 cos_out; reg 7:0 sin_out; reg 7:0 cos_out; reg 7:0 phase; reg 5:0 max_phase; reg 7:0 output_zeros; reg 5:0 sin_index; reg 7:0 sin_table; reg 1:0 phase_d1; reg 1:0 phase_

2、d2; reg 5:0 cos_index; reg 7:0 cos_table; assign saw_out=phase15 : 8; always(posedge reset or posedge clk begin if (reset=1'b1 phase<=8'b0; else begin if (sync=1'b1 phase<=8'b0; else phase<=phase+freq; end end always(posedge clk or posedge reset begin if (reset=1'b1 phas

3、e=8'b0000000; else if(clk begin if (sync=1'b1 phase=8'b00000000; else phase=phase+freq; end end always (posedge clk or posedge reset begin if (reset=1'b1 begin sin_index =1'b0; phase_d1 =2'b00; end else if(clk begin phase_d1=phase7 : 6; if (phase6=1'b0 sin_index=phase5:0;

4、 else sin_index=max_phase-phase5 : 0; end end always(posedge clk or posedge reset begin if (reset=1'b1 begin sin_index =1'b0; phase_d2 =2'b00; end else if(clk begin phase_d2 =phase_d1; case (sin_index5:0 6'b000000 : sin_index=8'b00000000; 6'b000001 : sin_index=8'b00000011

5、; 6'b000010 : sin_index=8'b00000110; 6'b000011 : sin_index=8'b00001001; 6'b000100 : sin_index=8'b00001100; 6'b000101 : sin_index=8'b00001111; 6'b000110 : sin_index=8'b00010010; 6'b000111 : sin_index=8'b00010101; 6'b001000 : sin_index=8'b0001100

6、0; 6'b001001 : sin_index=8'b00011011; 6'b001010 : sin_index=8'b00011110; 6'b001011 : sin_index=8'b00100001; 6'b001100 : sin_index=8'b00100100; 6'b001101 : sin_index=8'b00100111; 6'b001110 : sin_index=8'b00101010; 6'b001111 : sin_index=8'b001011

7、01; 6'b010000 : sin_index=8'b00110000; 6'b010001 : sin_index=8'b00110011; 6'b010010 : sin_index=8'b00110110; 6'b010011 : sin_index=8'b00111001; 6'b010100 : sin_index=8'b00111011; 6'b010101 : sin_index=8'b00111110; 6'b010110 : sin_index=8'b01000

8、001; 6'b010111 : sin_index=8'b01000011; 6'b011000 : sin_index=8'b01000110; 6'b011001 : sin_index=8'b01001001; 6'b011010 : sin_index=8'b01001011; 6'b011011 : sin_index=8'b01001110; 6'b011100 : sin_index=8'b01010000; 6'b011101 : sin_index=8'b0101

9、0010; 6'b011110 : sin_index=8'b01010101; 6'b011111 : sin_index=8'b01010111; 6'b100000 : sin_index=8'b01011001; 6'b100001 : sin_index=8'b01011011; 6'b100010 : sin_index=8'b01011110; 6'b100011 : sin_index=8'b01100000; 6'b100100 : sin_index=8'b011

10、00010; 6'b100101 : sin_index=8'b01100100; 6 9;b100110 : sin_index=8'b01100110; 6'b100111 : sin_index=8'b01100111; 6'b101 000 : sin_index=8'b01101001; 6'b101001 : sin_index=8'b01101011; 6'b101010 : sin_index=8'b01101100; 6'b101011 : sin_index=8'b011

11、01110; 6'b101100 : sin_index=8'b01110000; 6'b101101 : sin_index=8'b01110001; 6'b101110 : sin_index=8'b01110010; 6'b101111 : sin_index=8'b01110100; 6'b110000 : sin_index=8'b01110101; 6'b110001 : sin_index=8'b01110110; 6'b110010 : sin_index=8'b01

12、110111; 6'b110011 : sin_index=8'b01111000; 6'b110100 : sin_index=8'b01111001; 6'b110101 : sin_index=8'b01111010; 6'b110110 : sin_index=8'b01111011; 6'b110111 : sin_index=8'b01111011; 6'b111000 : sin_index=8'b01111100; 6'b111001 : sin_index=8'b0

13、1111101; 6'b111010 : sin_index=8'b01111101; 6'b111011 : sin_index=8'b01111110; 6'b111100 : sin_index=8'b01111110; 6'b111101 : sin_index=8'b01111110; 6'b111110 : sin_index=8'b01111110; 6'b111111 : sin_index=8'b01111110; default : sin_index=8'b000000

14、00; endcase end end always(posedge clk or posedge reset begin if (reset=1'b1 sin_out =1'b0; else if (clk begin if (phase_d21=1'b0 sin_out = sin_table; else sin_out=output_zeros-sin_table; end end always (posedge clk or posedge reset begin if (reset=1'b1 cos_index =1'b0; else if(c

15、lk begin if (phase6=1'b0 cos_index=phase5:0; else cos_index=max_phase-phase5 : 0; end end always(posedge clk or posedge reset begin if (reset=1'b1 cos_table =1'b0; else if(clk case (cos_index5:0 6'b000000 : cos_table=8'b01111111; 6'b000001 : cos_table=8'b01111110; 6'b

16、000010 : cos_table=8'b01111110; 6'b000011 : cos_table=8'b01111110; 6'b000100 : cos_table=8'b01111110; 6'b000101 : cos_table=8'b01111110; 6'b000110 : cos_table=8'b01111101; 6'b000111 : cos_table=8'b01111101; 6'b001000 : cos_table=8'b01111100; 6'

17、b001001 : cos_table=8'b01111011; 6'b001010 : cos_table=8'b01111011; 6'b001011 : cos_table=8'b01111010; 6'b001100 : cos_table=8'b01111001; 6'b001101 : cos_table=8'b01111000; 6'b001110 : cos_table=8'b01110111; 6'b001111 : cos_table=8'b01110110; 6'

18、;b010000 : cos_table=8'b01110101; 6'b010001 : cos_table=8'b01110100; 6'b010010 : cos_table=8'b01110010; 6'b010011 : cos_table=8'b01110001; 6'b010100 : cos_table=8'b01110000; 6'b010101 : cos_table=8'b01101110; 6'b010110 : cos_table=8'b01101100; 6

19、9;b010111 : cos_table=8'b01101011; 6'b011000 : cos_table=8'b01101001; 6'b011001 : cos_table=8'b01100111; 6'b011010 : cos_table=8'b0110011 0; 6'b011011 : cos_table=8'b01100100; 6'b011100 : cos_table=8'b01100010; 6'b011101 : cos_table=8'b01100000; 6&

20、#39;b011110 : cos_table=8'b01011110; 6'b011111 : cos_table=8'b01011011; 6'b100000 : cos_table=8'b01011001; 6'b100001 : cos_table=8'b01010111; 6'b100010 : cos_table=8'b01010101; 6'b100011 : cos_table=8'b01010010; 6'b100100 : cos_table=8'b01010000; 6

21、'b100101 : cos_table=8'b01001110; 6'b100110 : cos_table=8'b01001011; 6'b100111 : cos_table=8'b01001001; 6'b101000 : cos_table=8'b01000110; 6'b101001 : cos_table=8'b01000011; 6'b101010 : cos_table=8'b01000001; 6'b101011 : cos_table=8'b00111110;

22、6'b101100 : cos_table=8'b00111011; 6'b101101 : cos_table=8'b00111001; 6'b101110 : cos_table=8'b00110110; 6'b101111 : cos_table=8'b00110011; 6'b110000 : cos_table=8'b00110000; 6'b110001 : cos_table=8'b00101101; 6'b110010 : cos_table=8'b00101010; 6'b110011 : cos_table=8'b00100111; 6'b110100 : cos_ta

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论