Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
752 Views

Help with state machines in eclipse (NIOS II)

How can i initalise the states and cause this state machine of 3 states to work effectively. 

My code if found below: 

 

# include <stdio.h># include <io.h># include <system.h># include <alt_types.h># include "altera_avalon_pio_regs.h" 

 

 

int main() 

alt_u32 key_in, signal_raknarvarde, state; 

 

 

# define Scan_keys_state 0x01 

# define write_to_leds_state 0x02 

# define no_keys_state 0x03 

// Initiering av variabler och utsignaler till hårdvaran 

 

 

//int state = Scan_keys_state; 

//int state = write_to_leds_state; 

//int state = no_keys_state; 

// loop for ever 

while(1) 

 

 

switch (state) { 

case Scan_keys_state: 

// if key_in, state = write_to_leds; 

state = write_to_leds_state; 

break; 

 

 

case write_to_leds_state: 

state = no_keys_state; 

 

 

break; 

case no_keys_state: 

// Kolla att ingen knapp är nertryckt, 

//denna function kan göra att //wait(time); inte behövs 

state = Scan_keys_state; 

break; 

return 0; 

--------------------------- 

Thanks for the help in advance
0 Kudos
1 Reply
Altera_Forum
Honored Contributor I
36 Views

You'll have to define a bit better "work effectively". A problem I see in your code though is that you don't give an initial value to the state variable. You should uncomment one of the three lines that do that.

Reply