MATLAB Answers

pulse train generator - wrong freq output

1 view (last 30 days)
LO
LO on 11 Jun 2020
I am trying to get 50 Hz digital output from a USB-6211 using the code below. The TTL is supposed to activate a device which is able to show a readout of the incoming input (in Hz). The problem is that as soon as I set ch1.Frequency around 40 the device reads half of it (20).
I thought it could be a duty cycle issue. But changing the length of the d.c. does not eliminate the problem. I can "climb" up to 39 Hz...but then the 40 and anyhting beyond this gets halved or reduced to max 30 or 33..
any idea why ?
daq.reset
d = daq.getDevices;
s = daq.createSession('ni');
s.Rate = 20000; % sample rate
Fs = s.Rate;
s.DurationInSeconds = 5; % video duration in seconds
duration = s.DurationInSeconds;
ch3=addAnalogInputChannel(s,'Dev1','ai7','Voltage'); % this is the camera strobe channel
ch3.TerminalConfig = 'Differential';
ch1 = addCounterOutputChannel(s,'Dev1','ctr0','PulseGeneration'); % camera trigger
ch1.Frequency = 50; % this is going to be the camera fps
ch1.DutyCycle = 0.2; % amount of time the pulse stays active (from 0 to 1)
ch1.Terminal
ch2=addCounterInputChannel(s,'Dev1','ctr1','EdgeCount');
ch2.Terminal
lh = s.addlistener('DataAvailable', @(src, event) logData(src, event, fid1));
lh1 = s.addlistener('DataAvailable', @(src,event) plot(event.TimeStamps, event.Data));
s.IsContinuous = true;
s.startBackground;
pause(duration);
s.stop % end recording

  0 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!