IF-RIO

cancel
Showing results for 
Search instead for 
Did you mean: 

sbRIO9637 accurate timing problem

Dear colleagues, recently I started building a system that consists of sinewave generation, DSP synchronous demodulation and PID loop. At the very beginning I tried to make a simple program for 20kHz sinewave generation on sbRIO9637. I encountered this problem:

My board clock frequency is 40MHz. I need to generate the 20kHz sinewave and in the board datasheet I found that the attainable output DAC sampling rate should be 330 kSa/s. So I decided to generate 16-pts sinewave using direct digital synthesis. To be able to accurately generate this sinewave, I built in 125 cycle time delay. (40MHz/125cycles=320kHz=16x20kHz). I built-in also one simple control digital input to check the timing of the loop. 

However, when I compiled this file, I found that it was running at 2x157.5kHz=315kHz instead of 320kHz. The sinewave frequency was then proportionally lower, too. It looked like if the counter was counting 127 clock cycles instead of 125.

 

When I left out the time delay module, It ran at 2x175.4kHz=350.8kHz. So there seems to be still some margin for accurate timing. 

 

First I thought that this problem was caused by insufficient timing reserve for DAC output, so I left out the whole sinewave generation (including the DAC output method). However, the frequency with the delay function was again 157.5kHz instead of planned 160kHz.

 

Currently I don't know what goes wrong (maybe the problem of the fundamental idea)?

 

0 Kudos
Message 1 of 8
(8,447 Views)

Are you not able to use the generate sine wave vi's?  Sounds like a long round about way to create a sign wave.

 

-Bear

Regards,

Ben Johnson
ʕง•ᴥ•ʔง
0 Kudos
Message 2 of 8
(8,424 Views)

Dear Bear,

sure, I could use generate sinewave.vi but this did not come to my mind when I started. I found that i had to decrease expected wait time by two ticks for some unknown reason. The sinewave has now the expected frequency. Is it a bug in LV?

0 Kudos
Message 3 of 8
(8,422 Views)

Interesting, I'd like to see what you did.  Do you mean you changed the original code you were running that wasn't working before the generate sine.vi or did you edit that vi to get it working?

 

Posting code always helps too!

 

 

-Ben

Regards,

Ben Johnson
ʕง•ᴥ•ʔง
0 Kudos
Message 4 of 8
(8,413 Views)

I didn't use the generate_sine.vi

I used my own function for sinewave generation. Fortunately, I have made it working. I had to decrease the number of ticks (input to wait function) by two ticks. Now, it generates the 20.00kHz sinewave, as expected.

So I am posting the snapshot of current piece of the code.

 

Just a quick calculation: Sinetable has pts=16 points, fclk=40 000 kHz, desired f0=20kHz. So number of wait ticks needed for keeping the accurate frequency should be:

ticks=(fclk/f0)/pts=125. However, I realized that I needed 123 points, instead.

 

 

 

 

 

0 Kudos
Message 5 of 8
(8,411 Views)

I didn't use the generate_sine.vi

I used my own function for sinewave generation. Fortunately, I have made it working. I had to decrease the number of ticks (input to wait function) by two ticks. Now, it generates the 20.00kHz sinewave, as expected.

So I am posting the snapshot of current piece of the code.

 

Just a quick calculation: Sinetable has pts=16 points, fclk=40 000 kHz, desired f0=20kHz. So number of wait ticks needed for keeping the accurate frequency should be:

ticks=(fclk/f0)/pts=125. However, I realized that I needed 123 points, instead.

 

 

 

 

 

Download All
0 Kudos
Message 6 of 8
(8,410 Views)

Something interesting too, I measured the values of tick counters before and after running another loop (acquisition). The difference gave me a value =500. But the delay counter was set to 498 ticks.

0 Kudos
Message 7 of 8
(8,407 Views)

While developping another part of the code, another issue has appeared.

If I use a single analog output, I can run it at 320kHz (corresponding to 125 CLK ticks). However, if I use another parallel while loop with another two analog outputs running rouhgly at 4kHz, the speed of the abovementioned first loop dramatically drops down (to about 314 CLK ticks).

 

However, in the product datasheet I found that the board has four DACs.

So now, I don't know if they can run simultaneously at 320kHz or are they sharing some common interface?

If so, it seems that I should add another external DAC with SPI or I2C bus, so I will not make high bus traffic and use digital outputs, instead.

 

Ivan

0 Kudos
Message 8 of 8
(8,403 Views)