[Labjack T7] PWM Frequency In | LabJack
 

[Labjack T7] PWM Frequency In

10 posts / 0 new
Last post
Kurlet
Kurlet's picture
[Labjack T7] PWM Frequency In

I'm having trouble with understanding how Frequency In feature works.

I'm using newest Labjack T7 firmware with Python LJM library.

This is part of code for measurement:

    labjack = ljm.openS("T7", "ANY", "ANY")

    # Configure clock

    ljm.eWriteName(labjack, "DIO0_EF_ENABLE", 0)

    ljm.eWriteName(labjack, "DIO_EF_CLOCK0_DIVISOR", 0)

    ljm.eWriteName(labjack, "DIO_EF_CLOCK0_ROLL_VALUE", 0)

    ljm.eWriteName(labjack, "DIO_EF_CLOCK0_ENABLE", 1)

    ljm.eWriteName(labjack, "DIO0_EF_OPTIONS", 0)

    ljm.eWriteName(labjack, "DIO0_EF_CONFIG_A", 0)

    # Configure DIO0 for PWM Frequency In

    ljm.eWriteName(labjack, "DIO0_EF_INDEX", 3)

    ljm.eWriteName(labjack, "DIO0_EF_ENABLE", 1)

    # Update registers and print value

    ljm.eReadName(labjack, "DIO0_EF_READ_A_AND_RESET")

    print ljm.eReadName(labjack, "DIO0_EF_READ_B_F")

It works as expected when duty cycle is not 0% neither 100% and when signal is 0% and 100% it should return "inf".

However if i make some measurements before and than adjust signal to 0% or 100% it doesn't update, namly it should:

DIO#_EF_READ_A: Returns the period in ticks. If a full period has not yet been observed this value will be zero.

Instead it holds previous value untile power supply is not reseted manually.

My question is there any way to reset those regsiters using for example LJM library? So i would get alwasy "inf" where measurement can't be taken instead of wrong previous value?

Also i would like to know if it is safe to re-configure in-the-fly DIO0 (or DIO1) for depending on need reading both: Frequency In and Pulse Width In. For example:

1) Configure DIO0 for Frequency In feature

2) Read DIO0

3) Configure DIO0 for Pulse Width In feature

4) Read DIO0

5) Repeat...

LabJack Support
labjack support's picture
I ran a quick test and

I ran a quick test and noticed 2 things. When using DIO0_EF_READ_A_AND_RESET I will get a reading and the next reading will be zero as long as a new measurement has not been made. And disabling a DIO_EF does not clear results from previous operations. The disabling issue will be corrected in the next beta release and the reset function appears to operate correctly.

Kurlet
Kurlet's picture
After further investigation

After further investigation it seems that labjack needs some more time to measure certain signal characteristics.

For example when i perform measurement in single-shot mode using DIO extended features on same DIO i need to wait at least 500 ms in order to get proper readings even if the lowest frequency that i use is 244 Hz. I also tried continuous mode but it seems like have no effect.

LabJack Support
labjack support's picture
Using the reset register

Using the reset register reset the measurement even if one has not been completed. That means that reading and resetting faster than two times the signal period will result in no reading ever being completed. Try without the reset option.

We have been discussing a feature that would zero out the reading if no edges are detected after a specified amount of time. This is the way a DMM works. Does that sound useful to you?

Kurlet
Kurlet's picture
Tried with and without DIO0

Tried with and without DIO0_EF_READ_A_AND_RESET and it seems like with reset i got measurements fasters. Scenario for those two apporaches:

1) First configure DIO for Pulse width in than make delay for at least 500ms than read DIO_EF_READ_A_F and DIO_EF_READ_B_F

2) First configure DIO for Pulse width in than read DIO0_EF_READ_A_AND_RESET than make delay for at least 300ms than read DIO_EF_READ_A_F and DIO_EF_READ_B_F

It looks to work similar but when i tried to wait for 300 ms in first one, some measurements were wrong, probably registers weren't updated fast enough. What is strange to me is that PWM signal has frequency 244 Hz so i would expect approximately 5 ms for full period. 

LabJack Support
labjack support's picture
I would expect readings at 1

I would expect readings at 1/2 the signal rate. So every 10 ms or so for your signal. What firmware version does your T7 have?

I ran another test with the following conditions:

  • Clock 0: Prescale 8, Counts 10000000
  • DIO_EF0: Mode 5, all other values 0.
  • Function generator reporting 212.5 Hz.

I am seeing values from 212.26 to 212.76 with 10 value changes in a 100 ms window.  So that seems to be working.Try updating your firmware (betas are worth a try). Also, you can send your code or project to us and we will take a look at it.

Kurlet
Kurlet's picture
I'm using newest beta

I'm using newest beta firmware (1.0216).

My code is in the attachement. In my code i mocked external function which is used to set device PWM signal than i want to continuous measure duty (DIO0_EF_INDEX 5) and frequency (DIO0_EF_INDEX 3). When i try to wait 10 ms before reading those registers it gives me outdated readings.

File Attachment: 
LabJack Support
labjack support's picture
The first thing that I notice

The first thing that I notice is that the DIO_EF mode is being constantly changed. We can get both duty cycle and frequency from just mode 5 (duty cycle). READ_A and READ_B return the high time and the low time of the signal. The two can be added to get period. Removing the switch to frequency should simplify your program and hopefully get results similar to what I am seeing.

Kurlet
Kurlet's picture
Thanks for replay. I changed

Thanks for replay. I changed me code so i'm only using extended feature for pulse width in for both signal characteristic. I did some tests and it also needs at least 300 ms for proper signal reading.

File Attachment: 
LabJack Support
labjack support's picture
After a crash course in

After a crash course in python I got the program from your last post to work. Bellow there are two screenshots one when reading at 10ms and one when reading at 20ms. The 10ms program gets a new reading about 60% of the time. I believe this is due to timing jitter. Sleep functions in operating systems to not work well. They always have some error, ±5 or 10 ms is not uncommon. Bumping the read time up to 20 ms results in a new value every reading.