Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

buffered counter output in C

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

0 Kudos
Message 1 of 6
(6,760 Views)

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,

John Passiak
0 Kudos
Message 2 of 6
(6,757 Views)

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

 

0 Kudos
Message 3 of 6
(6,747 Views)

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

0 Kudos
Message 4 of 6
(6,744 Views)

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,

John Passiak
0 Kudos
Message 5 of 6
(6,731 Views)

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

0 Kudos
Message 6 of 6
(6,723 Views)