正弦脉宽调制波(PWM)的verilog文档

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

modulepwm_1phase(clk,rst,pwm);inputclk;inputrst;outputpwm;wire[9:0]q1;wire[7:0]q2;wire[7:0]rom_data;wire[7:0]rom_addr;wireclk_9;reg[6:0]cnt;reg[7:0]CNT;assignclk_9=q1[9];assignCLK_0=q1[0];always@(posedgeclk_9ornegedgerst)if(!rst)cnt=0;elseif(cnt==125)cnt=0;elsecnt=cnt+1;assignrom_addr=cnt;always@(posedgeCLK_0ornegedgerst)if(!rst)CNT=0;elseif(clk_9==0&&CNT!=255)CNT=CNT+1;elseif(clk_9==1&&CNT!=0)CNT=CNT-1;elseCNT=CNT;assignq2=CNT;counter1my_counter1(.CLK(clk),.RST(rst),.Q1(q1));rom_126datamy_rom_126_data(.ROM_DATA(rom_data),.ROM_ADDR(rom_addr));comp_rom_countermy_comp_rom_counter(.RST(rst),.CLK(clk),.PWM(pwm),.ROM_DATA(rom_data),.Q2(q2));endmodulemodulecounter1(CLK,RST,Q1);inputCLK,RST;output[9:0]Q1;reg[9:0]cnt;always@(posedgeCLKornegedgeRST)if(!RST)cnt=0;elsecnt=cnt+1;assignQ1=cnt;endmodulemodulerom_126data(ROM_DATA,ROM_ADDR);input[7:0]ROM_ADDR;output[7:0]ROM_DATA;reg[7:0]ROM[125:0];assignROM_DATA=ROM[ROM_ADDR];initial$readmemb(rom_pwm.txt,ROM,0,125);endmodulemodulecomp_rom_counter(RST,CLK,PWM,ROM_DATA,Q2);outputPWM;input[7:0]ROM_DATA;input[7:0]Q2;inputCLK;inputRST;regPWM;always@(posedgeCLKornegedgeRST)if(!RST)PWM=0;elseif(Q2ROM_DATA)PWM=1;elseif(Q2ROM_DATA)PWM=0;elseif(Q2==255&ROM_DATA==255)PWM=0;elseif(Q2==0&ROM_DATA==0)PWM=1;elsePWM=PWM;endmodulemoduletestbench;wirepwm_t;regclk_t;regrst_t;pwm_1phasemy_pwm_1phase(.clk(clk_t),.rst(rst_t),.pwm(pwm_t));initialbeginrst_t=1;#10rst_t=0;#10rst_t=1;endinitialbeginclk_t=0;forever#1clk_t=~clk_t;endendmodule100000001000011010001100100100111001100110011111101001101010110010110010101101111011110111000011110010001100110111010010110101111101110011100000111001001110100011101100111011111111001011110101111101111111100111111011111111011111111011111111111111111111111111111111111111111111111011111101111111001111101011111000111101101111001111110000111011011110101011100110111000101101111011011001110101011101000011001011110001011100000010111010101101011010111110101001101000101001110010010110100100001000100110000011011111000111011001101111011010010110001101011101010101100101000001001010010001010011111100111010001101000010111100101010001001100010000100011101000110010001010100010010000011110000110000001001000001110000010100000011000000100000000100000000000000000000000000000000000000000000000100000010000001000000011000001000000010100000110100010000000100110001011100011011000111110010001100101000001011010011001000110111001111000100001001001000010011010101001101011001011000000110011001101100011100110111100101111111

1 / 7
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功