[Labjack T7] Pulse Width In | LabJack
 

[Labjack T7] Pulse Width In

2 posts / 0 new
Last post
KRejno
rejnowicz.karol@gmail.com's picture
[Labjack T7] Pulse Width In

I have trouble with reading PWM duty using Pulse Width In:

Used: newest labjack t7 firmware and Python LJM Library

Part of configuration and measurement code:

 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)

sleep(0.001) #wait 1millisecond

#configure DIO0 for Pulse Width In

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

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

sleep(0.001)

high_state_time = ljm.eReadName(labjack, "DIO0_EF_READ_A_F)

low_state_time = ljm.eReadName(labjack, "DIO0_EF_READ_B_F")

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

This sequence of reading high_state_time and low_state_time works ok.

The problem is when i use DIO0_EF_READ_A_F_AND_RESET instead of DIO0_EF_READ_A_F.  In this case  high_state_time is read successfully, but low_state_time is 0. 
From documentation:  DIO#_EF_READ_A_F_AND_RESET: Performs the same read as described above, but then also clears the register so that zero is returned until another full period is measured.

And: DIO#_EF_READ_B: Returns the measured low time in clock source ticks.  This is a capture register ... it is only updated when one of the READ_A registers is read.

Does the read DIO0_EF_READ_A_F_AND_RESET should update the DIO0_READ_B_F or DIO0_EF_READ_A_F_AND_RESET should reset DIO0_READ_B_F?

What sequence should I use to correctly read low and high state time and make sure that registers are reset after reading?
Now for pwm_duty_read() function i use sequence:
_ENABLE, 1
_READ_A_F
_READ_B_F
_READ_A_F_AND_RESET
_ENABLE, 0
but this sequence takes more time and last _READ_A_F_AND_RESET looks redundant.

LabJack Support
labjack support's picture
The reset register clears out

The reset register clears out all the data. We will discuss options for keeping B, C, D after a reset.