01-31-2014 02:06 PM
Hi,
I need to control 32 PWM channels individually on a NI 9403 module plugged into a cRIO 9075. I am using the code example listed here - Multi Channel PWM. In my code the Host to calculates the Ton and Toff time in ticks using the frequency and duty cycle and send values to the FPGA target via a FIFO. Currently
As of now I using only 8 channels, but I am unable to get the exact frequency (as entered on the user interface) of my output signal, duty cycle is spot on. It seems like there is a latency in the loop which is toggling the out of the DAQ, but I am unable to determine what this is. I know that there is no problem with the calculation of Ton and Toff using the frequency and duty cycle.
An image of my code is pasted below. I am sure there might be a better way of doing this, or somehow getting rid of the latency that is causing the frequency to not be accurate. Open to any suggestions.
Thanks!
01-31-2014 03:51 PM
The following code seems to have reduced some latency. I am now seeing 907Hz frequency instead of 1KHz. Still not there, it's probably due to the memory access block in the for loop.
02-03-2014 02:26 PM
It looks like you're writting to your PWM channels in the second while loop there. You could move your calculations to your first loop, that would potentially decrease your latency. Your PWM write loop would then only need to pull the data out of memory and write it to the channels. You may want to see if making that change gets rid of the latency you are seeing.
Shane C
02-03-2014 02:47 PM
Thanks, I haven't tried your solution yet. But I was able to increase the loop count to 80 (ticks) and achieve the desired frequency. This will obviously run into a limit with higher frequencies. I will try your suggestion.
02-10-2014 12:45 AM