Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

To control LEDs with DE0_Nano

Altera_Forum
Honored Contributor II
2,428 Views

Hi, 

 

 

 

I wants to control leds on DE0_Nano board using Nios II Eclipse, for this anybody can provide code part?Because im very new to this , sory for lack of knowledge. 

 

 

 

Thanks, 

Alex.
0 Kudos
11 Replies
Altera_Forum
Honored Contributor II
587 Views

Create a PIO in your SOPC Builder / QSys project, and in the top level file in Quartus, connect this PIO port to the FPGA pins connected to the leds. 

Then in your Nios II project you will have some macros to control the PIO port, defined in altera_avalon_pio_regs.h.
0 Kudos
Altera_Forum
Honored Contributor II
587 Views

Thanks for reply, 

 

But i got the error like 

 

PIO_LED_BASE undeclared(first use in this), altera_avalon_pio_regs.h:No such file or directory 

make :***[obj/defaults/hello_world.0]Error 

 

 

Any ideas? 

 

 

 

 

Alex.
0 Kudos
Altera_Forum
Honored Contributor II
587 Views

Do you have a PIO in your SOPC/QSys system? Then the altera_avalon_pio_regs.h include file should automatically be included in the BSP. 

What name did you give your PIO? The name to use is your PIO name, in capital letters, with a _BASE suffix. For example if you called it my_pio, you must use MY_PIO_BASE.
0 Kudos
Altera_Forum
Honored Contributor II
587 Views

Thanks for prompt response, my PIO name is mismatched,now that problem solved, but when i run the program ,the output is  

 

[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] like this coming continously. 

Actually i wants to control leds on DE0_Nano board. 

Some times its showed errors also 

make:***[../Helloworld_bsp/-recurs-make-lib 

make[1]:*** [public.mk] Error1 

 

Thanks, 

Alex. 

 

 

0 Kudos
Altera_Forum
Honored Contributor II
587 Views

What does your software project look like? Can we have a look at your main() function?

0 Kudos
Altera_Forum
Honored Contributor II
587 Views

Iam using Nios II 11.1 version, 

 

My Nios Project is  

 

[#include <stdio.h># include"ststem.h># include "altera_avalon_pio_regs.h" 

int main() 

printf("Hello form Nios II); 

int count=0; 

int delay; 

while(1) 

IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, count & 0x01); 

delay=0; 

while(delay< 2000000) 

delay++; 

count++; 

return 0; 

}] 

 

 

This is the my program, whre is the mistake? 

 

Thanks, 

Alex.
0 Kudos
Altera_Forum
Honored Contributor II
587 Views

There are some mistakes in your code, I assume they come from a copy/paste error. The include line should be#include <system.h>and you didn't close the string in the printf line. You should also end the line with a \n to be sure it is written to the UART. 

Are you sure you upload the correct .sof image to the FPGA before you upload and run the software? 

And here is a tip: when you show some code, enclose it between [code] and [/code] tags, and you won't loose formatting and indentation.
0 Kudos
Altera_Forum
Honored Contributor II
587 Views

Sory for lack of my knowledge, i will tel what i did 

 

1.Created a empty project in Quartus 11.1, under ubuntu. 

2.Generated the system(SOPC builder)like sdram, altpll_sys,cpu,jtag_uart,timer_0, PIO_LED. 

3.Created block and symatic diagram(In symatic diagram inputs is clock and reset remaing all those things are outputs) 

4Eclipse--->program (previously which i posted in# 7) 

 

 

Now my problem is iam unable to run the Nios II program it showing error is elf file download failed, but .sof file is i downloaded correctly only, where is the mistake? 

Problem with my .sof file? Kindly any help ? 

 

 

Thanks, 

Alex.
0 Kudos
Altera_Forum
Honored Contributor II
587 Views

Did you start the project from scratch? It can be a bit difficult to get some parameters right, such as the sdram. It is easier to start with a reference project from the kit DVD and add your own components from there.

0 Kudos
Altera_Forum
Honored Contributor II
587 Views

Thanks for ur help Sir, 

 

I successfully running the uclinux on DE0_Nano board, after that i wants to add the feature of leds.I mean after running uclinux the leds should glow. 

For this nios2 Eclipse is enough or i need to get any other software? 

 

Kindly any help? 

 

 

 

 

Thanks, 

Alex.
0 Kudos
Altera_Forum
Honored Contributor II
587 Views

I have never used uclinux, but if you start from a working example all you should need is to add the PIO to the project to connect to the LEDS, and the PIO macros to control them from the software side.

0 Kudos
Reply