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 agoIn my opinion, pwm in software is a bad idea (especially if you work with FPGA) : because of interruptions, CPU instructions, access.....
For SOPC, you need a PIO. For software, You need an counter (simple) or a timer (a little difficult) and some comparators.
int i =0;
while(1)
{
i++;
if (i == periode)
{
IO_WRITE_...(0); // write '0' to your PIO
i = 0;
}
elseif (i >= pwm)
{
IO_WRITE_...(1); // write '1' to your PIO
}
//...
}