基于FPGA的洗衣机控制器电子定时器
文章目录
功能描述
一、框架
二、verilog代码
控制模块实现
三、视频上板效果展示
功能描述
(1)定时启动正转20秒暂停10秒反转20秒暂 停10秒,定时未到回到“正转20秒暂停10秒……”,定时到则停止; 若定时到,则停机发出音响信号;
(2)用两个数码管显示洗涤的预置时间(默认10分钟),再用两个数码管按倒计时方式对各个洗涤状态过程作计时显示,直到 时间到停机;(3)洗涤过程由“开始”信号开始;
(4)三只LED灯表示“正转”,“反转”、“暂停”三个状态。
(5)用动态扫描控制四个数码管的输出
一、框架
输入:时钟、复位、开始按键
输出:LED指示灯 数码管段选和位选
这个板子段选是38译码器,所以sel是3位bit
二、verilog代码
控制模块实现
主要思想就是通过两层状态机进行控制:
首先控制空闲状态、工作状态以及结束状态。
其中围绕工作状态展开进行二次状态设计,正转、反转以及暂停等等。
module control(input clk,input rst_n,input key_start,output wire led_R,output wire led_L,output wire led_P,output reg [7:0] data_time,output reg [7:0] sec_time);//����״̬�����С�������ֹͣparameter IDLE =3'd0;parameter WORKING =3'd1;parameter OVER =3'd2;//����״̬�µ�״̬����ת ֹͣ ��תparameter W_IDLE =4'd0;parameter R_ROTATE =4'd1;parameter PAUSE1 =4'd2;parameter L_ROTATE =4'd3;parameter PAUSE2 =4'd4;reg [2:0] state_all;reg [3:0] state;//10����
// reg [7:0] data_time;
// reg [7:0] sec_time;//��reg [25:0] count;assign led_R=(state_all==WORKING)?(state==R_ROTATE)?1'b1:1'b0:1'b0;assign led_L=(state_all==WORKING)?(state==L_ROTATE)?1'b1:1'b0:1'b0;assign led_P=(state_all==WORKING)?(state==PAUSE1 || state==PAUSE2)?1'b1:1'b0:1'b0;//10����always @(posedge clk or negedge rst_n) beginif(!rst_n) begindata_time<=8'h10;endelse if(state_all==WORKING && state==PAUSE2 && count==49999999 && sec_time==8'h00)beginif(data_time[3:0]==4'h0 && data_time[7:4]>4'h0)begindata_time[3:0]<=4'h9;data_time[7:4]<=data_time[7:4]-4'd1;endelse if(data_time[3:0]>4'h0 && data_time[7:4]>=4'h0)begindata_time[3:0]<=data_time[3:0]-4'd1;data_time[7:4]<=data_time[7:4];endelse if(data_time[3:0]==4'h0 && data_time[7:4]==4'h0)begindata_time[3:0]<=data_time[3:0];data_time[7:4]<=data_time[7:4];endendelse if(state_all==IDLE || state_all==OVER )begindata_time<=8'h10;endend
//��ת�ͷ�ת����ͣ������always @(posedge clk or negedge rst_n) beginif(!rst_n) beginsec_time<=8'h20;endelse if(count==49999999 && (state==R_ROTATE || state==L_ROTATE))beginif(sec_time[3:0]==4'h0 && sec_time[7:4]>4'h0)beginsec_time[3:0]<=4'h9;sec_time[7:4]<=sec_time[7:4]-4'd1;endelse if(sec_time[3:0]>4'h0 && sec_time[7:4]>=4'h0)beginsec_time[3:0]<=sec_time[3:0]-4'd1;sec_time[7:4]<=sec_time[7:4];endelse if(sec_time[3:0]==4'h0 && sec_time[7:4]==4'h0)beginsec_time<=8'h10;endendelse if(count==49999999 && (state==PAUSE1 || state==PAUSE2))beginif(sec_time[3:0]==4'h0 && sec_time[7:4]>4'h0)beginsec_time[3:0]<=4'h9;sec_time[7:4]<=sec_time[7:4]-4'd1;endelse if(sec_time[3:0]>4'h0 && sec_time[7:4]>=4'h0)beginsec_time[3:0]<=sec_time[3:0]-4'd1;sec_time[7:4]<=sec_time[7:4];endelse if(sec_time[3:0]==4'h0 && sec_time[7:4]==4'h0)beginsec_time<=8'h20;endendelse if(state==W_IDLE)beginsec_time<=8'h20;endend //1��������always @(posedge clk or negedge rst_n) beginif(!rst_n) begincount<=26'd0;endelse if(state==R_ROTATE || state==PAUSE1|| state==L_ROTATE|| state==PAUSE2)beginif(count<49999999)begincount<=count+1;endelse begincount<=26'd0;endendelse begincount<=26'd0;endend//��״̬�л�always @(posedge clk or negedge rst_n) beginif(!rst_n) beginstate <= W_IDLE;endelse if(state_all==WORKING)begincase(state)W_IDLE:beginstate<=R_ROTATE;endR_ROTATE:beginif(count==49999999 && sec_time==8'h00)beginstate<=PAUSE1;endelse beginstate<=R_ROTATE;endendPAUSE1:beginif(count==49999999 && sec_time==8'h00)beginstate<=L_ROTATE;endelse beginstate<=PAUSE1;endendL_ROTATE:beginif(count==49999999 && sec_time==8'h00)beginstate<=PAUSE2;endelse beginstate<=L_ROTATE;endendPAUSE2:beginif(count==49999999 && sec_time==8'h00)beginstate<=W_IDLE;endelse beginstate<=PAUSE2;endenddefault:state <= W_IDLE;endcaseendelse beginstate <= W_IDLE;endend //�ܹ���״̬�л�always @(posedge clk or negedge rst_n) beginif(!rst_n) beginstate_all <= IDLE;endelse begincase(state_all)IDLE:beginif(key_start==1'b1)beginstate_all<=WORKING;endelse beginstate_all<=IDLE;endendWORKING:beginif(data_time==8'h00)beginstate_all<=OVER;endelse beginstate_all<=WORKING;endendOVER:beginstate_all<=IDLE;enddefault:state_all <= IDLE;endcaseendend
endmodule
三、视频上板效果展示
基于fpga的洗衣机控制器 定时器