全自动洗衣机的设计Verilog程序文件.docx
- 文档编号:10958588
- 上传时间:2023-05-28
- 格式:DOCX
- 页数:23
- 大小:116.11KB
全自动洗衣机的设计Verilog程序文件.docx
《全自动洗衣机的设计Verilog程序文件.docx》由会员分享,可在线阅读,更多相关《全自动洗衣机的设计Verilog程序文件.docx(23页珍藏版)》请在冰点文库上搜索。
全自动洗衣机的设计Verilog程序文件
实验报告
学院:
大数据与信息工程学院
专业:
电子与通信工程
学号:
2015021718
学生:
鹏举
指导教师:
良荣
2016年5月24
一、实验题目3
二、实验目的3
三、实验要求3
四、洗衣机工作原理与功能说明3
状态图如下4
程序RTL视图如下4
五、详细代码如下5
模块一实现洗衣机状态转换和各状态输出控制5
模块二实现复位信号的异步复位同步释放11
模块三实现当前状态的数码管显示12
模块四实现按键检测13
模块五实现顶层的调用15
一、
实验题目
自动洗衣机设计
二、实验目的
1、熟练掌握QuartusII工程文件的建立过程。
2、掌握Verilog的基本语法、语句、模块的使用。
3、了解模块的建立与使用。
4、了解FPGA的开发基本流程。
三、实验要求
1、初始状态,准备启动。
2、开始进水;为防止进水过程出现故障,故不用定时器控制,而是手动给一个信号模拟水位检测传感器,表示进水完成。
3、开始洗涤:
正反洗涤4次开始排水。
4、排水后立即脱水。
5、洗涤之后漂洗2次,每次漂洗过后都排水甩干。
6、整个过程全部用数码管来显示状态机状态,并用两个led灯表示电机的正转与反转状态。
四、洗衣机工作原理与功能说明
自动洗衣机的工作原理:
洗衣机有7个工作状态分别为空闲(idle)、加水(water)、洗衣(wash)、排水(drain)、甩干(dry)、漂洗(rinse)、结束音乐提示(music)。
一次完整的洗涤,进水3次、洗涤1次、漂洗两次、排水3次、甩干3次。
一次完整的状态转换为:
空闲(idle)、加水(water)、洗衣(wash)、排水(drain)、甩干(dry)、加水(water)、漂洗(rinse)、排水(drain)、甩干(dry)、加水(water)、漂洗(rinse)、排水(drain)、甩干(dry)、结束音乐提示(music)。
程序功能说明:
程序有4个输入start启动信号、water_test水满检测信号,水满了就置一、drain_test排水检测,水排完了就置一、emergency紧急停止信号,任何情况下输入都进入idle状态,即停止工作。
一开上电过后系统处于空闲状态,当输入信号start后进入加水状态,水满过后进入浸泡状态,浸泡完毕进入洗衣状态,洗衣完毕进入排水状态,第一次排水完毕进入甩干状态,第一次甩干完成进入加水状态,第二次加水完成后进入第一次漂洗状态,第一次漂洗完毕进入第二次排水状态,排水完毕进入第二次甩干状态,第二次甩干完毕进入第三次加水状态,再进入第二次漂洗状态,第三次排水状态,第三次甩干状态,进入结束音乐提醒状态,回到空闲状态。
洗衣服和漂洗为洗衣电机的低速档位,在排水过程中将电机档位变为高档位。
当甩干完毕变到其他状态时,就把电机档位变到低档位。
洗涤和漂洗时,电机正转和反转之间有3秒钟的延时(即让电机自动减速,不至于电机突然反转时负荷太大烧毁电机)。
状态图如下
程序RTL视图如下
4个输入由外部按键输入,经过模块key按键消抖确定按键是否被按下。
按键输入到模块washer作为一些状态转换的条件。
washer的状态输出到数码管显示模块segmain显示系统当前处于什么状态。
系统有4个输出clockwise正转信号0表示转,1表示不转、
anticlockwise反转信号0表示转,1表示不转、finish结束信号0表示结束,1表示未结束、cstate表示当前状态。
经调试实现了想要的功能。
五、详细代码如下
模块一实现洗衣机状态转换和各状态输出控制
//----------------------------------------------------
//用1段式状态机,分成3段来写
//----------------------------------------------------
modulewasher(
clk,
rst_n,
start,
water_test,//水满信号
drain_test,//排水检测
emergency,//紧急情况处理
clockwise,//正转信号
anticlockwise,//反转信号
finish,//结束信号
level,//档位显示0为高档位1为低档位
cstate//用于显示处于哪个状态
);
parameteridle=0,
inwater=1,
steep=2,//浸泡
wash=3,//洗涤
drain=4,//排水
dry=5,
rinse=6,//漂洗
music=7;
regsteep_test;//浸泡结束信号
regwash_test;//洗涤结束信号
regdry_test;//甩干结束信号
regrinse_test;//漂洗结束信号
regmusic_test;//音乐结束信号
inputclk,rst_n;//时钟复位
inputstart;//启动信号
inputwater_test;//水满信号
inputdrain_test;//排水检测
inputemergency;//紧急停止信号
outputregclockwise;//正转信号0表示转,1表示不转
outputreganticlockwise;//反转信号0表示转,1表示不转
outputregfinish;//结束信号0表示结束,1表示未结束
output[2:
0]cstate;//表示现在的状态
outputreglevel;//显示电机档位
reg[2:
0]cstate_r;
assigncstate=cstate_r;
reg[1:
0]water_time;//洗涤一次漂洗两次
reg[1:
0]drain_time;//排水三次
reg[1:
0]dry_time;//甩干三次
always(posedgeclk)
if(~rst_n)begin
cstate_r<=idle;
end
else
begin
case(cstate_r)
idle:
if(start)begin//0
cstate_r<=inwater;//一开始就进入进水状态
end
elsecstate_r<=idle;
//1
inwater:
if(emergency)cstate_r<=idle;//遇到紧急情况就停止
elseif(water_test)
begin
case(water_time)
2'b00:
cstate_r<=steep;//水满了就进入浸泡状态
2'b01:
cstate_r<=rinse;
2'b10:
cstate_r<=rinse;
default:
;
endcase
end
elsecstate_r<=inwater;
//2
steep:
if(emergency)cstate_r<=idle;//遇到紧急情况就停止
elseif(steep_test)cstate_r<=wash;//浸泡完毕就进入洗涤状态
elsecstate_r<=steep;
//3
wash:
if(emergency)cstate_r<=idle;//遇到紧急情况就停止
elseif(wash_test)cstate_r<=drain;//洗完就进入排水状态
elsecstate_r<=wash;
//4
drain:
if(emergency)cstate_r<=idle;
elseif(drain_test)begin
cstate_r<=dry;
end
elsecstate_r<=drain;
//5
dry:
if(emergency)cstate_r<=idle;
elseif(dry_test)begin
case(dry_time)
2'b01:
cstate_r<=inwater;
2'b10:
cstate_r<=inwater;
2'b11:
cstate_r<=music;
default:
;
endcase
end
elsecstate_r<=dry;
//6
rinse:
if(emergency)cstate_r<=idle;
elseif(rinse_test)
cstate_r<=drain;
elsecstate_r<=rinse;
//7
music:
if(emergency)cstate_r<=idle;
elseif(music_test)cstate_r<=idle;
elsecstate_r<=music;
default:
cstate_r<=idle;
endcase
end
reg[28:
0]counter;
reg[3:
0]num;
//regin_water;
always(posedgeclkornegedgerst_n)
begin
if(~rst_n)begin
steep_test<=1'b0;
wash_test<=1'b0;
dry_test<=1'b0;
rinse_test<=1'b0;
music_test<=1'b0;
water_time<=2'd0;
drain_time<=2'd0;
dry_time<=2'd0;
counter<=29'd0;
num<=4'd0;
music_test<=1'b0;
clockwise<=1'b1;
anticlockwise<=1'b1;
finish<=1'b1;
end
elsebegin
case(cstate_r)
idle:
begin//0
music_test<=1'b0;//音乐结束信号复位
clockwise<=1'b1;
anticlockwise<=1'b1;//电机旋转方向信号
finish<=1'b1;//结束信号
wash_test<=1'b0;//洗涤完成信号复位
rinse_test<=1'b0;
dry_test<=1'b0;//将甩干标志清零
steep_test<=1'b0;//将浸泡结束标志位复位
music_test<=1'b0;
end
inwater:
begin//1water_test不用置零
clockwise<=1'b1;
anticlockwise<=1'b1;
level<=1'b1;//档位跳到低位档
dry_test<=1'b0;//将甩干标志清零
if(water_test)begin//进水完成信号为外部输入信号
if(water_time==2'b11)begin
water_time<=2'b00;
end
elsewater_time<=water_time+1'b1;
end
end
steep:
begin//2
clockwise<=1'b1;
anticlockwise<=1'b1;
if(counter==29'd250000000)begin
counter<=29'd0;
steep_test<=1'b1;//浸泡10秒钟浸泡完成
end
elsecounter<=counter+1'b1;
end
wash:
begin//3
steep_test<=1'b0;//将浸泡结束标志位复位
case(num)
4'd0:
begin
clockwise<=1'b0;//正转5秒
anticlockwise<=1'b1;
end
4'd1:
begin
clockwise<=1'b1;//停转3秒
anticlockwise<=1'b1;
end
4'd2:
begin
clockwise<=1'b1;//反转5秒
anticlockwise<=1'b0;
end
4'd3:
begin
clockwise<=1'b1;//停转3秒
anticlockwise<=1'b1;
end
4'd4:
begin
clockwise<=1'b0;//正转5秒
anticlockwise<=1'b1;
end
4'd5:
begin
clockwise<=1'b1;//停转3秒
anticlockwise<=1'b1;
end
4'd6:
begin
clockwise<=1'b1;//反转5秒
anticlockwise<=1'b0;
end
4'd7:
begin
num<=4'd0;
wash_test<=1'b1;//下一个状态置零
clockwise<=1'b1;
anticlockwise<=1'b1;
end
default:
begin
clockwise<=1'b1;
anticlockwise<=1'b1;
end
endcase
if(num==1||num==3||num==5)
begin
if(counter==29'd150000000)//延时3秒
begin
counter<=29'd0;
num<=num+1'b1;
end
elsecounter<=counter+1'b1;
end
elseif(counter==29'd250000000)begin
counter<=29'd0;
num<=num+1'b1;
end
elsecounter<=counter+1'b1;
end
drain:
begin//4drain_test不用置零
clockwise<=1'b1;
anticlockwise<=1'b1;
wash_test<=1'b0;//洗涤完成信号复位
rinse_test<=1'b0;//漂洗完成信号复位
level<=1'b0;//调节档位到高档位
if(drain_test)begin//排水信号为外部输入信号
if(drain_time==2'b11)begin//排水3次
drain_time<=2'b00;
end
elsedrain_time<=drain_time+1'b1;
end
end
dry:
begin//5
clockwise<=1'b0;//甩干正转信号置1
anticlockwise<=1'b1;
if(counter==29'd250000000)begin
counter<=29'd0;
clockwise<=1'b1;//停止正转
anticlockwise<=1'b1;
dry_test<=1'b1;//甩干完成未清零所以一次跳两个状态
if(dry_time==2'b11)begin
dry_time<=2'b00;
end
elsedry_time<=dry_time+1'b1;
end
elsecounter<=counter+1'b1;
end
rinse:
begin//6
case(num)
4'd0:
begin
clockwise<=1'b0;//正转5秒
anticlockwise<=1'b1;
end
4'd1:
begin
clockwise<=1'b1;//停止转动3秒
anticlockwise<=1'b1;
end
4'd2:
begin
clockwise<=1'b1;//反转5秒
anticlockwise<=1'b0;
end
4'd3:
begin
rinse_test<=1'b1;
num<=3'd0;
clockwise<=1'b1;//停止转动
anticlockwise<=1'b1;
end
default:
;
endcase
if(num==1)
begin
if(counter==29'd150000000)//延时3秒
begin
counter<=29'd0;
num<=num+1'b1;
end
elsecounter<=counter+1;
end
elseif(counter==29'd250000000)
begin//延时5秒
counter<=29'd0;
num<=num+1'b1;
end
elsecounter<=counter+1'b1;
end
music:
begin//7
clockwise<=1'b1;
anticlockwise<=1'b1;
level<=1'b1;//将档位调到低档位
dry_test<=1'b0;//将甩干完成信号复位
finish<=1'b0;//结束将结束信号置1
if(counter==29'd50000000)begin
counter<=29'd0;
music_test<=1'b1;
end
elsecounter<=counter+1'b1;
end
default:
;
endcase
end
end
endmodule
模块三实现当前状态的数码管显示
modulesegmain(
clk,
rst_n,
datain,
seg_data,
seg_
);
inputclk;
inputrst_n;
input[2:
0]datain;
output[7:
0]seg_data;
outputseg_;
reg[7:
0]seg_data;
reg[2:
0]bcd_led;
reg[18:
0]count;
assignseg_=1'b0;
always(posedgeclk)
begin
if(~rst_n)
begin
count<=19'd0;
end
else
count<=count+1'b1;
end
always(posedgeclk)
begin
if(count[18])
begin
bcd_led<=datain;
end
end
always(bcd_led)
begin
case(bcd_led)
4'h0:
seg_data=8'hc0;//0共阳低有效
4'h1:
seg_data=8'hf9;//1
4'h2:
seg_data=8'ha4;//2
4'h3:
seg_data=8'hb0;//3
4'h4:
seg_data=8'h99;//4
4'h5:
seg_data=8'h92;//5
4'h6:
seg_data=8'h82;//6
4'h7:
seg_data=8'hf8;//7
//4'h8:
seg_data=8'h80;//8
//4'h9:
seg_da
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 全自动 洗衣机 设计 Verilog 程序 文件