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

i have a problem about pio

Altera_Forum
Honored Contributor II
1,190 Views

i have a problem with pio. 

void main 

unsigned long M=0; 

unsigned long N=0; 

unsigned long fenzi=0; 

unsigned long fenmu=0; 

unsigned long em; 

 

M=6997*4*188; 

 

N=7314*204*8*10; 

 

fenzi=M; 

 

fenmu=N; 

 

 

while(N > 0) 

em = M % N;  

 

M = N; 

 

N = em; 

 

 

 

fenzi=fenzi/M; 

fenmu=fenmu/M; 

 

after i have computer out fenzi and fenmu,i want to trans them to a FPGA module. 

the module have three input port (clk,[31:0] fenzi,[31:0] femu). 

what should i do ? 

 

may i use 2 pio port? 

 

if so,what is the code?
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
343 Views

HI, snow 

are u from P.R.C? http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/biggrin.gif  

fenzi? fenmu? http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/biggrin.gif  

they are called "arenumerator" and "denominator" in English http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/tongue.gif  

i know what u mean. and i suggest u can read "Altera Embedded Peripherals Handbook" section 11 "PIO Core with Avalon Interface" and "Nios II Software Developer’s Handbook" section 4 "Developing Programs using the HAL" 

good luck 

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/cool.gif
0 Kudos
Altera_Forum
Honored Contributor II
343 Views

hi oceanx 

 

thank you for your help. 

 

yes, you are right,i am from P.R.C. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/biggrin.gif  

 

i have read the releated parts of the handbook,and i have try to use it as follows, 

 

# include "excalibur.h" 

# include "stdio.h" 

# define clk 57600 //73140# define v 7# define outrate 6840 

 

unsigned int Gcd(unsigned int M,unsigned int N) 

 

unsigned int Rem; 

 

while(N > 0) 

Rem = M % N;  

 

M = N; 

 

N = Rem; 

 

 

return M; 

 

 

 

 

 

void main(void) 

 

unsigned int wnfenzi,wnfenmu,gcd; 

unsigned int rnfenzi,rnfenmu,rnzheng; 

unsigned int fenzi,fenmu,faqam,qamfenzi,qamfenmu; 

unsigned int inqam; 

unsigned int bo,co; 

 

//&#35745;&#31639;&#20889;&#26102;&#38047;&#21442;&#25968; 

wnfenzi=outrate*v*188; 

wnfenmu=clk*204*8; 

gcd=Gcd(wnfenzi,wnfenmu); 

 

 

wnfenzi=wnfenzi/gcd; 

wnfenmu=wnfenmu/gcd; 

printf("wnfenzi=%d,wnfenmu=%d\n",wnfenzi,wnfenmu); 

 

 

 

na_wnfenzi_pio->np_piodirection=0xffffffff; 

na_wnfenmu_pio->np_piodirection=0xffffffff; 

 

na_wnfenzi_pio->np_piodata=wnfenzi; 

na_wnfenmu_pio->np_piodata=wnfenmu; 

 

 

 

 

//&#35745;&#31639;&#35835;&#20351;&#33021;&#21442;&#25968; 

 

rnfenzi=wnfenmu*47; 

rnfenmu=wnfenzi*2; 

 

if(rnfenzi>rnfenmu) 

rnzheng=rnfenzi/rnfenmu; 

rnfenzi=rnfenzi-rnfenmu*rnzheng; 

 

if(rnfenzi==0) 

rnfenmu=2; 

 

rnfenmu=rnfenmu-1; 

rnfenzi=rnzheng+rnfenzi; 

//&#36755;&#20986;&#20026;rnfenmu(factor),rnzheng(conl_1),rnfenzi(conl_2) 

printf("rnfenzi=%d,rnzheng=%d,rnfenmu=%d\n",rnfenzi,rnzheng,rnfenmu); 

 

na_rnfenmu_pio->np_piodirection=0xffffffff; 

na_rnzheng_pio->np_piodirection=0xffffffff; 

na_rnfenzi_pio->np_piodirection=0xffffffff; 

 

na_rnfenmu_pio->np_piodata=rnfenmu; 

na_rnzheng_pio->np_piodata=rnzheng; 

na_rnfenzi_pio->np_piodata=rnfenzi; 

 

 

 

//&#35745;&#31639;&#36870;&#36895;&#29575;&#21305;&#37197; 

 

faqam=outrate%1000; 

inqam=outrate/1000; 

 

if(faqam==0) 

fenzi=outrate; 

fenmu=clk; 

 

 

gcd=Gcd(faqam,1000);  

qamfenzi=faqam/gcd; 

qamfenmu=1000/gcd; 

 

fenzi=inqam*qamfenmu+qamfenzi; 

fenmu=clk*qamfenmu; 

 

printf("fenzi=%d,fenmu=%d\n",fenzi,fenmu); 

 

na_fenzi_pio->np_piodirection=0xffffffff; 

na_fenmu_pio->np_piodirection=0xffffffff; 

 

na_fenzi_pio->np_piodata=10; 

co=na_fenzi_pio->np_piodata; 

 

 

na_fenmu_pio->np_piodata=fenmu; 

bo=na_fenmu_pio->np_piodata; 

 

 

 

 

 

but when i use modelsim to check the result ,i do not understand the waves. 

i mean when the data are written to the pio&#39;s data register,will the pio&#39;s output be always the data? what should i do if i want to output them at a time ,after all the numbers be computed out?
0 Kudos
Altera_Forum
Honored Contributor II
343 Views

HI snow 

I suggest u can open the "altera_avalon_pio_regs.h" and "system.h" of NIOS2 project in the IDE and read it carefully. 

use these followed macro: 

IORD_ALTERA_AVALON_PIO_DATA(base) 

IOWR_ALTERA_AVALON_PIO_DATA(base, data) 

 

Reading the English Datasheet carefully before u program http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif
0 Kudos
Reply