I played with this a bit this morning and found that specifying the pulse width and delay as fractions of a single cycle awkward (at best) from an engineering standpoint. So, I changed things around to accept input parameters of the desired waveform period, pulse wdith, and pulse delay–specified in seconds. This removes the engineer from having to calculate the pulse width and delay ratios (typically specified in seconds) from the waveform’s period.
I think I will incorporate a pulse generator function into my PCGU1000Ctl application. The user would specify pulse width, delay, and number of pulses. Then, if in pulse mode, on each frequency change the app will create a temporary library file that maintains the specified width and delay.
[code]'Function MakePulseLib() As String
’
’ created: 01/17/2009
’ by: Cliff Knight (freeware, honorary mention would by nice)
’
’ modifed: 01/18/2009 by CIK to delete fractional specification of pulse width and delay
’
’ inputs:
’ periodWave - the desired waveform period in seconds, Ex 1kHz = 0.001, defaults to 0.001
’ note: may be passed as 1/f, Ex. 1kHz = 1/1000
’ widthPulse - the desired pulse width in seconds, Ex. 20us = 0.00002, defaults to 0.00002
’ delayPulse - the delay between pulses in seconds, defaults to 0.00005
’ mumPulses - the desired number of pulses, defaults to 1
’ amplitudeMax - the desired maximum pulse amplitude multiplier (-1.0 to 1.0), defaults to 1.0
’ amplitudeMin - the desired minimum pulse amplitude multiplier (-1.0 to 1.0), defaults to 0.0
’ sampleLength - the desired sample length, defaults to 8192
’
’ outputs:
’ function returns a text string containing the waveform library code
’
’ notes:
’ For flexibility the amplitude multipliers are not validated or qualified in any way other
’ than to assure thay are >= -1.0 and <= 1.0.
’
’ example:
’ sLib = MakePulseLib(0.001, 0.00002, 0.00005, 2, 1.0, 0.0, 8000)
’
’ would create a waveform that when reproduced at 1kHz (0.001s period) would have
’ 2 pulses of 20us width, with a 50us delay between them;
’ maximum amplitude will be the FG’s Vout * 1.0;
’ maximum amplitude will be the FG’s Vout * 0.0;
’ an 8000 point sample length will be used
’
’ Note that at other frequencies the pulse widths will be altered proportionaly
’ At 5kHz this would be two 4us pulses, separated by a 10us delay
’
’ The waveform period may be passed as the reciprocal of the frequency,
’
’ sLib = MakePulseLib(1/13587, 0.000002, 0.000005, 2, 1.0, 0.0, 8000)
’
’ would create a waveform that when reproduced at 13.587kHz (0.00007359s period) would have
’ 2 pulses of 2us width, with a 5us delay between them;
’ maximum amplitude will be the FG’s Vout * 1.0;
’ maximum amplitude will be the FG’s Vout * 0.0;
’ an 8000 point sample length will be used
’
Public Function MakePulseLib(Optional ByVal periodWave As Double = 0.001, _
Optional ByVal widthPulse As Double = 0.00002, _
Optional ByVal delayPulse As Double = 0.00005, _
Optional ByVal numPulses As Long = 1, _
Optional ByVal amplitudeMax As Double = 1#, _
Optional ByVal amplitudeMin As Double = -1#, _
Optional ByVal sampleLength As Long = 8192 _
) As String
Dim ctr0 As Long
Dim lPulse As Long
Dim lDelay As Long
Dim sAmplMax As String
Dim sAmplMin As String
Dim ts As String
Dim tl As Long
Dim td As Double
On Error GoTo MakePulseLib_Err
'verify max and min amplitude values, Abs() cannot be greater than 1.0
If Abs(amplitudeMax) > 1# Then _
amplitudeMax = 1#
If Abs(amplitudeMin) > 1# Then _
amplitudeMin = 1#
'verify sample length, canmnot be > 8192
If sampleLength > 8192 Then _
sampleLength = 8192
'get the # of sample points for the pulse and delay
'calculate width ratio
td = widthPulse / periodWave
'calculate # of points
lPulse = Round(sampleLength * td, 0)
'same for delay
td = delayPulse / periodWave
lDelay = Round(sampleLength * td, 0)
'format the amplitudes as decimal
sAmplMax = Format(amplitudeMax, "0.00000")
sAmplMin = Format(amplitudeMin, "0.00000")
'init the output waveform as the minimum amplitude
ts = sAmplMin & vbCrLf & "(0)" & vbCrLf
'for each pulse
For ctr0 = 1 To numPulses
'add it to the waveform as "n.nnnnn (points)" + CrLf + "(0)" to block ramping
ts = ts & sAmplMax & " (" & lPulse & ")" & vbCrLf & "(0)" & vbCrLf
'subtract # of points from sample length
sampleLength = sampleLength - lPulse
'if there's another pulse add the delay
If ctr0 < numPulses Then
'same as pulse above, but for delay
ts = ts & sAmplMin & " (" & lDelay & ")" & vbCrLf & "(0)" & vbCrLf
sampleLength = sampleLength - lDelay
End If
Next
'remaining sample points must be >= 0
If sampleLength >= 0 Then
'if > 0 then add the command
If sampleLength > 0 Then _
ts = ts & sAmplMin & " (" & sampleLength & ")" & vbCrLf
Else
'whoops, used up the sample buffer
ts = "error -99; waveform definition error--likely too many pulses"
End If
MakePulseLib_Exit:
'set return value
MakePulseLib = ts
Exit Function
MakePulseLib_Err:
'set error as return value
ts = "error " & Err.Number & "; " & Err.Description
Err.Clear
Resume MakePulseLib_Exit
End Function
[/code]