- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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 copiado
3 Respostas
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
--- 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
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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?- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
--- 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

Responder
Opções do tópico
- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora