Chisel3 - Tutorial - VendingMachineSwitch
import chisel3._
import chisel3.util._ // Problem:
//
// Implement a vending machine using a 'switch' statement.
// 'nickel' is a 5 cent coin
// 'dime' is 10 cent coin
// 'sOk' is reached when there are coins totalling 20 cents or more in the machine.
// The vending machine should return to the 'sIdle' state from the 'sOk' state.
//
class VendingMachineSwitch extends Module {
val io = IO(new Bundle {
val nickel = Input(Bool())
val dime = Input(Bool())
val valid = Output(Bool())
})
val sIdle :: s5 :: s10 :: s15 :: sOk :: Nil = Enum(5)
val state = RegInit(sIdle) switch (state) {
is (sIdle) {
when (io.nickel) { state := s5 }
when (io.dime) { state := s10 }
}
is (s5) {
when (io.nickel) { state := s10 }
when (io.dime) { state := s15 }
}
is (s10) {
when (io.nickel) { state := s15 }
when (io.dime) { state := sOk }
}
is (s15) {
when (io.nickel) { state := sOk }
when (io.dime) { state := sOk }
}
is (sOk) {
state := sIdle
}
}
io.valid := (state === sOk)
} object VendingMachineSwitchMain {
def main(args: Array[String]): Unit = {
chisel3.Driver.execute(Array("--target-dir", "generated/VendingMachineSwitch"), () => new VendingMachineSwitch)
}
}
Chisel3 - Tutorial - VendingMachineSwitch的更多相关文章
- Chisel3 - Tutorial - VendingMachine
https://mp.weixin.qq.com/s/tDpUe9yhwC-2c1VqisFzMw 演示如何使用状态机. 参考链接: https://github.com/ucb-bar/ch ...
- Chisel3 - Tutorial - Tbl
https://mp.weixin.qq.com/s/e8vJ8claauBtiuedxYYaJw 实现可以动态索引的表. 参考链接: https://github.com/ucb-bar/c ...
- Chisel3 - Tutorial - Stack
https://mp.weixin.qq.com/s/-AVJD1IfvNIJhmZM40DemA 实现后入先出(last in, first out)的栈. 参考链接: https://gi ...
- Chisel3 - Tutorial - Functionality
https://mp.weixin.qq.com/s/3hDzpJiANdwp07hO03psyA 演示使用函数进行代码复用的方法. 参考链接: https://github.com/ucb- ...
- Chisel3 - Tutorial - Parity
https://mp.weixin.qq.com/s/OtiQnE52PwdCpvmzJ6VFnA 奇偶发生器.统计输入中1的个数,如果为偶数则输出0,奇数则输出1. 参考链接: https: ...
- Chisel3 - Tutorial - ByteSelector
https://mp.weixin.qq.com/s/RQg2ca1rwfVHx_QG-IOV-w 字节选择器. 参考链接: https://github.com/ucb-bar/chisel ...
- Chisel3 - Tutorial - ShiftRegister
https://mp.weixin.qq.com/s/LKiXUgSnt3DzgFLa9zLCmQ 简单的寄存器在时钟的驱动下,逐个往下传值. 参考链接: https://github.com ...
- Chisel3 - Tutorial - Adder
https://mp.weixin.qq.com/s/SEcVjGRL1YloGlEPSoHr3A 位数为参数的加法器.通过FullAdder级联实现. 参考链接: https://githu ...
- Chisel3 - Tutorial - Adder4
https://mp.weixin.qq.com/s/X5EStKor2DU0-vS_wIO-fg 四位加法器.通过FullAdder级联实现. 参考链接: https://github.co ...
随机推荐
- SpringBoot:模板引擎 thymeleaf、ContentNegotiatingViewResolver、格式化转换器
目录 模板引擎 thymeleaf ContentNegotiatingViewResolver 格式化转换器 模板引擎 thymeleaf.ContentNegotiatingViewResolve ...
- jquery注册页面的判断及代码的优化
今天主要负责完成注册页面的jquery代码的写入与优化,基本代码和登录页面差不多,复制修改一下代码就行了,主要区别在于多了一个重复密码与密码是否一致的判断,刚开始写出来的代码导致每个框的后面都追加重复 ...
- [hdu5400 Arithmetic Sequence]预处理,容斥
题意:http://acm.hdu.edu.cn/showproblem.php?pid=5400 思路:预处理出每个点向左和向右的最远边界,从左向右枚举中间点,把区间答案加到总答案里面.由与可能与前 ...
- [hdu5340]二分,枚举,二进制压位加速
题意:判断一个字符串能否划成三段非空回文串. 思路:先用二分+hash在nlogn的时间内求出以每条对称轴为中心的回文串的最大半径r[i](可以用对称的两个下标之和来表示 ),然后利用r[i]求出pr ...
- [zoj3593]扩展欧几里得+三分
题意:给一个数A,有6种操作,+a,-a,+b,-b,+(a+b),-(a+b),每次选择一种,用最少的次数变成B. 思路:由于不同的操作先后顺序对最后的结果没有影响,并且加一个数与减一个相同的数不能 ...
- 帝国cms 批量替换 字段内容包含的 指定的 关键字 SQL命令
帝国cms 批量替换 字段内容包含的 指定的 关键字update phome_ecms_news_data_1 set newstext=replace(newstext,'原来','现在');
- python--制作微信好友照片墙
知识来源:https://zhuanlan.zhihu.com/p/73975013 1.环境 os:MAC tool:python 3.7 ,pip3.7 2.前提: 使用pip3.7 instal ...
- 14.1 Go数据结构
14.1 Go数据结构 每一个程序都在学习十八般武艺,学习语言.数据库.HTTP等技能. 而程序中的九阳神功就是数据结构与算,掌握了数据结构与算法,你的内功修炼就会有质的飞跃. 无论从事业务开发,测评 ...
- 为什么我不建议你通过 Python 去找工作?
二哥,你好,我是一名大专生,学校把 Python 做为主语言教给我们,但是我也去了解过,其实 Python 门槛挺高的,所以我在自学 Java,但是我现在并不清楚到底要不要全心的去学 Java,学校里 ...
- xcode搜索路径缩写
$(inherited) 这个$(inherited)可用于将构建设置从project级别继承到target级别.拿添加pod依赖遇到的问题来说就是,当前工程target级别没有继承项目级别的配置,所 ...