- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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: ThanksLink Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)) ;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page