Skip to main content
Skip table of contents

2.9 - Timers/Counters [U6 Datasheet]

The U6 has 4 timers (Timer0-Timer3) and 2 counters (Counter0-Counter1). See our Configuration and Timers & Counters pseudocode pages for programming guidance.

Subsections

When any of these timers or counters are enabled, they take over an FIO/EIO line in sequence (Timer0, Timer1, Timer2, Timer3, Counter0, then Counter1), starting with FIO0+TimerCounterPinOffset. The valid range for TimerCounterPinOffset is 0-8, so Timer0 can appear on FIO0-EIO0, and the highest I/O ever used would be EIO5 for Counter1 if all 4 timers and both counters are enabled. Some examples:

1 Timer enabled, Counter0 disabled, Counter1 disabled, and TimerCounterPinOffset=0:
FIO0=Timer0

1 Timer enabled, Counter0 disabled, Counter1 enabled, and TimerCounterPinOffset=0:
FIO0=Timer0
FIO1=Counter1

2 Timers enabled, Counter0 enabled, Counter1 enabled, and TimerCounterPinOffset=8:
EIO0=Timer0
EIO1=Timer1
EIO2=Counter0
EIO3=Counter1

Timers and counters can appear on various pins, but other I/O lines never move. For example, Timer1 can appear anywhere from FIO1 to EIO1, depending on TimerCounterPinOffset. On the other hand, FIO2 (for example), is always on the screw terminal labeled FIO2.

Applicable digital I/O are automatically configured as input or output as needed when timers and counters are enabled, and stay that way when the timers/counters are disabled.

Timers and counters use digital I/O hardware so the digital I/O specs from Appendix A apply.  An input recognizes 0.0-0.8V as low and 2.0-5.8V as high, so rising and falling edges must transition between those levels.  For more information about signal connections see Section 2.8.1.

There are special channels numbers that can be used to read timer and counter values.  These channel numbers can be used most places where you would use analog input channel numbers, such as LJLogUD and LJStreamUD.  See Section 3.2.1 for more information.

Timers

The timers (Timer0-Timer3) have various modes available.  These are listed in the following table and more details can be found in Section 2.9.1.

Table 2.9-1. U6 Timer modes

Index (Low-level & UD) 

0

16-bit PWM output

1

8-bit PWM output

2

Period input (32-bit, rising edges)

3

Period input (32-bit, falling edges)

4

Duty cycle input

5

Firmware counter input

6

Firmware counter input (with debounce)

7

Frequency output

8

Quadrature input

9

Timer stop input (odd timers only)

10

System timer low read (Default mode)

11

System timer high read

12

Period input (16-bit, rising edges)

13

Period input (16-bit, falling edges)

14

Line-to-Line input

All timers use the same timer clock. There are 7 choices for the timer base clock:

Table 2.9-2. U6 Timer clock base options

Index (Low-level/UD) 

0/20

4 MHz

1/21

12 MHz

2/22

48 MHz (Default)

3/23

1 MHz /Divisor

4/24

4 MHz /Divisor

5/25

12 MHz /Divisor

6/26

48 MHz /Divisor

The first 3 clocks have a fixed frequency, and are not affected by TimerClockDivisor. The frequency of the last 4 clocks can be further adjusted by TimerClockDivisor, but when using these clocks Counter0 is not available. When Counter0 is not available, it does not use an external FIO/EIO pin. The divisor has a range of 0-255, where 0 corresponds to a division of 256.

Counters

Each counter (Counter0 or Counter1) consists of a 32-bit register that accumulates the number of falling edges detected on the external pin. If a counter is reset and read in the same function call, the read returns the value just before the reset.

Note that Counter0 is not available with certain timer clock base frequencies. In such a case, it does not use an external FIO/EIO pin. An error will result if an attempt is made to enable Counter0 when one of these frequencies is configured. Similarly, an error will result if an attempt is made to configure one of these frequencies when Counter0 is enabled.

Usage

Usage for all timers & counters is pretty much the same.  First you configure, then you read and/or write.  The effect of the parameters can vary depending on timer mode, so see the timer mode descriptions for more details.

Test using the Test panel in LJControlPanel

Before attempting to use LJLogUD or your own software, first test in LJControlPanel as described in our configuring counters and configuring timers tutorials and confirm the results are as expected.

Configure

To configure counters, write to the following:
CounterEnable
TimerCounterPinOffset

To configure timers, write to the following:
NumberTimersEnabled
TimerClockBase
TimerClockDivisor
TimerCounterPinOffset
TimerValue
TimerMode

There are 2 basic ways to configure:

1. Configure the power-up defaults of device as desired, then power cycle the device.  On Windows this can be done using the Config Defaults screen in LJControlPanel.

2. Configure at the start of your program.  For the Windows UD library see our Timer and Counter and Easy Function pseudocode.  Find any timer example for your programming language and it should demonstrate writes to the above parameters.

Read & Write

Depending on the timer/counter, you might want to do reads of TimerValue or do updates of TimerValue.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.