基于FPGA的洗衣机控制器电子定时器

文章目录

功能描述

一、框架

二、verilog代码

控制模块实现

三、视频上板效果展示



功能描述

(1)定时启动正转20秒暂停10秒反转20秒暂 停10秒,定时未到回到"正转20秒暂停10秒......",定时到则停止; 若定时到,则停机发出音响信号;

(2)用两个数码管显示洗涤的预置时间(默认10分钟),再用两个数码管按倒计时方式对各个洗涤状态过程作计时显示,直到 时间到停机;(3)洗涤过程由"开始"信号开始;

(4)三只LED灯表示"正转","反转"、"暂停"三个状态。

(5)用动态扫描控制四个数码管的输出

一、框架

输入:时钟、复位、开始按键

输出:LED指示灯 数码管段选和位选

这个板子段选是38译码器,所以sel是3位bit

二、verilog代码

控制模块实现

主要思想就是通过两层状态机进行控制:

首先控制空闲状态、工作状态以及结束状态。

其中围绕工作状态展开进行二次状态设计,正转、反转以及暂停等等。

Matlab 复制代码
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) begin
    if(!rst_n) begin
        data_time<=8'h10;
    end
    else if(state_all==WORKING && state==PAUSE2 && count==49999999 && sec_time==8'h00)begin
        if(data_time[3:0]==4'h0 && data_time[7:4]>4'h0)begin
            data_time[3:0]<=4'h9;
            data_time[7:4]<=data_time[7:4]-4'd1;
        end
        else if(data_time[3:0]>4'h0 && data_time[7:4]>=4'h0)begin
            data_time[3:0]<=data_time[3:0]-4'd1;
            data_time[7:4]<=data_time[7:4];
        end
        else if(data_time[3:0]==4'h0 && data_time[7:4]==4'h0)begin
            data_time[3:0]<=data_time[3:0];
            data_time[7:4]<=data_time[7:4];
        end
    end
    else if(state_all==IDLE || state_all==OVER )begin
        data_time<=8'h10;
    end
    end    
Matlab 复制代码
   
    //��ת�ͷ�ת����ͣ������
    always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        sec_time<=8'h20;
    end
    else if(count==49999999 && (state==R_ROTATE || state==L_ROTATE))begin
        if(sec_time[3:0]==4'h0 && sec_time[7:4]>4'h0)begin
            sec_time[3:0]<=4'h9;
            sec_time[7:4]<=sec_time[7:4]-4'd1;
        end
        else if(sec_time[3:0]>4'h0 && sec_time[7:4]>=4'h0)begin
            sec_time[3:0]<=sec_time[3:0]-4'd1;
            sec_time[7:4]<=sec_time[7:4];
        end
        else if(sec_time[3:0]==4'h0 && sec_time[7:4]==4'h0)begin
            sec_time<=8'h10;
        end
    end
    else if(count==49999999 && (state==PAUSE1 || state==PAUSE2))begin
        if(sec_time[3:0]==4'h0 && sec_time[7:4]>4'h0)begin
            sec_time[3:0]<=4'h9;
            sec_time[7:4]<=sec_time[7:4]-4'd1;
        end
        else if(sec_time[3:0]>4'h0 && sec_time[7:4]>=4'h0)begin
            sec_time[3:0]<=sec_time[3:0]-4'd1;
            sec_time[7:4]<=sec_time[7:4];
        end
        else if(sec_time[3:0]==4'h0 && sec_time[7:4]==4'h0)begin
            sec_time<=8'h20;
        end
    end
    else if(state==W_IDLE)begin
        sec_time<=8'h20;
    end
    end    
    
    //1��������
    always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        count<=26'd0;
    end
    else if(state==R_ROTATE || state==PAUSE1|| state==L_ROTATE|| state==PAUSE2)begin
        if(count<49999999)begin
            count<=count+1;
        end
        else begin
            count<=26'd0;
        end
    end
    else begin
        count<=26'd0;
    end
    end
    
    
    
    //��״̬�л�
    always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        state <= W_IDLE;
        end
    else if(state_all==WORKING)begin
        case(state)
        W_IDLE:begin
            state<=R_ROTATE;
        end
        R_ROTATE:begin
            if(count==49999999 && sec_time==8'h00)begin
                state<=PAUSE1;
            end
            else begin
                state<=R_ROTATE;
            end
        end
        PAUSE1:begin
            if(count==49999999 && sec_time==8'h00)begin
                state<=L_ROTATE;
            end
            else begin
                state<=PAUSE1;
            end
        end
        L_ROTATE:begin
            if(count==49999999 && sec_time==8'h00)begin
                state<=PAUSE2;
            end
            else begin
                state<=L_ROTATE;
            end
        end
        PAUSE2:begin
            if(count==49999999 && sec_time==8'h00)begin
                state<=W_IDLE;
            end
            else begin
                state<=PAUSE2;
            end
        end
        default:state <= W_IDLE;
        endcase
    end
    else begin
        state <= W_IDLE;
    end
    end    
    
    //�ܹ���״̬�л�
    always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        state_all <= IDLE;
        end
    else begin
        case(state_all)
        IDLE:begin
            if(key_start==1'b1)begin
                state_all<=WORKING;
            end
            else begin
                state_all<=IDLE;
            end
        end
        WORKING:begin
            if(data_time==8'h00)begin
                state_all<=OVER;
            end
            else begin
                state_all<=WORKING;
            end
        end
        OVER:begin
                state_all<=IDLE;
        end
        default:state_all <= IDLE;
        endcase
    end
    
    
    end
endmodule

三、视频上板效果展示

基于fpga的洗衣机控制器 定时器

相关推荐
尤老师FPGA10 天前
使用DDR4控制器实现多通道数据读写(十六)
fpga开发·ddr4
HX科技10 天前
STM32给FPGA的外挂FLASH进行升级
stm32·嵌入式硬件·fpga开发·flash·fpga升级
sz66cm10 天前
FPGA基础 -- Verilog 驱动强度(drive strength)与电荷强度(charge strength)
fpga开发
海涛高软10 天前
FPGA深度和突发长度计算
fpga开发
hahaha601610 天前
vivado使用非自带的第三方编辑器
fpga开发
芝士不会写代码11 天前
【FPGA学习】DDS信号发生器设计
学习·fpga开发
9527华安11 天前
国产安路FPGA实现MIPI视频解码转HDMI输出,基于SC500摄像头,提供TD工程源码和技术支持
fpga开发·音视频·csi·mipi·dphy·安路fpga·sc500
可编程芯片开发11 天前
基于FPGA的白噪声信号发生器verilog实现,包含testbench和开发板硬件测试
fpga开发·白噪声·snr
风释雪FPGA11 天前
[XILINX]ZYNQ7010_7020_软件LVDS设计
fpga开发
XINVRY-FPGA11 天前
XCVU47P-2FSVH2892E Xilinx Virtex UltraScale+ FPGA AMD
c语言·c++·人工智能·嵌入式硬件·阿里云·fpga开发·fpga