Skip to main content
Submitted by D Bruch on Thu, 04/09/2009 - 17:01

I have RIO-47120 operating through a serial connection. I'm trying to produce a sinusoidal waveform on one of the analog outputs. I've been able to achieve this by using a loop which updates an angle, computes the sign of this angle, and outputs the computed value as an analog voltage. In order to get a 1 Hz sine wave I have to increment the angle by 0.625 degrees. This seems to match the processing speed of the RIO and its updating loop. Is there a way to command the processing speed so I know I'm getting a 1 Hz wave? Or, better yet, is there another command that would produce a continuous (or at least 60+ second) sine wave? Thanks.

Daniel

Comments 4

Galil_AndyH on 04/10/2009 - 12:27

The key is that you want to have a deterministic loop time. You can do this with the AT command. Here is a program that outputs a 1Hz sine wave.

[code]
REM sine wave output for RIO
amp=2;'amplitude of sine wave (Volts)
freq=1;'frequency of sine wave (Hz)
of=2.5;'DC offset (Volts)
n=((360*freq)/500)
AT0;i=0;'set time and index reference
#A
s=(amp*@SIN[i])+of;i=i+n
AO0,s;AT-2
JP#A,i<360
n=((360*freq)/500);i=0
JP#A
[/code]

D Bruch on 04/10/2009 - 13:25

Andy,

Thanks for your assistance. This works great. This leads me to two additional questions. First, why does a 2 msec wait/initialize time (AT-2 command) work for a one Hz wave? Second, What is the best command to use to stop the program?

Thanks,
Daniel

D Bruch on 04/10/2009 - 14:19

After some prodding I've answered my first question. It seems that the AT command has to correspond with how many increments you break the sine wave into. Luckily I was able to figure that one out, in spite of it being Friday. My second question still stands; I've searched around for an interrupt or stop command but have yet to come up with one.

Thanks for your help,
Daniel

Galil_AndyH on 04/10/2009 - 14:44

The ST or HX commands will stop the program. You could also put a condition on the JP#A and just set a variable or an input and then have the program end.

For example

REM sine wave output for RIO
stop=0;'variable to stop program
amp=2;'amplitude of sine wave (Volts)
.
.
.
JP#A,stop=0

Then you would just set stop=1 to stop the program.