Forum Discussion

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

Problem with integrating Qsys system in Quartus with created Qsys PWM module

I'm busy with a projects for a month now and I now need to create a PWM component to add it to my main system. After some googling I found a design example with a PWM (pulse-width modulator) to demonstrate the steps how to create a component and instantiate it in a system. It's is from the quartus handbook, section ii: building systels with sopc builder (2005). (https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0cdiqfjaa&url=http%3a%2f%2fwww.ee.nmt.edu%2f~erives%2f554_10%2faltera_pwm.pdf&ei=yebbuaglfy-grafq_idwdw&usg=afqjcneyydpyxn3pogqlfa5ztyteqvs6pq&sig2=nlsqp5dpuivtkjpfjapupa&bvm=bv.44697112,d.bmk)

Because it's a bit outdated and uses SOPC I followed the tutorial "Making Qsys Components" to create the PWM module. I integrated this in a simpel system with a NIOS II CPU, On-chip RAM and the clock which should be fine I think. I now have to create the top-level file and create the right pin-mappings. I'm using the Altera DE2-115 Board and I just want to use the a green led as the output for the PWM. So the speed can be controlled from the software part by writing the registers. Later on, I can change this to an external pin to control a dc fan.

I hope somebody can help me further because I'm stuck.

My projects files can be found h (https://www.dropbox.com/sh/f8paupnrprnciqy/cstvdoljwy)ere (https://www.dropbox.com/sh/f8paupnrprnciqy/cstvdoljwy)

5 Replies

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

    If possible, it is easier to start with one of the example projects from the kit and add your custom component to it. Then you don't have to redo the whole mapping, just modify the QSys instance in the top level file by adding your PWM output, and connect it to one of the LEDs (in the example project the LEDs are most probably connected to a PIO).

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

    I have added an extra PIO for the green led and my top levels file is as follows:

    module PWM_Module (CLOCK_50, KEY, LEDG[0]);

    input CLOCK_50;

    input [0:0] KEY;

    output [0:0] LEDG;

    embedded_system U0

    ( .clk_clk(CLOCK_50),

    .reset_reset_n(KEY[0]),

    .pwm_out_export(LEDG), // pwm_out.export

    );

    endmodule

    I have imported the DE2_115.qsf file and the pin mappings should be fine. I could compile and program the hardware system to the board.

    Now I have created the NIOS II project in Eclipse but can't find a way to get it working. In the tutorial using SOPC the following step is mentioned:

    The SW Files tab lets you associate software files with the component, and specify their usage. This component example design provides both a header file that defines the registers and driver software for the Nios II processor

    This tab wasn't available in Qsys, I tried to manually add these files to the created bsp project without succes.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I don't think this tab is here any more, but you don't need to generate software files from the component editor.

    In your BSP you will find a system.h file. This should contain some defines with the base address of your component. For example if your component is called pwm, you will find a PWM_BASE constant.

    Then from your code, include those two files and use the IORD / IOWR macros:
    #include <system.h>
    # include <io.h>
    // read a register
    IORD(PWM_BASE,reg_num);
    // write a register
    IOWR(PWM_BASE,reg_num, value);
    
    reg_num is the register number, i.e. the value your component will see on the address vector when it is accessed.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for your feedback, I think I'm starting to understand it now, I'll try this tomorrow when I have the DE2-115 board available.

    I'm wondering how I can make use of the header (.h) and source file of altera_avalon_pwm_routines to use the following functions for a cleaner code:

    altera_avalon_pwm_init();

    altera_avalon_pwm_enable();

    altera_avalon_pwm_disable();

    altera_avalon_pwm_change_duty_cycle();

    I now have placed the header file under HAL/inc and the c file under HAL/src, in the main I included the header file:

    # include "altera_avalon_pwm_routines.h"

    But the header files includes "altera_avalon_pwm_regs.h" so I place it at the same place?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yes you put both header files in the HAL/inc folder.

    But first I would suggest to put all your .h and .c files with the application rather than the component. It is easier to debug, as you don't have to recompile the BSP each time you make a change. Once you have working functions, you can try and put the .h files in HAL/inc and the .c files in HAL/src. You will then need to make a _sw.tcl file to declare all your source files, so that the BSP generator knows what files to pick up.