Verilog实现手表计时

实现手表的计时功能:

1.具有start启动信号、pause暂停信号,可以自定义其触发机制。

2.具有时间更改接口,可以更改时、分、秒。

3.输出时、分、秒。

Verilog设计

模块端口定义:

module watch1(input   wire            clk         ,input   wire            rst_n       ,input   wire            start       ,   //input   wire            pause       ,   //input   wire            h_add       ,   //when it is 1, hour   will add 1(when changing the time, the current time do not count)input   wire            m_add       ,   //when it is 1, minute will add 1(when changing the time, the current time do not count)input   wire            s_add       ,   //when it is 1, second will add 1(when changing the time, the current time do not count)output  reg     [4:0]   hour        ,output  reg     [5:0]   minute      ,output  reg     [5:0]   second           // second+1 per period
);

手表计时使能:

always@(posedge clk or negedge rst_n)if(!rst_n) running <= 1'b0;else if(pause && start)     //push the keys in the same time, the watch still runsrunning <= 1'b1;//running;keep the stateelse if(pause)     //running <= 1'b0;else if(start)     //running <= 1'b1;else ;

或者:

always@(posedge clk or negedge rst_n)if(!rst_n) running <= 1'b0;else if(start_rise)     //push the key, the watch will run(higher priority)running <= 1'b1;else if(pause_rise)     //push the key, the watch will stoprunning <= 1'b0;// else if(start_fall)     //release the key, the watch will run//     running <= 1'b1;else ;

小时:

always@(posedge clk or negedge rst_n)if(!rst_n) hour <= 'b0;else if(h_add) beginif(hour == CNT_23)hour <= 'b0;elsehour <= hour + 1'b1;endelse if(running & ~m_add & ~s_add ) begin    //when changing the time, the current time do not countif(second == CNT_59 && minute == CNT_59) beginif(hour == CNT_23)hour <= 'b0;elsehour <= hour + 1'b1;endelse ;endelse ;

分钟:

always@(posedge clk or negedge rst_n)if(!rst_n) minute <= 'b0;else if(m_add) beginif(minute == CNT_59)minute <= 'b0;elseminute <= minute + 1'b1;endelse if(running & ~s_add & ~h_add ) begin    //when changing the time, the current time do not countif(second == CNT_59) beginif(minute == CNT_59)minute <= 'b0;elseminute <= minute + 1'b1;endelse ;endelse ;

秒:

always@(posedge clk or negedge rst_n)if(!rst_n) second <= 'b0;else if(s_add) beginif(second == CNT_59)second <= 'b0;elsesecond <= second + 1'b1;endelse if(running & ~m_add & ~h_add ) begin    //when changing the time, the current time do not countif(second == CNT_59)second <= 'b0;elsesecond <= second + 1'b1;    // second+1 per periodendelse ;

仿真波形

时钟进位:

启动&暂停:

或者:

顶层集成

//
module watch_top(input   wire            clk         ,input   wire            rst_n       ,input   wire            start_key   ,   //按键:开始计时(按下按键时均为0)input   wire            pause_key   ,   //按键:暂停计时input   wire            h_key       ,   //按键:时+1input   wire            m_key       ,   //按键:分+1input   wire            s_key       ,   //按键:秒+1output  wire    [4:0]   hour        ,   //时output  wire    [5:0]   minute      ,   //分output  wire    [5:0]   second          //秒(每时钟周期+1)
);// parameter ======================================================// wire =============================================================
wire start;
wire pause;
wire h_add;
wire m_add;
wire s_add;// reg =============================================================// assign =============================================================// always ==========================================================// instantiation ======================================================================
//
key_filter u_start_filter(.clk        (clk   ),.rst_n      (rst_n ),.key_in     (start_key),.key_flag   ( ),.key_out    (start),.key_cont   ()
);
key_filter u_pause_filter(.clk        (clk   ),.rst_n      (rst_n ),.key_in     (pause_key),.key_flag   ( ),.key_out    (pause),.key_cont   ()
);
//
key_filter u_h_filter(.clk        (clk   ),.rst_n      (rst_n ),.key_in     (h_key),.key_flag   ( ),.key_out    (),.key_cont   (h_add)
);
key_filter u_m_filter(.clk        (clk   ),.rst_n      (rst_n ),.key_in     (m_key),.key_flag   ( ),.key_out    (),.key_cont   (m_add)
);
key_filter u_s_filter(.clk        (clk   ),.rst_n      (rst_n ),.key_in     (s_key),.key_flag   ( ),.key_out    (),.key_cont   (s_add)
);
//
watch2 u_watch(.clk         (clk   ),.rst_n       (rst_n ),.start       (start ),   //.pause       (pause ),   //.h_add       (h_add ),   //when it is 1, hour   will add 1.m_add       (m_add ),   //when it is 1, minute will add 1.s_add       (s_add ),   //when it is 1, second will add 1.hour        (hour  ),.minute      (minute),.second      (second) 
);endmodule

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/614829.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Java】Set集合的基本使用

&#x1f4dd;个人主页&#xff1a;哈__ 期待您的关注 一、HashSet集合 1.HashSet集合的特点 2.HashSet常用方法 ①&#xff1a;add(Object o)&#xff1a;向Set集合中添加元素&#xff0c;不允许添加重复数据。 ②&#xff1a;size()&#xff1a;返回Set集合中的元素个数…

空腹血糖正常情况下,针刺感觉的成因是什么?

前一阵&#xff0c;在好大夫看到一则北京崇文门医院朱学敏大夫看诊时案例&#xff1a; “患者就诊&#xff0c;询问得知患者没有用降糖药&#xff0c;目前空腹餐后血糖升高&#xff0c;达到7.7左右&#xff0c;餐后大概在11.5-11.9之间。”整体来说&#xff0c;患者血糖还是偏…

一文读懂Java中的WebEndpointProperties类(附Demo)

目录 前言1. 基本知识2. Demo3. 彩蛋 前言 对于Java的相关知识&#xff0c;推荐阅读&#xff1a;java框架 零基础从入门到精通的学习路线 附开源项目面经等&#xff08;超全&#xff09; 1. 基本知识 Spring Boot 的配置类 WebEndpointProperties&#xff0c;用于配置 Web 端…

用c++实现串匹配问题、选择排序

5.2.2 串匹配问题 【问题】 给定两个字符串S和T&#xff0c;在主串S中查找子串T的过程称为串匹配(string matching,也称模式匹配&#xff09;&#xff0c;T称为模式。在文本处理系统、操作系统、编译系统、数据库系统以及 Internet 信息检索系统中&#xff0c;串匹配是使用最频…

【c++】优先级队列|反向迭代器(vector|list)

优先级队列的常用函数的使用 #include<iostream> #include<queue> using namespace std;int main() {priority_queue<int>st;st.push(1);st.push(7);st.push(5);st.push(2);st.push(3);st.push(9);while (!st.empty()){cout << st.top() << &qu…

Linux第89步_了解异步通知及其结构和函数

1、了解“异步通知” “异步通知”的核心就是信号。信号是采用软件模拟的“中断”&#xff0c;它由“驱动程序”主动向“应用程序”发送信号&#xff0c;并报告自己可以访问了&#xff0c;“应用程序”收到信号以后&#xff0c;就从“驱动设备”中读取或者写入数据。整个过程就…

数字化用户投稿发表论文

《数字化用户》是由国家新闻出版总署批准的正规期刊。本刊坚持科学发展观&#xff0c;响应我国数字化信息时代的方针、政策和发展战略&#xff1b;探讨数字化建设的规划、方案和成果&#xff1b;交流数字化技术和应用的实例和经验&#xff1b;推广数字新技术、科技新理念&#…

C盘满了怎么办,清理工具TreeSize

TreeSize是一款强大的磁盘空间分析工具&#xff0c;它可以帮助用户轻松地找出电脑中占用空间最多的文件和程序&#xff0c;从而让用户进行针对性地删除或卸载。 占用空间很小 下载链接&#xff1a;https://pan.quark.cn/s/bea23ed6b1d3

电动车新国标迎来修订机会,用户的真实需求能被满足吗?

文&#xff5c;新熔财经 作者&#xff5c;宏一 自2019年4月《电动自行车安全技术规范》发布至今&#xff0c;电动车的新国标标准已经实施5年&#xff0c;市场上的争议也此起彼伏地持续了5年。 因为新国标对电动车的各项技术标准提出的明确要求&#xff0c;其中&#xff0c;最…

Docker 学习笔记(七):介绍 Dockerfile 相关知识,使用 Dockerfile 构建自己的 centos 镜像

一、前言 记录时间 [2024-4-12] 系列文章简摘&#xff1a; Docker学习笔记&#xff08;二&#xff09;&#xff1a;在Linux中部署Docker&#xff08;Centos7下安装docker、环境配置&#xff0c;以及镜像简单使用&#xff09; Docker 学习笔记&#xff08;三&#xff09;&#x…

MathJax —— Vue3的使用方法

版本&#xff1a; mathjax3 需要实现效果 一、使用方式 1. index.html 中引入 <!-- 识别单行&#xff0c;行内&#xff0c;\( \)样式的公式 --><script>MathJax {tex: {inlineMath: [[$, $],[$$, $$], [\\(, \\)]]},};</script><script id"MathJ…

使用vite从头搭建一个vue3项目(二)创建目录文件夹以及添加vue-router

目录 一、创建 vue3 项目 vite-vue3-project-js二、创建项目目录三、创建Home、About组件以及 vue-router 配置路由四、修改完成后页面 一、创建 vue3 项目 vite-vue3-project-js 使用 vite 创建一个极简 vue3 项目请参考此文章&#xff1a;使用Vite创建一个vue3项目 下面是我…