Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
11 years ago

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

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.