Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Run and debug nios project

Hello,

I am running a c file on niosii to check if the LEDs are working or not using buttons.

This is my C file:

#include <stdio.h> // for uart# include <unistd.h> // for uart read(), open()# include <stddef.h> // for uart# include <fcntl.h> // for uart# include "altera_avalon_pio_regs.h" // pio access# include "system.h"

int main(void)

{

alt_u8 button_pio_value = 0;

alt_u32 led_counter = 0;

alt_u8 led_counter2 = 0;

alt_u8 led_on = 0;

printf("hello world\n");

while(1)

{

button_pio_value = iord_altera_avalon_pio_data(button_pio_base);

led_counter++;

if (led_counter == 500000)

{

led_counter = 0;

led_counter2++;

switch (button_pio_value)

{

case 0: led_on = led_counter2 % 16; break;

case 1: led_on = (led_counter2 % 16) + 16; printf("button 1 pressed\n"); break;

case 2: led_on = (led_counter2 % 16) + 32; printf("button 2 pressed\n"); break;

case 4: led_on = (led_counter2 % 16) + 64; printf("button 3 pressed\n"); break;

case 8: led_on = (led_counter2 % 16) + 128; printf("button 4 pressed\n"); break;

default: led_on = led_counter2 % 16; break;

}

iowr_altera_avalon_pio_data(led_pio_base, led_on);

} // if

} // while

return 0;

}

problems:

1) I am supposed to use the buttons after running the project and see the LEDs blinking, but they didnt and i see this message in the console

nios2-terminal: connected to hardware target using jtag uart on cable

nios2-terminal: "usb-blaster [usb-0]", device 1, instance 0

nios2-terminal: (use the ide stop button or ctrl-c to terminate)

2) I am trying to debug and i put two breakpoints one in front of the printf and another one in front of the switch. The problem is that i cannot go to each breakpoint to see what is happening. I see only two right mark beside the bullets and the program is still running.

I think: there is somthing wrong with the loops but this program is already tested by altera and i am just doing the steps to build and test.

please if anyone have an idea, please help,

thanks

13 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You can't use 1us period! The processor can't operate with so a high rate of interrupt. At fclk=50MHz that would mean only 50 cycles!!!

    You must modify timer in sopc builder, regenerate the system and recompile the fpga design.

    You should use a period 100us or greater. Usually a 1ms period is pretty enough for most applications.

    Cris
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Cris: this is the second time to solve my problems...

    thanks for your help, and be ready for tomorrow questions :D

    Also, i would like to thank JacoL for your participation and help