Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

Multichannel (32) PWM not generating correct frequency

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!

 

MultiChannelPWM.PNG

0 Kudos
Message 1 of 5
(5,976 Views)

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.

 

MultiChannelPWM.PNG

0 Kudos
Message 2 of 5
(5,965 Views)

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

Message 3 of 5
(5,943 Views)

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.

0 Kudos
Message 4 of 5
(5,940 Views)
That example uses an R series card which takes 1 tick (25ns) to set the digital outputs. The 9403 is much slower and takes 7-8us to set its digital outputs. It will be very difficult to do 32 independent PWMs with such a slow module. I recommend the 9401 instead
Stephen B
0 Kudos
Message 5 of 5
(5,882 Views)