- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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; //计算写时钟参数 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; //计算读使能参数 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; } //输出为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; //计算逆速率匹配 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's data register,will the pio'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?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page