Tasks
1. Use the PWM DIO to output a frequency on F00.
2.Measure that frequency using F01.
Successes
I used the F0 output to successfully generate a 1K signal and verified that with a scope.
Problems
I wired F00 to F01 and attempted to measure that frequency. I measured a period of 0 and a frequency of +Inf.
Debugging
The PWM signal appears to be present during the counter measurement attempt.
I've attached the PWM code and the counter code, because they could interact grossly. I am assuming that I've specified separate timebases and there isn't a "timebase fight" going on. The counter code is as follows....
// ************ counter *************
LJM_eWriteName(handle, "DIO1_EF_ENABLE", 0); // Disable the EF system for initial configuration
LJM_eWriteName(handle, "DIO1_EF_INDEX", 3); // Configure EF system for ring to rising
LJM_eWriteName(handle, "DIO_EF_CLOCK1_DIVISOR", 1); // Configure Clock1's divisor
LJM_eWriteName(handle, "DIO_EF_CLOCK1_ROLL_VALUE", 0); // Configure Clock1's roll value, 0 = max resolution ??
LJM_eWriteName(handle, "DIO1_EF_OPTIONS", 1); // Configure what clock source to use: Clock1
LJM_eWriteName(handle, "DIO1_EF_CONFIG_A", 1); // Configure specified clock source's count matches this value the line will transition from high to low
LJM_eWriteName(handle, "DIO1_EF_ENABLE", 1); // Enable the EF system, PWM wave is now being outputted AND the counter
LJM_eReadName(handle, "DIO1_EF_READ_A_F",&Freq); // read period on F01??
LJM_eReadName(handle, "DIO1_EF_READ_B_F",&Freq); // read freq on F01??
printf("frequency = %f",Freq );
//*****************************************************************
Not sure what I'm doing wrong and could use a boot in the right direction.
This might be a good programming example to include in your example distribution (assuming we can get the ^&^*&&^ thing working.) 1 external connection allows you to play with generating clocks as well as measuring frequencies.
Fred
I gave this a quick try and everything worked for me. I tried firmware versions 1.0188 and 1.0199. Code is attached.
I've had a chance to play with this and it has a weird problem .....
The code "works" in that it reports 1KHZ. The FIO0 output is putting out the 1KZ signal fine.
... however when I remove the external connection between the FIO0 output and the FIO1 input .... it continues to report there is a 1KHZ signal on FIO1.
Not sure what is going on, the code seems to clearly define FIO0 as the PWM output and FIO1 as the measurement input, but somehow the measurement input is reporting 1KHZ when left unconnected.
e = LJM_eWriteName(handle, "DIO0_EF_ENABLE", 1); // Turn on the PWM
if (e != 0) break;
e = LJM_eWriteName(handle, "DIO1_EF_ENABLE", 1); // Turn on the period measurement
if (e != 0) break;
for (t = 0; t < 20; ++t) {
Sleep(100);
e = LJM_eReadName(handle, "DIO1_EF_READ_A", &result);
if (e != 0) break;
printf("Value A = %f\r\n", result);
}
The LabJack is looking at the rising edges. Every time an edge is detected the difference between the current clock count and the last clock count is saved as the period. If no edges are being detected then the values never get updated. You are always seeing that last valid measurement.
You can try DIO1_EF_READ_A_AND_RESET will reset the measurement and clear the result. Resetting comes with a couple caveats. If you are reading faster than the signal that you are trying to read then the result will always be zero, because the measurement is being reset before a measurement can be completed.
We are working on a new feature what will allow you to specify a timeout. If no edges are detected during that time period then the result will be reset. I think that will produce the results that you expect.