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++

Newbie question: driving leds

Altera_Forum
Honored Contributor II
2,869 Views

Hello everybody! 

 

I'm an absolute newbie in Altera / NIOS. 

I have an NEEK with Cyclon III and touch panel LCD. 

But for the time being, I am studying the basics. 

 

I have been through the document "my first NIOS II software" tutorial. 

Downloaded and installed recently the NIOS 9.1 and Quartus 9.1, both with 

their latest service packs. I downloaded the proper application (that goes together 

with the tutorial). 

 

Basically the application works. I have added the proper code to blink the LED and 

it works. 

Now as there are 4 leds, I modified like this : 

(The only modification is count & 0x0F instead of count & 0x01). 

 

while(1) { 

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, count & 0x0F); 

delay = 0; 

while(delay < 2000000) { 

delay++; 

count++; 

 

I thought (naively) that if I give the 4 last bits to this macro, it would make a 

binary counter with the LEDS 1 to 4. However, it does nothing more than it used 

to, it seems that only the last bit is taken into account. If I simply use "count", without 

anding it with 0x01, it works the same. 

Am I missing something? Is there a configuration somewhere that enables or disables 

LEDS 2, 3 and 4? 

 

Thanks for any hint! 

 

Pascal
0 Kudos
14 Replies
Altera_Forum
Honored Contributor II
832 Views

Hi Pascal. Have you corrected the pinning? In the Example Designs there are fault Pin-Assignements for the LEDs. Try to correct them and try again. The Pins you can find in the reference_manual for the NEEK. 

 

Edit: I have looked that up you can find a running example under NIOS_Evaluation_Kit_v8.0\cycloneIII_3c25_niosII\examples\cycloneIII_3c25_start_my_first_fpga the Pins are: 

PIN_P13 

PIN_P12 <- this is wrong in "standard" it's PIN_T1 there 

PIN_N12 

PIN_N9 

 

Good Luck.
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

Hello Peet_2! 

 

Thanks for your reply. 

This brings more questions: 

1. How can I correct the pinning? (which file should I edit, how and with which edifor?) 

2. I have found a reference to the relevant pins in the reference manual page 2-14. 

Indeed, it says that it is pin P12. How do you know it should be pin T1? I don't see 

schematics… Are there errata sheets somewhere? 

3. Even if one of the pins is wrong, if I assign the leds using count & 0x0F, shouldn't 

I observe at least 3 working leds (those connected to P13, N12, N9?) 

 

 

Thanks, 

 

Pascal
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

Hi, I use Quartus for my designs, so I edit the Assignments and Pins from there. There is a tab Assignments in the Software, from which you can open the PinPlanner. It shouldn't be T1. In the documentation they say you have to use Pin12, but in the example projects, they have set PinT1, which seems wrong to me and schould be corrected. 

 

How do you use the Project? Haven't you got the NEEK Evaluation_Kit CD? There are all Documents and ExampleDesigns on it. You can find that on Alteras FTP. I opened the "Standard" Example from the Example Folder of the CD and just looked into PinPlanner to see if the LEDs are connected correct. There is also a little Hardware-Example on the CD, which lets the LEDs count in Hardware. The name is hardware_tutorials/my_first_hardware_tutorial.pdf perhaps try that on your neek first. 

 

(When you power up the neek there is also one of the LEDs blinking. Are you sure you have got your custom code running correctly? Normally you have to built a NIOS-Design, connect the relevant Pins, do synthesis and load the Design into the FPGA. Before that you can't run your custom c-code on the NIOS. It's a silly question, but you are sure that runs ok?) 

 

Edit: the link is ftp://ftp.altera.com/outgoing/download/support/ip/processors/nios2/cycloneiii_3c25_niosii-v8.0.0.exe
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

Hello again! 

 

Ok, I found the design files. Sorry. 

 

Yes, that's also what I did, I opened the cycloneIII_3c25_NiosII_standard file. 

 

Beside this I'm sure the program works. The original program just says 

"hello world", and the pdf tutorial sows the code to be added to blink one led. 

I added the code, recompiled and could verify that the led blinks. 

Now, replacing count & 0x01 by count & 0x0F and recompiling has no effect. 

 

What I did is exactly what is explained in the tutorial for NIOS. So there is no 

FPGA design. The FPGA design file (which is ready to use for this tutorial) is loaded 

and then the program is compiled and run. 

 

Now I checked the pin planner. Indeed, the led[1] is on T1. So I changed it to P12. 

Now something I don't understand: 

 

Why are there 2 nodes on the same pin ? I mean top_led and top_out_port_from_the_led_pio. 

 

Thans, 

 

Pascal 

 

PS: Now it's late here, I will continue tomorrow.
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

The design uses a verilog file for the system design, in this they first defined the Input/Output Pins. (for LED here it is: output [ 1: 0] top_led; )This Pins are connected to wires. These are also named (for the LED wire here wire [ 1: 0] top_led; ) and this wire connects the OutputPin of the NIOS Core. The outputport from the NIOS is then connected to the busses or components in the NIOS, but that isn't in the verilog toplevelfile anymore. (here .out_port_from_the_led_pio (top_led), where out_port_from_the_led_pio is the portname of the NIOS Side and connects to top_led) 

 

Your code should work (with 0x0F) I have tried it and it works as you expected it. I have attached the compressed project to this thread. The C-Code is in the zip as txt-File. 

 

Perhaps you look more into creating a NIOS System. I have generated a NIOS-Core very simple for this demo, to test. It has just a CPU, Memory and the PIO. The design I have created as a blockshematic. In my opinion for first start this is a bit better to read, also it work like the verilog file or vhdl. (the names of the project are messed up, because I stripped an old project for this, so just ignore the filenames) 

 

(some more tipps for start: read the manuals, they are quite good. Never add spaces to pathes when working with altera tools. when you update your nios core sometimes you have to regenerate your bsp to get the nios code working again. make backups of working code before further editing. Some path are absolute in the designs, so don't move project folders. while in the SOPC Builder, you can deactivate modules by clicking the green arrows on the left. Sometimes this saves a lot of time, because the parameters does not have to put in later again, you can just reactivate.) 

 

Good Luck with the NEEK. ;-)
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

Hello! 

 

Thanks for your help! That's what I call technical support! 

I will probably have some more questions.. 

 

Pascal
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

Hello! 

 

Here we go for another question. I am writing a tutorial for a design from scratch, 

which is a good way to learn myself. 

 

What I did: 

- Create an empty project; 

- Configured the right parameters (for the device of the NEEK = EP3C25324C8). 

- Opened the SOPC builder, left the default verilog checked, added a NIOS processor 

(just in case, I started with the smallest model). 

- Added some internal memory and set the memory2_0.s1 at a proper value to 

eliminate errors. The generation went fine, without errors or warnings. 

 

(No PIO yet, I just want to check if the processor can run). 

 

- As the top object (forgive the improper terms if any) was the default "MyFirstFPGA" 

and the SOPC design was called niostest, I checked niostest_inst.v, and wrote 

MyFirstFPGA.v accordingly. 

- Now, I am stuck at the last step. I wanted to use Pin Planner to add a clock and 

a reset. I could first add the clock, but I cannot change the direction to input. 

So that will be the only accurate question for today: how do I change the direction 

of a pin in Pin Planner? I tried right-click -> Pin Properties, right-click->node properties,  

no way to produce any effect. 

 

Beside this, if there is something wrong in what I did, please tell me! 

 

Thanks for your help! 

 

Pascal
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

I cannot follow your description, the last paragraph with the defining of the top level is a bit confusing. 

 

I think what you mean is how to define the clock as input signal. That you must do in your verilog file, where you define the pins. The direction then appears in the pinplanner after synthesis I think. 

 

(Can't follow your steps, as I am not sitting before Quartus right now.)
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

Hello Peet! 

 

Here is an accurate version of what I did. 

 

http://passworld.co.jp/forummsp430/viewtopic.php?f=18&t=166&p=392#p392 

 

Now you were telling me I should define the clock as an input in the vhdl file, but 

which one? 

 

Thanks! 

 

Pascal
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

That Forum requires registration. Attache the file here please, then I might look into it.

0 Kudos
Altera_Forum
Honored Contributor II
832 Views

Hello! 

 

Thanks for your reply. The registration problem is fixed. 

There is a zip file at the end of the document. I cannot attach it here, it's too big 

probably because there are compilation results. But I prefer not removing anything. 

So the full description of what I did is here (http://passworld.co.jp/forummsp430/viewtopic.php?f=18&t=166&p=392#p392), and the pin assignment is missing. 

 

Thanks, 

 

Pascal
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

Hi, I will take a short look into that code. In the Device settings, are you sure you got the device right? On my neek there is a EP3C25F324C6 and you took the C8. (if you change the device the assignments are lost, so copy them from assignment editor before you do so. After changing you can paste them back in again) Then into SOPC: First I would select 4Bit for the PIO, as you don't have 8 LEDs on the neek. In the code defined pins, but not connected shows up white in pinplanner. Most times something is wrong with names or datawith when you have assigned the FPGA-Pins and there are afterwards white ones over. Rest of the NIOS looks fine, but you will need more ram to run your programs, so take 40Kb of onchip_memory. Perhaps you will have to optimze the addresses then. Try "System / Auto-Assign" for that, now I generated that system and back to Quartus. 

 

For the system I can't help you very much, as my verilog is really bad. I would have written 

 

// Define the module inputs and outputs module MyFirstFPGA(CLOCK, RESET, LEDS); input CLOCK; input RESET; output LEDS; // Instantiate the NIOSII processor niostest niostest_inst ( .clk (CLOCK), .out_port_from_the_LEDs (LEDS), .reset_n (RESET) ); endmodule 

 

The Instiantiation of niostest is described in niostest_inst.v I would just take that description for the initialisation. (Perhaps that code is different in your case because it was here generated with Quartus 9.1.) So then I reanamed RESET and now synthesis is running. I now load that into the neek, opencore stayes connected. And up to NIOS Eclipse >> new Application and BSP from Template >> HelloWorld. 

 

Pasted: 

#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(LEDS_BASE, count & 0x0F); delay = 0; while(delay < 2000000) { delay++; } count++; } return 0; }  

And it works nicely, without problems on the first try. :confused: So no problem.
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

Ok, so now I see what you are planning to do. That Tutorial, I would edit some parts. At 2.1.3 and 2.1.5 I would recommend, to just look what is printed on the Chip and select exactly that device. So just select Cyclone III and find the right device in the list. 

 

3.1 others then in your screenshot the F type cpu was selected in the project I downloaded. 

 

3.2 I would advise to directly take more ram, because the LED-Code already uses up 18Kb I think. 

 

3.3 Add 4Bit PIO 

 

4. lokk into niostest_inst.v instead of niostest.v I would also recommend to keep the _n and take it over to the toplevel file, so that you later on can see, that it is active low pin. 

 

You have not described how to assign the pins. You can import the Pin-Settings easily from a csv Altera provides. I have attached it to the thread. Try Import-Pin assignments in quartus (danger, that one is with the T1 LED Pin) 

 

You will have to keep the openCore connection window open too work with the nios CPU. Perhaps you add that at the bottom of your Tutorial. The rest is really fine written, with nice Screenshots. 

 

Wanna see more of that tutorials. Perhaps do some things with uart in the c-code, add some buttons or do some other things where you can interact with the board. But also be warned, the vga and lcd are not so easy to access on the neek, because of the MAX chip. So perhaps don't try that as second project. 

 

Have fun good luck. That's it from me. no more time now. CU
0 Kudos
Altera_Forum
Honored Contributor II
832 Views

Hello! 

 

Thanks a lot! I made the necessary modifications and could make it run. 

 

Pascal 

 

PS: for those who might be interested, there is a complete report here (http://passworld.co.jp/forummsp430/viewforum.php?f=18). 

Starting from scratch, you should be able to run a led blinking application. 

Please report any error / inaccuracy.
0 Kudos
Reply