Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12420 Discussions

Help with state machines in eclipse (NIOS II)

Altera_Forum
Honored Contributor II
839 Views

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 II
123 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