Forum Discussion
Altera_Forum
Honored Contributor
15 years agoNIOS II C code tips?
hey everybody I'm trying to make a PWM using NIOSII and SOPC and i have reached the point where i need to wright the C code for my model but i can't find any documentation describing how to do it...
Altera_Forum
Honored Contributor
15 years ago10x alot this was very helpful here's my final code
--- Quote Start --- /* PWM Code */ # include <stdio.h># include "system.h"# include"altera_avalon_pio_regs.h" int alt_main() { int n; // PWM total period int a; // PWM working period int c=0; // internal counter while(1) { n=IORD(PIO_0_BASE,0);// pio_0 (total period ) a=IORD(PIO_1_BASE,0);// pio_1 (on period) if (n<a) { c=0; IOWR(PIO_2_BASE,0,0); } if (n>=a) { c++; if(c<a) { IOWR(PIO_2_BASE,0,1); } if(c>a && c<=n) { IOWR(PIO_2_BASE,0,0); } if(c>n) { c=0; } } } return 0; } --- Quote End ---