Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

implementing state machines using matlab function block in simulink

Status
Not open for further replies.

sandy3129

Member level 3
Member level 3
Joined
Nov 7, 2014
Messages
56
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
445
hello guys I'm trying to understand how to implement state machines using matlab function in simulink, can anyone let me know what the meaning of this statement
" persistent state , state = x1_state(start, {x1unsigned, 2,0});" in the following code????
Thanks in advance.

Code:
function matched = detect_1101(d_in)
start= 0;
found1=1;
found11=2;
found110=3;
   persistent state , state = x1_state(start, {x1unsigned, 2,0});
  matched = 0;
  
  
  switch state 
      
      case start
          if d_in ==1
              state = found1;
          else
              state =start;
          end
          
      case found1
          if d_in ==1
              state = found11 ;
          else
              state =start;
          end    
      case found11
          if d_in ==0
              state = found110;
          else
              state =found11;
          end
          
       case found110
          if d_in ==1
              state = found1;
              matched = 1;
          else
              state = start;
          end    
      otherwise
          state = start;
  end
  end
 

I hope you are trying to use system generator M-code block. Check this link

**broken link removed**

It says "Persistent variables are local to the function in which they are defined". However did you write this yourself or it was generated?. the declaration looks like a data type declaration for variable state. Moreover this unknown variable could have been declared in another Matlab .m file and can be used all throughout the system generator design.

There are predefined M-code functions given by Xilinx for M-code block which you can customize yourself. If that is your intention, try this way

Code:
function [c] = test1(a, b)

switch a
case 0
c = a + b;
case 1
c = a – b;
end
 
i dint write this it was generated only, just tried to understand it, so the word "persistent" is used for declaring only local variables, k got it.

"
There are predefined M-code functions given by Xilinx for M-code block which you can customize yourself.
,Sir where can i find those m code functions!!!!?

My intention is to write the state machine in only simulink, that i can do it either using state chart or matlab function block in simulink, my "state chart" is not synthesizing through fpga in loop process. so im trying to use state machines through matlab functional blocks.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top