03-25-2014 12:36 PM
Hi everyone,
I am looking for a possibility to generate a finite buffered counter output with varying pulse widths, using the X-Series. I am working in C / Python.
I want to output two pulses triggered to an external signal. The first pulse should be short, the second pulse long.
The following code outputs only two identical pulses. How can I modify it to output two different pulses?
CreateCOPulseChanTicks(channel,"","100MhzTimebase",DAQmx_Val_Low,0,300,300)
CfgImplicitTiming(DAQmx_Val_FiniteSamps,2) #output two pulses
CfgDigEdgeStartTrig(src,DAQmx_Val_Falling) #external signal
SetStartTrigRetriggerable(True) #retrigger
Best Regards,
Stefan
03-25-2014 02:16 PM
Hi Stefan,
Use DAQmxWriteCtrTime (or DAQmxWriteCtrTicks or DAQmxWriteCtrFreq). This will let you pass an array of high/low times. Call it before starting your task.
Best Regards,
03-26-2014 03:59 AM
Hi John, thank you for your reply. I tried this function, however I still get two identical pulses, observed by an oscilloscope at the counter output. This is my code:
clock_output = Task() #param=initial delay, ticks low, ticks high write = int32() clock_output.CreateCOPulseChanTicks(channel,"","",DAQmx_Val_Low,30,50,80) clock_output.CfgImplicitTiming(DAQmx_Val_FiniteSamps,2) clock_output.CfgDigEdgeStartTrig(src,DAQmx_Val_Falling) #set clock trigger clock_output.SetStartTrigRetriggerable(True) #retrigger dhigh=(ctypes.c_ulong * 2)() dlow=(ctypes.c_ulong * 2)() dhigh[0]=70 dhigh[1]=200 dlow[0]=90 dlow[1]=500 clock_output.WriteCtrTicks(2,0,10.0,DAQmx_Val_GroupByChannel,dhigh,dlow,None,None) clock_output.StartTask()
Do you have an idea?
Best regards,
Stefan
03-26-2014 04:51 AM
I think I found the solution: CtrWrite advances with each sample written and stays at the last sample, if the buffer is finished. Thus, the last programmed pulse is repeated as given in the ImplicitTiming. If you do a retrigger, you have to provide a long buffer with the alternating pulses you want to write. Here is my working example, this time with WriteCtrTime
clock_output.CreateCOPulseChanTime(channel,"",DAQmx_Val_Seconds,DAQmx_Val_Low,0.0,1E-6,1E-6) clock_output.CfgImplicitTiming(DAQmx_Val_FiniteSamps,2) clock_output.CfgDigEdgeStartTrig(src,DAQmx_Val_Falling) #set clock trigger clock_output.SetStartTrigRetriggerable(True) #retrigger dhigh=(ctypes.c_double * 5000)() dlow=(ctypes.c_double * 5000)() for i in range(0,2500): dhigh[i*2]=1E-6 dlow[i*2]=3E-6 dhigh[i*2+1]=1.5E-6 dlow[i*2+1]=2.5E-6 clock_output.WriteCtrTime(5000,0,10.0,DAQmx_Val_GroupByChannel,dhigh,dlow,None,None)
Best regards,
Stefan
03-26-2014 05:27 PM
It's good you found a workaround but the behavior doesn't seem right to me...
The default behavior in DAQmx (the C / LabVIEW / .NET APIs) is to regenerate data from the buffer. Perhaps the python wrapper you are using is disallowing regeneration somewhere? I tried this with regeneration disabled and it gives the same behavior you reported (though with regeneration enabled it does not).
You can use DAQmxGetWriteRegenMode to verify this theory and DAQmxSetWriteRegenMode to enable regeneration in case it is disabled.
Best Regards,
03-27-2014 11:59 AM
Hi John,
I tried this function and it gives me DAQmx_AllowRegen (10097). I set it to both possibilities but it does not make a difference, I still get two identical pulses. I don't know the reason for this behaviour. I will stick with my workaround.
Best regards,
Stefan