Jump to content
  • 0

Generating 500 kHz Signal in C++


C. Drutman

Question

I am just starting with the MCC Library with a USB-2627, and my goal is to generate a 500 kHz sin wave as a simple sanity test. My first step was to verify I could output a signal with AOut, and that worked as advertised. I then changed the signal-generating part of the code to:

 

double f=.5E6 ;

double w=6.283*f ;

double dt=1.E-6 ;

double t=0 ;

double data=0 ;

while (err == ERR_NO_ERROR) {

  data=sin(w*t) ;

  err=ulAOut(hdnl, channel, range, flags, data) ;

  t += dt ;

}

When I looked at the signal on a scope, I got a ~10 Hz sin wave, so clearly I am missing something. Looking at the documentation for the USB-2627, there is a reference to setting the sampling rate; is that what I am missing? If so, what is the MCC Library call to set this?

FYI, I am using GCC on Linux.

Many thanks.

 

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

A 500k Hz sine wave is not doable. This is because the analog outputs on your board have a maximum update rate of 1M S/s and a decent sine wave should have at least 100 updates per cycle. If you use this rule of thumb, the maximum sine wave possible is 1 M S/s divided by 100 or 10k Hz. If you are still interested in generating a waveform, please review the AOutScan.c example. 

Link to comment
Share on other sites

  • 0
On 12/8/2022 at 11:51 AM, JRys said:

A 500k Hz sine wave is not doable. This is because the analog outputs on your board have a maximum update rate of 1M S/s and a decent sine wave should have at least 100 updates per cycle. If you use this rule of thumb, the maximum sine wave possible is 1 M S/s divided by 100 or 10k Hz. If you are still interested in generating a waveform, please review the AOutScan.c example. 

Not quite what I am looking for. I am receiving data from a device, and based on that data I need to generate an analog output. The input data is updating every 10 us, and I need to generate an analog output at the same rate, with a slight lag for computing the analog output from the input signal. Filling a buffer, as in AScanOut.c, is not an option as a I only have a single input at a time. Based on the test I did, I cannot send single analog outputs quick enough.

Edited by C. Drutman
Update
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...