Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

software signal lock example in C++

Solved!
Go to solution

Hello,

I'm new to NI and DAQ. Just posted this question before http://forums.ni.com/t5/Signal-Conditioning/usb-6211-DAQ-frequency-question/td-p/3202422  and found out that the signal can't be locked on a hardware level.

Can anyone provide an example in C / C++ to lock a 400 hz signal. I've used the ContAcq-IntClk.c example to read data from one resolver (sind and cosine) and a reference signal. However since the signal shifts to the right (in this case) it becomes difficult to determine the resolver's position.

 

Thank you in advance.

Regards,

Gerhard

0 Kudos
Message 1 of 2
(4,572 Views)
Solution
Accepted by topic author crashdog

Looks like I can self solve another of my posts 😉 lonely here in this forum... kind of... 😉

Well since I asked for a code example, I'll provide my solution here. It's probably by far not perfect, but works. So improvement suggestions are welcome.

	DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, 1000, 10.0, DAQmx_Val_GroupByChannel, data, 3000, &read, NULL));
	if( read>0 ) {		
		for (int loopa = 2001; loopa < 2999; loopa++)
		{
			if (data[loopa] > highestRef)
			{
				highestRef = data[loopa];
				highestPos = loopa;
			}
		}
		referenceS = data[highestPos];
		lsine = data[highestPos-1999];
		cosine = data[highestPos-999];

		radians = atan2(cosine, lsine);
		angle = radians * (180 / M_PI);

		if (cosine < 0)
			angle += 360;

		printf("D: %f %f ref: %f refH: %f Pos: %i angle: %f\r", lsine, cosine, referenceS, highestRef,highestPos, angle);
		fflush(stdout);
	}
0 Kudos
Message 2 of 2
(4,566 Views)