Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

generate a continuous signal variing in frequency and amplitude

I am using measurement studio 8.0 with Visual Studio, writing C++.
I would like to output a continuous analog signal through a PCI6733 card.
The amplitude and frequency of this signal have to be refreshed approximately
every 100ms according to values given by a simulation.

I think the more relevant example from measurement studio is the one called
"ConGenVoltageWfm_IntClkDlg" in the example files provided. This example
works nicely on its own, with my cards.

What i am trying to do is to refresh it without interrupting the signal already being sent.
To do so, i am calling the following bit of C++ code every time I want to update the
frequency and amplitude:

           CFunctionGenerator fGen(m_task->Timing,
           m_desiredFrequency,
           m_samplesPerBuffer,
           m_cyclesPerBuffer,
           m_waveformType,
           m_amplitude);

            CNiDAQmxAnalogSingleChannelWriter writer(m_task->Stream);
            writer.WriteMultiSample(false, fGen.Data);

The thing that happens is that the amplitude refreshes with a big lag time
(a few seconds) whereas the frequency is updating correctly every 100ms.
Moreover, this seems to take a lot of CPU power. This CPU consumption is
not appearing in the task manager surprisingly, but my dialog  obviously struggle
to be moved. Maybe you have some ideas ?

I may be using a wrong technique ! It's more than likely actually 🙂 Thanks very
much for your advices !

Regards,
Laurent
Message 1 of 8
(5,908 Views)
Hi Radium,
 
I have seen this kind of problem before with the high processor usage.  When you run the code can you run it without the debugger?
This may actually help the CPU usage.
The code looks fine and I can't really see anything too wrong with it.
 
Have you tried looking at the examples that are installed with DAQmx support?
~\National Instruments\NI-DAQ\Examples??
 
These may have some good starting points for your code.
 
I'll keep looking
 
AdamB
Applications Engineering Team Leader | National Instruments | UK & Ireland
Message 2 of 8
(5,879 Views)

Hi Radium,

I thought you might like this.

I just created this for you to have a go with.  It is a DLL that will allow you to create an array of x size and it will produce the appropriate freq as per your input.  From execution to execution it will also store the phase so phase will not be lost.

It is just example code but it should do as you need without you having to write the maths yourself.  Give it a go?

ArraySize = The size of the buffer you will be using

SampleFreq = The rate that you have the analog card set to output. (for example100Ks/s)

Frequency = Frequency you wish to see on the output

Amplitude = amplitude you wish to see on the output

Output Array = the calculated values

The bmp shows the waveforms produced and how tey sit together.

Hope all this helps

AdamB

Message Edited by AdamB on 09-21-2006 11:37 AM

Applications Engineering Team Leader | National Instruments | UK & Ireland
Download All
Message 3 of 8
(5,865 Views)
Thank you very much AdamB for these answers ! To go back to my problem I think I've just found a solution this evening ! I am still trying to get my head around it, but that should work.

The technique that I am trying to use (filling the buffer on the fly, calling the given bit of code every say 100ms) appears to be ok. It's really the "ConGenVoltageWfm_IntClkDlg" example that I have to use.

It looks like the very slow response of the signal at low frequencies is actually coming from the way i generate my buffer, using the CFunctionGenerator.

Assuming I want to output 5 period of a common sinewave, the length of 5 cycles is higher in time at low sineware frequencies than at high frequencies (assuming I keep the same write frequency to output the points on the DAQCard). Since the DAQCard is outputting the entire buffer before i can send anything else, I think it is simply taking a lot of time to output low frequency sinewave cycles.

I believe that the technique I will have to use is outputting the same buffer length each time i send an array to the buffer, in order to remove this low frequency response time problem. To simulate a smooth frequency change, I will have to use the Chirp formula. But it's not obvious that i will have a complete sinewave periods for each buffer i send, so i will have to keep track of the last phase delay to compute the next array of values, and avoid discontinuities.

Thanks a lot for your help AdamB, I keep you informed of the result I will have !
0 Kudos
Message 4 of 8
(5,855 Views)
Hi Radium,
 
Whatyou described there is exactly what the dll does.  Hope it helps
Good look
 
Thanx
 
AdamB
Applications Engineering Team Leader | National Instruments | UK & Ireland
Message 5 of 8
(5,850 Views)
Hi AdamB
I tried to build my own code to generate fixed length buffers, keeping in memory the last phase of the sinewave that I have just sent in order to generate the following buffer from that starting phase. Here is a the bit of (gash) code im using so far, I will clean it in the next days.
This code is now working fine, and I know that am sending the right vector with the right values.

The only issue that is still happening is that the amplitude of the signal is sometimes suddently decreases, reaches a constant 0 for a few miliseconds and re-increases up to the correct value. This phenomenum is lasting 1 or 2 seconds and is a bit annoying because im counting the number of time the signal crosses 0 on an external device to get the frequency 🙂

Enclosed is the bit of code i am using. I am calling the "updateChannel()" function from an external code every 100ms approx.
Let me know if you see any bad practise 🙂

Thanks a lot guys !!!
Rad  
0 Kudos
Message 6 of 8
(5,829 Views)

Hi, can u help in generating a sine wave and powerspectrum in the wavegraph indicators as shown in the image.

0 Kudos
Message 7 of 8
(3,971 Views)

Hi, can u help in generating a 50Hz sine wave and powerspectrum in the wavegraph indicators as shown in the image using C# in Visual Studio 2010.

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