06-09-2012 09:32 AM
Dear All
I am trying to generate a continuous digital output based on a rotary encoder. The rotary encoder sends out 1800 trigger pulses every revolution (which I use as my sample clock) and it also sends out 1 pulse every revolution (which I use as the start trigger of my digital waveform).
So the way I do this is, I build a waveform of 1800 datapoints (and set the low and high times) for the intial delay and sample time. And then I write this on a digital output channel using my sample clock (with 1800 samples per channel) as the rotary encoders 1800 pulses and start trigger as the single pulse every revolution. So in thoery, between the two start triggers there should be 1799 pulses.
However what I have noticed it when I plug this digital output on an oscilliscope, the digital wave is produced every alternate cycle of the rotary encoder. It is only when I reduce the number of sample to be written to the output channel to around 1650, that I get a digital output on every cycle of the encoder. One explanation I can think is that, for some reason, the 1800 samples, of an 'n' cycle are not written before the the next start tigger (of the 'n+1' wave) is detected, therefore it ignores the start trigger and completes its 1800 samples before looking for a start trigger of the 'n+2' wave. This it does because I have put in a 'wait unti done' vi. My code does not work without this vi.
I donot see why it is not able to write 1800 samples before the start trigger of the next wave. There might be an issue with the way I have written the code. (please find code attached)
Any kind of help would be greatly appreciated. I am using a PCIe-6351.
Regards
06-11-2012 05:19 AM
Ok looking at your code the first thing that strikes me as needing to be changes is your DAQ task. You are creating and closing a task with every iteration of the while loop. This is bad practice.
The only elements of the task that should be within the loop are the write and the wait until done.
The second thing to check is how many elements you are writing. This can be done using an array size vi. Does this show an array of 1800 elements? if not there is something wrong with how you have generated your array of values.
Hope this helps to begin with.
06-11-2012 07:14 AM
looking a bit more into it I am not convinced you have set your DAQ task timing parameters correctly. Have a look at the examples in the example finder in the help menu to get a better Idea.
Also the code you have made to create your array can be simplified to what is shown below.
06-11-2012 11:57 AM
Hey Matthew,
Thank you for looking for the issue. I agree the the wave generation code can be much simplified as you pointed out.
However that did not seem to solve the problem
I tried increasing the samples per channel on the sampling clock, without changing the value of the samples per cycle bit. So when I increased the value to about 4000, I started getting pulse cycles every engine cycle.And the channel was still writing 1800 samples per channel. It seems to have solved the issue, although I have no idea why.
06-12-2012 03:12 AM
in your daq task you have specified multiple channels but in your write you only have single channel n sample. I think you need to change to a single channel or change the array that you are writing to a 2D array for all the channels you are using. Did you have a look in the example finder? They show how to code a DAQ task well. I use them as a starting point for most of my DAQ code.