waveforms4j icon indicating copy to clipboard operation
waveforms4j copied to clipboard

Strange behavior of FDwfDigitalOutDividerSet()

Open micheledellaciana1 opened this issue 5 years ago • 3 comments

Hi, I'm not understanding how it works FDwfDigitalOutDividerSet(). From the C doc I saw that It sets the divider of the internal clock for the counter. Here it sets the frequency in Hz of the counter? If it's so, it works properly only is you set as frequency the maximum frequency (i.e. 1e8 Hz). With lower frequency, It behaves differently.

For example, if you put the frequency of the counter to 10 kHz, and low and high counter to 5 and 5, I expect to see a square wave with a period of 1 ms, (0.1 * 5 + 0.1 *5 = 1), but I get a square wave of period 2ms.

    FDwfDigitalOutEnableSet(pin, true);
    FDwfDigitalOutDividerSet(pin, (int) 1e4); // Frequency of counter
    FDwfDigitalOutCounterInitSet(pin, true, 0);
    FDwfDigitalOutCounterSet(pin, 5, 5);
    FDwfDigitalOutConfigure(true);

By the way, If I set the counter frequency to the max, everything works fine, but the sum of the values of the counters cannot exide unsigned int maximum (I think because c function has that limitation).

am I missing something about FDwfDigitalOutDividerSet() ?

Thk in advance,

Michele

micheledellaciana1 avatar Apr 14 '20 23:04 micheledellaciana1

I'm not quite sure as I haven't used this is quite a long time now. Did you read the SDK docs page 69: https://reference.digilentinc.com/_media/waveforms_sdk_reference_manual.pdf?

Check out my Blink1 class here: https://github.com/knowm/waveforms4j/blob/develop/src/test/java/org/knowm/waveforms4j/ad2/Blink1.java. You can see it's setting the frequency. BTW is my comment then false on line 53? Is it actually set to 5 Hz??

timmolter avatar Apr 15 '20 07:04 timmolter

BTW, I never use FDwfDigitalOutCounterInitSet, so you might just try eliminating that line. Maybe it's messing something up.

timmolter avatar Apr 15 '20 07:04 timmolter

Exactly, the blink has a frequency of 5 Hz, not 2!

FDwfDigitalOutCounterInitSet works properly...

micheledellaciana1 avatar Apr 15 '20 13:04 micheledellaciana1