资源描述:
《verilog编写的延时函数》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Verilog编写的延时函数用quartus编译通过,并口用modelsim进彳亍了后仿真老师让编写一个程序实现开关的延吋控制,具体要求是开关量变高电平后延吋500ms输出波形PWM1变为高,在延时500msPWM2输出波形变为高,在延时500msPWM3输出变为高电平。当开关量变为低电平时,一次延时500ms,PWM3,PWM2,PWM1一次变为高电平。源程序如下:moduletestosc(osc_in,osc_out,clk_in,clk_out,input_signal,PWM1,PWM2,PWM3,start,signal_buffcr);inputosc
2、_in,clk_in,input_signal;outputPWM1,PWM2,PWM3,start;outputosc_out,clk_out;outputsignal_buffer;regPWM1,PWM2,PWM3,osc_out,clk_out,start;//outl,out2,out3,out4,out5,out6,out7,out&out9,outlO,outll,outl2,outl3,outl4,outl5,outl6,outl7,outl8,outl9,out20,out21,out22,out23,out24,out25,out26,out27
3、,out2&out29,out30,out31,out32;rcg[10:0]count;regsignal_buffer;initialbeginPWMl<=l,b0;PWM2<=rbO;PWM3<=rbO;start<=rbO;count〈二11'dO;signal_buffer<=rbO;endalways@(osc_in)beginif(osc_in二二1)beginosc_out<=0;clk_out<=0;endelsebeginosc_out〈二1;clk_out<=l;endendalways©(posedgeclkin)begin辻(inputsi
4、gnal二二1'bO)begincase(count)1TdO:if(signal_buffer==rbl)//distinguishthetriggersignalsstart<=rbl;elsestart<=rbO;ll,d2:PWM3<=l,bO;ird4:PWM2<=rbO;11'd6:beginPWM1〈二1'bO;start〈二1'bO;sigrml_buffcr〈二1’bO;//remembertheinputsignalenddefault:beginPWM1VPWM1;PWM2<=PWM2;PWM3<=PWM3;endendcaseendelseb
5、egincase(count)1TdO:if(signalbuffer二二1'bO)start〈二1'bl;elsestart<=TbO;ll,d2:PWMl<=l,bl;ll'd4:PWM2Vl'bl;1Td6:beginPWM3〈二l'bl;start<=rbO;signal_buffer<=rbl;enddefault:beginPWM1<=PWM1;PWM2<=PWM2;PWM3〈二PWM3;endendcaseendendalways@(posedgeclk_inornegedgesteirt)if(start==rbO)count〈二11'dO;else
6、if(count>lrdl500)count<=lrdO;elsecount<=count+irdl;endmodulequartus仿真波形:elk.iBmimenw3by"B7、是误差不会大于1ms,可以忽略。希望能帮到你们。