Forum Discussion

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

Newbie question: driving leds

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

14 Replies

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

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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