Nios II PIO Stimulus input signals for simulation with Modelsim/questasim
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.
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:
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.
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