Hi
I recently get the T7, which I will be using to acquire data from different sensors running a Python script. How can I create a counter to read the pulses of an incremental encoder? The encoder I'm using sends 1024 pulses per revolution. I try it with a Raspberry Pi using "GPIO.event_detected(chA)" command and it is working find. I'm wondering if there is a similar command to use with ljm. It will be great if an example is available.
Sounds like you want to use a basic counter:
https://labjack.com/support/datasheets/t7/digital-io/extended-features
For example, say you want to use FIO0 as an interrupt counter:
https://labjack.com/support/datasheets/t7/digital-io/extended-features/i...
First write the following to configure the counter:
DIO0_EF_INDEX = 8
DIO0_EF_ENABLE = 1
An easy way to try that is using the Register Matrix in Kipling. Add
those 2 registers to the active list so you can write to them, and
also add DIO0_EF_READ_A so you can see the current count.
To test, connect one end of a jumper wire to GND and touch the other
end inside the FIO0 terminal. DIO0_EF_READ_A should increment by 1 or
more counts each time.
Thank you for the reply. I was able to test it with the Register Matrix and then I wrote a small code in python (see attachment). What I am not getting is how to interpret the value on DIO0_EF_READ_A. You said that it "should increment by 1 or more counts each time", what does it mean? This is the output I am reading:
FIO2 state : 1.000000 DIO2_EF_READ_A state : 24.000000
FIO2 state : 0.000000 DIO2_EF_READ_A state : 32.000000
FIO2 state : 1.000000 DIO2_EF_READ_A state : 33.000000
FIO2 state : 0.000000 DIO2_EF_READ_A state : 45.000000
FIO2 state : 1.000000 DIO2_EF_READ_A state : 46.000000
FIO2 state : 0.000000 DIO2_EF_READ_A state : 55.000000
FIO2 state : 1.000000 DIO2_EF_READ_A state : 56.000000
FIO2 state : 0.000000 DIO2_EF_READ_A state : 63.000000
Thanks!
The interrupt counter counts the rising edges of pulses on a digital line. DIO2_EF_READ_A reads the current count of pulses from the FIO2 interrupt counter. So your first call reads 24 pulses total have been counted, second is 32 pulses total and so on.
To add, "should increment by 1 or more counts each time" means you should see the pulse counts increments per DIO#_EF_READ_A call.
Thank you for the answer. I had some troubles because I was using a simple switch to send the pulses manually. For some reason the pulses I was reading did not match to the pulses I was sending.
Now I assembled the encoder to a stepper motor, and for each turn I am able to read the pulses accurately. Thanks!
Perhaps you are wondering why we said "1 or more" counts per wire touch rather than "1" count per wire touch? The reason is that the counters are very fast and detect all the edges from the wire bouncing and your hand wiggling. Similary, if you tested with a mechanical switch of some sort they usually bounce and also create more than 1 edge per close/open.
https://labjack.com/support/datasheets/t7/digital-io/extended-features/i...