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

Nios II PIO Stimulus input signals for simulation with Modelsim/questasim

Jacob11
New Contributor II
312 Views

Hi guys,

 

It is my first post, so apologies if I leave out something important.

 

I have created a very simple Nios II environment with 2 buttons button as a PIO input width 2, and leds as a PIO output width 2.

 

I created the eclipse project, which will toggle the LED on and off. The led outputs simulate just fine in Modelsim.  But the Buttons always just show X.

model1.PNG

 

what I really want to do, is provide input stimulus signals like we would do for an HDL design. So I can have the LED toggle when the button signal goes high. I would flip the button on and off every 100 clock cycles and the LED would toggle with it. This is what I want to simulate, but in Nios instead of VHDL or verilog. In a VHDL simulation this is pretty trivial to accomplish.

 

I have been working on this all day and I cannot figure out how to do it.

 

I did try to just printf the value of the button, but it prints 0:

 

btn_in = IORD_ALTERA_AVALON_PIO_DATA(BUTTON_BASE);
printf("Button First Read: %d \n", btn_in);

 

It always reads 0 even though I set the PIO hardwire to 0x3 when I created it in Platform Designer.

 

What is the trick to this??

 

Code:

#include <stdio.h>
#include "altera_avalon_pio_regs.h"
#include "system.h"

 

int main()
{
int led_pattern = 0x01;
int btn_in;

btn_in = IORD_ALTERA_AVALON_PIO_DATA(BUTTON_BASE);
printf("Button First Read: %d \n", btn_in);
printf("Blinking LEDs \n");
while (1)
{
led_pattern = ~led_pattern; //invert led_pattern
IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE,led_pattern); //macro which writes led_pattern to the LED_BASE memory address

}
return 0;

}

 

Nios:

plat1.PNG

 

 

what I want is something like this:

while(1) {

btn_in = IORD_ALTERA_AVALON_PIO_DATA(BUTTON_BASE);

IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, btn_in );

}

 

for that to work I need to be able to stimulate the buttons so the data read gives a value. I feel like this should be simple, but I am missing something.

 

Any ideas on that??

 

Thank you to anyone who takes the time to respond. Have a nice day.

 

0 Kudos
1 Solution
Jacob11
New Contributor II
267 Views

Hello Sheng. Thank you for the response.

 

I solved it. The code is fine, but providing stimulus signals needs to be done in modelsim with the FORCE command.

 

http://www.pldworld.com/_hdl/2/_ref/se_html/manual_html/c_vcmds87.html

 

I was able to create a macro file(.do) which switches this stimulus repeatedly during the simulation.

 

Thank you,

Jacob

View solution in original post

3 Replies
ShengN_Intel
Employee
282 Views

Hi,


Probably something is missing in the while loop.

while (1)

{

btn_in = ~IORD_ALTERA_AVALON_PIO_DATA(BUTTON_BASE);

led_pattern = ~led_pattern; //invert led_pattern

btn_in &= led_pattern;

IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE,btn_in); //macro which writes led_pattern to the LED_BASE memory address

}


Best Regards,

Sheng

p/s: If any answer from community or Intel support are helpful, please feel free to mark as solution and give Kudos.


Jacob11
New Contributor II
268 Views

Hello Sheng. Thank you for the response.

 

I solved it. The code is fine, but providing stimulus signals needs to be done in modelsim with the FORCE command.

 

http://www.pldworld.com/_hdl/2/_ref/se_html/manual_html/c_vcmds87.html

 

I was able to create a macro file(.do) which switches this stimulus repeatedly during the simulation.

 

Thank you,

Jacob

ShengN_Intel
Employee
251 Views

Hi Jacob,


Also can use forever, always or repeat statements in testbench just in case you don't want to use FORCE command.

Btw glad to hear that your issue has been resolved. I'll now transition this thread to community support. If you have a new question, feel free to open a new thread to get the support from Intel experts. Thank you.


Best Regards,

Sheng


Reply