Hello.
I do not see a simple explanation of how to configure counter modes in LJPython. From what I can tell using the control panel, the default mode is a system clock counter (or something like this). It continually increments. As before, I can properly configure my counter using LJ Control Panel, but cannot seem to find any examples of how to set up a firm or firm with debounce timer.
From what I can tell, I need to instantiate a ConfigParser object, change the mode of the timer, and import it. Even with (some) helpful comments in the source, it is clear as mud how to do this. This seems like it should be an example.
Thanks,
Colin
Start by looking at this example which uses timers:
https://github.com/labjack/LabJackPython/blob/master/Examples/PWM-loopin...
Timer mode documentation can be found here:
U3: https://labjack.com/support/datasheets/u3/hardware-description/timers-co...
U6: https://labjack.com/support/datasheets/u6/hardware-description/timers-co...
UE9: https://labjack.com/support/datasheets/ue9/hardware-description/timers-c...
A quick example using low-level calls and a U3, derived from the PWM-loooping example:
from time import sleep
import u3
#Open first found U3
d = u3.U3()
# Set the timer clock to 48 MHz (default).
d.configTimerClock( TimerClockBase = 2)
#Enable 1 timer starting at FIO4. Note to use NumberTimersEnabled for the U6.
d.configIO( NumberOfTimersEnabled = 1, TimerCounterPinOffset = 4 )
# Configure the timer for firmware counter with debounce (mode 6). Debounce is 16 to 32 ms (value = 1).
d.getFeedback( u3.Timer0Config(TimerMode = 6, Value = 1) )
#Wait for 1 second
sleep(1.0)
#Read the current count
print d.getFeedback( u3.Timer0() )
#Close the device
d.close()
This is functional within a single session. Two questions:
1. Setting the timer configuration resets the timer. I have also noted that when I try to read the timer after closing a session and opening another one (without reconfiguring) , I return a configuration error. How can I configure the timer/counter to continue even after the session is closed? I do not wish to have to maintain a session indefinitely and/or insert blocking code to wait for counts. Is this not possible?
2 What is the semantic difference between a timer and a counter in this case? It seems that we are clearly counting something, but using a timer. This explains why I did not find the examples.
Thanks.
I'm sorry. Point 1 above was my mistake. I had a previous daemon backgrounded that was reverting my counter configuration during efforts. I can see that the configuration is retained.
By testing for config, using something like this works:
# When passed no argument, just reads.
currentconfig = device.configIO()
try:
device.getCalibrationData()
if currentconfig['Counter0Enabled'] or currentconfig['NumberTimersEnabled'] != 1:
device.configIO(EnableCounter0=True, NumberTimersEnabled=1)
d.getFeedback( u6.Timer0Config(TimerMode = 6, Value = 1) )
result['value'] = device.getFeedback(u6.Timer0())[0]
except:
# Error handling ....
Thanks,
Colin
1. If you configure a timer, it will remain active until you disable the timers or power cycle (USB disconnect/reconnect) the U6. So if the timer is already configured from a previous session, you can just do the "d.getFeedback( u6.Timer0() )" call and read the current count.
You can configure timers and counters to be enabled when the U6 powers up, so your application will only read the timer value. In LJControlPanel, use the IO Defaults Panel to configure Timer/Counter power up defaults, and power cycle your U6 for the settings to take effect. In your application don't configure timers/counters and only read the timer value.
2. The firmware counters (timer) are firmware based, where there is a firmware jump to an interrupt service routine on each edge. The maximum total timer edges that can be processed is 30,000 per second. Counters are dedicated hardware counters, and can handle a frequency up to 8 MHz.