10x 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 ---