基于FPGA的图像处理(五)--状态机
2012-11-29 22:14
471 查看
使用FPGA实现各种算法时,状态机是很常用的方法,在SysGen中有两种非常简便的方法构建状态机,一是使用Mcode,以switch-case语句轻松实现,二是使用SysGen自带状态机模块。
状态机
假设我们要从01序列中检测出1011序列,则状态机模型如下
Next State Matrix:[0 1; 2 1; 0 3; 2 1]
Output Matrix : [0 0; 0 0; 0 0; 0 1]
一、使用Mcode实现
上一篇博客讲解了在Sysgen中Mcode的限制能力,这里直接使用
构建模型如下:
Singal From Workspace用于产生一个01序列,作为输入信号。
gatwayIn将数据类型转化为UFix_1_0
添加Mcode函数stateMcode.m
Scope效果如图:
二、使用Mealy State Machine模块实现
构建模型:
设置Mealy State Machine参数,就是状态机的参数
仿真结果如下:
在进行FPGA图像处理时,经常会用到状态机,这几天刚学习过,记录一下,其实使用Verilog直接实现也不是很难,只是会比SysGen稍微麻烦一些,修改起来也会花费更多的时间。
Model Based Design 在Xilinx 的工具中逐渐得到加强,相信以后会更加的方便。
状态机
假设我们要从01序列中检测出1011序列,则状态机模型如下
Next State Matrix:[0 1; 2 1; 0 3; 2 1]
Output Matrix : [0 0; 0 0; 0 0; 0 1]
一、使用Mcode实现
上一篇博客讲解了在Sysgen中Mcode的限制能力,这里直接使用
构建模型如下:
Singal From Workspace用于产生一个01序列,作为输入信号。
gatwayIn将数据类型转化为UFix_1_0
添加Mcode函数stateMcode.m
function [nextState, matched] = stateMcode(currentState, din) % This is the update function for detecting a pattern of 1011 % This function represents a stateless and combination logic block. % The output nextState should be to a register, and the output % of the register should be fed back to the input currentState. % Because the state register block has a feed back connection, in % order to propagate the port prototypes automatically, the prototype % of nextState should be determined only by constants or through % an explicity xfix() call. seen_none = 0; % initial state, if input is 1, switch to seen_1 seen_1 = 1; % first 1 has been seen, if input is 0, switch % seen_10 seen_10 = 2; % 10 has been detected, if input is 1, switch to % seen_1011 seen_101 = 3; % now 101 is detected, is input is 1, 1011 is % detected and the FSM switches to seen_1 % the default value of matched is false matched = false; switch currentState case seen_none if din==1 nextState = seen_1; else nextState = seen_10; end case seen_1 % seen first 1 if din==1 nextState = seen_1; else nextState = seen_10; end case seen_10 % seen 10 if din==1 nextState = seen_101; else % no part of sequence seen, go to seen_none nextState = seen_none; end case seen_101 if din==1 nextState = seen_1; matched = true; else nextState = seen_10; matched = false; end otherwise % if nextState is not assigned outside the switch statement, % an otherwise statment is required nextState = seen_none; end
Scope效果如图:
二、使用Mealy State Machine模块实现
构建模型:
设置Mealy State Machine参数,就是状态机的参数
仿真结果如下:
在进行FPGA图像处理时,经常会用到状态机,这几天刚学习过,记录一下,其实使用Verilog直接实现也不是很难,只是会比SysGen稍微麻烦一些,修改起来也会花费更多的时间。
Model Based Design 在Xilinx 的工具中逐渐得到加强,相信以后会更加的方便。
相关文章推荐
- 基于FPGA的图像处理(五)--状态机
- 基于FPGA的图像处理(三)--图像融合
- FPGA图像处理系列——基于ZEDBoard构建图像处理通路(Block Ram版本)
- 基于FPGA+DSP的实时图像处理平台的设计与实现
- 基于DSP和FPGA的通用图像处理平台设计
- FPGA verilog做基于模板的图像处理的方法
- 数据算法基于FPGA的图像处理(七)--Verilog实现均值滤波Strut2教程-java教程
- 基于FPGA的图像处理(六)--Shared Memory
- 基于FPGA的图像处理(六)--Shared Memory
- 基于Halide的图像处理应用CPU-FPGA异构计算加速
- 基于ARM+FPGA+多DSP的嵌入式实时图像处理系统
- 基于FPGA的图像处理(一)--System Generator介绍
- 基于FPGA的图像处理(一)--System Generator介绍
- 基于FPGA的图像处理(二)--System Generator入门
- 基于FPGA视频图像处理系统设计
- 基于FPGA的图像处理--基本概念导图
- 基于FPGA的图像处理(二)--System Generator入门
- 基于FPGA的图像处理(七)--Verilog实现均值滤波
- 基于FPGA的图像处理(四)--Matlab Language supported by Mcode
- 基于FPGA的图像处理(四)--Matlab Language supported by Mcode