MATLAB DESIGN HDL CODER RELEASE NOTES User's Guide Page 62

  • Download
  • Add to my manuals
  • Print
  • Page
    / 410
  • Table of contents
  • TROUBLESHOOTING
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 61
62 www.xilinx.com System Generator for DSP User Guide
UG640 (v 12.2) July 23, 2010
Chapter 1: Hardware Design Using System Generator
Finite State Machines
This example shows how to create a finite state machine using the MCode block with
internal state variables. The state machine illustrated below detects the pattern 1011 in an
input stream of bits.
The M-function that is used by the MCode block contains a transition function, which
computes the next state based on the current state and the current input. Unlike example 3
though, the M-function in this example defines persistent state variables to store the state
of the finite state machine in the MCode block. The following M-code, which defines
function detect1011_w_state is contained in file detect1011_w_state.m:
function matched = detect1011_w_state(din)
% This is the detect1011 function with states for detecting a
% pattern of 1011.
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 state is a 2-bit register
persistent state, state = xl_state(seen_none, {xlUnsigned, 2, 0});
% the default value of matched is false
matched = false;
switch state
case seen_none
if din==1
state = seen_1;
else
state = seen_none;
end
case seen_1 % seen first 1
if din==1
state = seen_1;
else
Page view 61
1 2 ... 57 58 59 60 61 62 63 64 65 66 67 ... 409 410

Comments to this Manuals

No comments