Altera_Forum
Honored Contributor
14 years agoproblem of adding custom component in SOPC
Hi~~
My SOPC setting have processor,PIO,SDRAM,FLASH..so on. I want to add a custom component which is a simple counter IP. (behavior: when I push the switch ,then the counter will plus one ) The following code is the counter IP. --- Quote Start --- output reg [ 7: 0] readdata; input clk; input [ 7: 0] in_port; reg [7:0] out; always @ ( clk or in_port) begin if ( in_port[7] == 0 ) readdata = 0; else if ( in_port[6] == 1 ) readdata = out + 8'b00000001; else readdata = out; out = readdata; end --- Quote End --- the IP setting is the following --- Quote Start --- counter count ( .readdata(readdata), // avalon_slave.readdata .clk (clk), // clock.clk .in_port (in_port) // conduit_end.export ); --- Quote End --- And the follwing code is C langauge in NIOS IDE --- Quote Start --- while(1){ count =IORD_ALTERA_AVALON_PIO_DATA(COUNTER_BASE); printf("count %d \n",count); } --- Quote End --- The above counter IP that I simulation with modelsim , and I can get the correct result. But when I download the .sof file to the DE0 board, I can't get the same result which simulation with modelsim. I use a lot of time to resolve this bug. Then I find the reg(the red color in first quote) that can't hole the last value. Therefore, I can't get the correct result. Normally when I declare the veriable type is reg, and this variable will keep the last value. But I run in NIOS, I don't have this feature. Counld you give me some suggestion Thank you very much. http://www.alteraforum.com/forum//proweb/misc/progress.gif