06-27-2011 03:07 AM
I'm trying to make two continuously PWM signals that their rising edge are at same time.
Pulse width can be change for each out indecently, and freq always update for booth at same command (see below code lines)
When it start the two signal are perfect but after few update it lose the raising edge sync
___/-----\_________/-------------\_______
___/------------\_____/---------------\_____
steps
1) create task with ctr0:1
2) start it on external rising edge
3)change Pulse DC and change pulse Freq according to needs
Example of updating :
void UpdatePwm(LPVOID lpParams) {
.
.
status = DAQmxSetCOPulseDutyCyc(g_PwmTaskHandle, "Dev1/ctr0", xValue);
.
status = DAQmxSetCOPulseDutyCyc(g_PwmTaskHandle, "Dev1/ctr1", yValue);
.
status = DAQmxSetCOPulseFreq(g_PwmTaskHandle, "Dev1/ctr0:1", freq);
.
06-28-2011 04:13 PM
Hi reln,
The results you are seeing are due to clock deviation. In this case what you need to do is use the 10 MHz reference clock as a phase lock, so all your samples are in phase and look synced. Please refer to M Series Synchronization with LabVIEW and NI-DAQmx. Though the code is in LabVIEW the concept is the same. What is the DAQ device that you are using?
Best Regards,
Jignesh P
06-29-2011 12:29 PM
It looks like you're using the same device for each pulse generation so Jignesh's suggestion isn't going to be applicable.
The issue is that the updates to the counter's frequency are done in software so are thus non-deterministic. Even though you are writing to the hardware with the same function call, the exact time that each counter updates will vary and so you might update one of the frequencies before the other, which would create an offset.
There might be a better way to do this depending on what hardware you are using. For example, X Series DAQ devices support buffered counter outputs. Or... if you were on an M Series device you could use digital output lines to generate the PWM signals.
Best Regards,
07-05-2011 03:12 AM
At the end with some NI support I did it
ctr0 is regular CO Pulse task :---> DAQmxCreateCOPulseChanFreq
ctr0 output is the ctr1 trigger
ctr1 is a DAQmxCreateCOPulseChanTicks
and it retiger by ctr0 output --> DAQmxSetStartTrigRetriggerable(itaskHandle,1);
in order to make them at same risetime 2 action need to be done
set ctr1 to DAQmx_Val_Low
count the minimum possible(2) clock at low --> DAQmxSetCOPulseLowTicks
and count the positive duty cycle --> DAQmxSetCOPulseHighTicks
ctr0 is uptate regular DAQmxSetCOPulseFreq and DAQmxSetCOPulseDutyCyc
so I got delay of 2/100Meg sec