Hourly pulse counter

I have a variable stream of pulses at an input which I accumulate into a totalizer.

I want to add another counter to record the number of pulses every clock hour - eg from 10am until 11am. I will get a series of counts, each for a different clock-hour, replaced an hour later by a new count - and so on for ever.

This data will be transferred to another system within the hour so I can just re-use the same counter variable - but I have to reset the variable to zero every clock hour. I cannot figure out how to do that.

If I use INTERVAL = 1hour to drive the reset, it will not be synchronized with clock hours. The reset will be every hour after the program last started

Is there is a way of combining INTERVAL and TIME/DOW to achieve synchronization?

Can I use a wild-card - eg TIME = *:00:00 ??

With a bit of prompting I got gemini to produce this. I havent tested it yet but this is the general idea. It takes advantage of the MINUTE and HOUR functions which I believe return the minutes and hours of the day.

10 REM =================================================
20 REM VAR1: ACCUM (HOURLY BUCKET)
30 REM VAR2: HOURLY_EXPORT (LAST HOUR TOTAL)
40 REM VAR3: DAILY_ACCUM (DAILY BUCKET)
50 REM VAR4: DAILY_EXPORT (LAST DAY TOTAL)
60 REM VAR5: NEWHOUR (HOUR FLAG)
70 REM VAR6: MIDNIGHT (DAY FLAG)
80 REM IN1: PULSE_INPUT
90 REM =================================================
100 REM
110 REM 1. SOFTWARE ACCUMULATION
120 IF+ IN1 THEN ACCUM = ACCUM + 1
130 REM
140 REM 2. DEFINE THE TRIGGER FLAGS
150 IF+ MINUTE = 0 THEN NEWHOUR = 1
160 IF+ HOUR = 0 THEN MIDNIGHT = 1
170 REM
180 REM 3. HOURLY DATA HANDOFF
190 IF NEWHOUR THEN HOURLY_EXPORT = ACCUM
200 IF NEWHOUR THEN DAILY_ACCUM = DAILY_ACCUM + ACCUM
210 REM
220 REM 4. DAILY DATA HANDOFF
230 IF MIDNIGHT THEN DAILY_EXPORT = DAILY_ACCUM
240 IF MIDNIGHT THEN DAILY_ACCUM = 0
250 REM
260 REM 5. HOURLY RESET
270 IF NEWHOUR THEN ACCUM = 0
280 REM
290 REM 6. CLEAR FLAGS (LAST LINES)
300 NEWHOUR = 0
310 MIDNIGHT = 0

Thank you - I will review and apply

I can find no mention of the HOUR and MINUTE “functions” in any documentation, online-Help, or forum. I guess there may also be DAY, MONTH, and YEAR functions??

Clearly these are useful. Can I suggest a Forum post (at minimum) to make people aware of these - and their required syntax.

I carried out some simple tests with the MINUTE function

10 IF+ MINUTE = 30 THEN DEBUG1 = 1
20 DEBUG2 = MINUTE

In line 10,

  • 30 minutes was just a (random) time soon after the program started.
  • Units/Range for DEBUG1 = Off/On

In line 20 I did not know what units/range to set for DEBUG2 ?? I tried 55 “counts”

None of these lines “worked”.
DEBUG1 remained Off as the laptop clock changed from 28, 29, 30, 31 minutes past the hour
DEBUG2 remained 0.000

What to try next?

1 Like

The interpreter accepted the MINUTE command, that’s good news. We must get these commands documented. TIME returns the number of seconds since midnight so through some gyrations we can get the hours and minutes flags working. I am not in the office so havent tested this:

10 REM Get total hours to isolate the remainder
20 HOURS = INT ( TIME / 3600 )
30 HR_IN_SEC = HOURS * 3600
40 REM Get seconds since the top of the hour
50 SEC_PAST_HR = TIME - HR_IN_SEC
60 REM Divide by 60 to get the current minute (0-59)
70 CURRENT_MIN = INT ( SEC_PAST_HR / 60 )

80 REM Now your logic will work:
90 IF+ CURRENT_MIN = 30 THEN DEBUG1 = 1
100 DEBUG2 = CURRENT_MIN

Does your second block of code mean the the first block doesn’t work (eg HOUR and MINUTE functions dont work as you said) or is this an alternative way to achieve a similar result?

According to the TIME function description, TIME = Hours x 100 + Minutes + secs/100. ie at time 14:30:30, TIME = 1430.30 If the description of TIME function is correct, I think your line 20 should be:
20 HOURS = INT ( TIME / 100 ) not = INT ( TIME / 3600 )

I dont understand is what units to define to get the 1430.3 format

Setting of units seems critical. How do I set units for ANY variable to show just a number - as in 1430.3? The best available option seems to be 55 “count” but this does not give the format for TIME described in the definition. I defined custom units = 68 “number”

I set up the following test code just now:

10 VAR1 = TIME (VAR1 units = 50 time) result 21:03:45 (actual time - ok)
20 VAR2 = TIME (VAR2 units = 55 counts) result 75825.000 = 21h, 3m, 45s in secs
30 VAR3 = TIME (VAR3 units = 48 hours, 47 minutes, 68 number) result 75825.000
40 VAR4 = TIME / 100 (VAR4 units = 47, 48, 68) result 758.250

I cannot find any “units” setting that displays the “correct” value of 2103.45.
I will try to work with the “total seconds” value which I can get.

This experiment suggests that the format described under TIME function (ie 1430.3) does not exist. Rather, when expressed as a number, TIME returns the number of seconds elapsed in the current day. From that, MINUTE and HOUR can be easily calculated as in your examples.

A general question - what “units” to use for a dimensionless number, eg result of an arithmetic calculation, which has no physical dimensions such as kg, degC??

I think there is a solution which is simpler than we’re making it out to be here. I will spend time on it when the team gets back to work on Feb25.

In general, you can do math on time pretty easy:
IF TIME-ON( OUT1 ) > 0:01:00 THEN DO SOMETHING.

We need an easy way to trigger on the hour, will work on that next. And document the HOUR and MINUTES commands.