- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm targeting a DE0-Nano development board, and I've created a NIOS ii/e embedded processor. I want to blink a LED, using the following C code from 'my first nios ii software tutorial':
# include <stdio.h># include "system.h"# include "altera_avalon_pio_regs.h" int main() { int count = 0; int delay; while(1) { IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, count & 0x01); delay = 0; while(delay < 2000000) { delay++; } count++; } return 0; } When I debug, I can step through and see the LED light, the value 'count' increment, but there is no 'delay' - it skips the 'while(delay...)' statement. I do not understand - can somebody help?Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- I do not understand - can somebody help? --- Quote End --- The compiler is doing you a favor, and eliminating the code, since it appears to do nothing (but waste its time). Try volatile int delay; Cheers, Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dave,
Works! thanks- but now I wonder why 'delay' is not declared in the Altera tutorial as volatile? Is there a better way to do this - a timer implemented in the NIOS processor?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- but now I wonder why 'delay' is not declared in the Altera tutorial as volatile? --- Quote End --- Possibly because the original author was using a different version of gcc, or had optimization turned off ... or left it out as a lesson to the user :) --- Quote Start --- Is there a better way to do this - a timer implemented in the NIOS processor? --- Quote End --- That is one way. Another way is to create an Avalon-MM slave hardware component to generate pulses (a pulse width modulator) and use that to control the LED. Ultimately it depends what you are trying to learn. Finding all the different ways to blink LEDs will keep you busy for hours :) Cheers, Dave

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