> For the complete documentation index, see [llms.txt](https://help.qtech.co.nz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.qtech.co.nz/datran/datran-vi-scada/datran-dlp-ide/troubleshooting/pulse-counts-wrong.md).

# Pulse counts or midnight resets are wrong

A pulse total is too low, or a daily total resets at the wrong time.

## The pulse total is too low

The simple approach relies on detecting digital pulse edges and comparing them to the state of the previous value. This approach is acceptable if the duration of each pulse will always be greater than the DLP execution cycle rate. The default execution time will be 500mS. However, if any pulses are shorter than the DLP execution time this approach will not be reliable. Pulses could occur in the time between DLP cycles, and as a result would not be sampled.

**The most robust method for pulse accumulation is to access the Q03 hardware pulse accumulators via the DLP, enabling reliable sampling of signals up to 40Hz.**

1. To enable PANL counting on a particular digital input, set the associated `PDIG` register to True during the PROGINIT section of the DLP, for example `INITDIG PDIG8, TRUE` for input 8.
2. Add pulses that occurred since the last DLP cycle to the running total: copy any new pulses from the `PANL` register to the temp register, add these to the accumulator, and copy the result back to the total. The `PANL` register contains the number of pulses that have occurred since the last time the register was read.

For the full example, see [Count pulses with the pulse counters](https://help.qtech.co.nz/datran/datran-vi-scada/datran-dlp-ide/dlp-self-help-course/module-05-pulse-counting.md#step-2-count-pulses-with-the-pulse-counters).

This technique can be used for RDIN 1-8 on an eXcel RTU and RDIN 1-24 on a QRTU only. It can be utilized for inputs of an expansion module if the correct firmware is used. The firmware must be the following and above: Q03 Rev 5.10, Q25 Rev 4.10 and Q26 Rev 1.10. On the XL4 Plus, shorter pulses can be detected by setting a digital input to pulse counting mode. The minimum pulse width in this mode is 20ms. This feature is configured in QTech Workbench: see [Digital input modes](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/configure.md#digital-input-modes).

## The total goes past 65535

Once you have created your pulse counters and have them working properly you will find that you will need to reset them periodically, if not the total count will most likely exceed the maximum number the DLP can deal with (65535) in a matter of days. Most often the reset of pulse counters occurs at midnight each day, or at midnight of a certain day every week, or at midnight on the first day of a month. See [Reset a total at midnight](https://help.qtech.co.nz/datran/datran-vi-scada/datran-dlp-ide/dlp-self-help-course/module-05-pulse-counting.md#step-3-reset-a-total-at-midnight).

## The midnight reset happens at the wrong time

On the XL4 Plus, for firmware version 7.07 and earlier the time is in UTC. This is 12 hours behind NZST. It does not change with daylight saving. This means if you use `CKDOW` or similar to flag a midnight reset you will need to apply a 12-hour offset in your DLP. Due to requests, firmware version 7.08 and later all use local time as determined by DATRAN. See [Port an XL4 site to the XL4 Plus](https://help.qtech.co.nz/datran/datran-telemetry/datran-xl4-plus-rtu/upgrade-xl4-to-xl4-plus/port-xl4-site.md#dlp-changes).

In the DLP IDE, **Synchronize RTC** synchronizes the attached module's real time clock (RTC) to this computer's time and date.

## The last pulses of the day are missing

Because the midnight reset happens without any need to communicate with the base station, it is possible to miss the last few pulses of each day if only the "Total Today" is being reported. To get around this it is quite common to also include a "Total Yesterday" value, as shown in the Module 05 example.

## Still not working? Contact QTech

Email <techsupport@qtech.co.nz> with the RTU's model and firmware, the input, the totals you expected and saw, and the DLP file.
