Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21602 Discussions

Help with Nios ii

Altera_Forum
Honored Contributor II
1,317 Views

Hi 

I'm a new user of the Nios II IDE. I'm currently trying to modify the SD card music player that came as one of the demos for my DE board. I'm trying to pause the system with the use of the sleep function. i'm using the follow code fragment. 

 

if (button_pressed) 

count++; /// originally set to zero 

 

while (count%2==1) ////every odd pressed of the button will pause while every even / /////pressed will resume the execution of the code. 

usleep(100); 

continue; //// should recheck the condition of the while loop 

 

However when the program enters the loop it stays there forever. :eek:  

Can some offer some help or suggestion?:confused:  

Thanks
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
598 Views

First button pressing makes count=1. So system will remain in the while-loop because you never check if button is pressed, is buttonpressed changed on interrupt?. Assuming your button pio is called BUTTON and high level idle state: 

 

if (!IORD(BUTTON,0)) //check button pressing { //Wait for button release while (!IORD(BUTTON,0)) ; //Wait for button pressing again while (IORD(BUTTON,0)) ; //Wait for button release again while (!IORD(BUTTON,0)) ; }
0 Kudos
Altera_Forum
Honored Contributor II
598 Views

Does the DE board have something on it to take out the bounce in the key contact? If not you'll also want to add a little code to do that or you may see random operation with it actually getting many pulses on both key down and key up.

0 Kudos
Reply