Go to Triangle Digital Support Home Page TDS2020F TECHNICAL MANUAL
Hardware support
Timekeeping
Live website search
Enter key words
 

TIMEKEEPING

DEFINITIONS

(DATE)

( n1 - a n2 )

Day number to printable date string, format 25.12.01; as 12.25.01 after USA

(TIME)

( d - a n )

Ticks to printable time string. Each tick 53.333ms or 1 sec

+TIMER

( - )

Enable timer 3 overflow interrupt

-TIMER

( - )

Disable timer 3 overflow interrupt

.DATE

( - )

Print current date in format 25.12.01; as 12.25.01 after USA

.TIME

( - )

Print current time in format 17.09.55

>DMY

( n - day,mth,yr)

Day number to date

>SMH

( d - sec,min,hr)

Ticks into normal units

@DATE

( - n )

Date in days since 1.01.84

@TIME

( - d )

Ticks into the day; double word

DAYS

( - a )

Variable containing day number since 1.01.84

DELAY

( d - )

(#TIMING.TDS) Delay by 32-bit number d units. One unit =  814ns. (real time)

DMY

( d - n )

Date formatted as 25.12.01 to day number; as 12.25.01 after USA

DMY>

( day,mth,yr - n)

Normal units to day number

HRS

( d - )

Set time from double no, format 17.09.30

MINS

( - a )

Variable containing minutes into the day

MS

( u - )

Delay by 0 to 65535 ms (software loop)-about twice the time with TDS2020DV in place)

MS

( u - )

(#TIMING.TDS) Delay by 1 to 65535 ms (real time)

NOW

( d - )

Set date from double no, format 25.12.01; as 12.25.01 after USA

REAL

( - t )

(#TIMING.TDS) Returns real time as 48-bit 2's complement number repeating every 7 years

REST

( u - )

Delay by 1 to 65535 units. One unit approx 0.8s (2.0s with TDS2020DV in place)

SECONDS

( n - )

NMI will occur after n seconds. n=1 to 99

SMH>

( sec,min,hr - d)

Converts normal units to ticks

TICKS

( - a )

Variable containing parts of a minute (1125 ticks per minute)

TIME&DATE

( - sec,min,hr,

Returns all six values

 

day,mth,yr )

 

USA

( - )

Alters DMY NOW (DATE) .DATE to USA format

W!

( - )

Set PCF8583 chip from on card time system

W@

( - )

Set on-card time system from PCF8583 chip

WAIT

( u - )

Delay by 1 to 65535 units. One unit approx. 26s (54s with TDS2020DV in place)

FILES

#TIMEEUR.TDS

]

Keep TDS2020F in synchronism with national time

#TIMEUK.TDS

]

standards by telephone or radio transmissions.

#TIMEUSA.TDS

]

 

#DIARY.TDS

 

Day-of-week, day-of-year and week number diary calculations.

#TONES.TDS

 

Gives three independent tones generated under interrupt.

HOW TO USE DATE & TIME

There are two timekeeping mechanisms on TDS2020F:

 

CHIP CLOCK:

PCF8583 clock chip on the I2C bus maintained by a battery on the TDS2020BYN (piggyback) or TDS2020BYD (separate) battery board or external battery.

BOARD CLOCK:

Operates entirely by software. Does not work when the power is off or in standby.

 

In an application needing non-volatile date and time use the words NOW and HRS to set the current date and time in the board clock, then use W! to transfer a copy to the chip clock. For example at 9pm on Christmas Day evening:

 

25.12.01 NOW 21.00.00 HRS W!

 

If you now switch off, the board clock will be lost but a battery connected to pin VBATT (z3) will maintain the chip clock. When you power up again the board clock will have the default date and time of 1.01.84 and 00.00.00. Use W@ to set the board clock from the chip clock. The board clock can be seen most easily with .DATE and .TIME which display via the serial port to your terminal (unless EMIT is redirected).

The reason for this scheme is to avoid delay in obtaining time. Using the board clock an application can tell the current moment to the nearest microsecond.

To keep the clocks in synchronism we suggest that an application uses W@ at regular intervals (say once per hour or day) at a moment its execution time of about 4.2ms will not be important (7.4ms when using the TDS2020DV development board).

USA-STYLE DATES

Execute USA before any use of dates to change the format manipulated by DMY NOW (DATE) and .DATE . The above example becomes:

 

12.25.01 NOW 21.00.00 HRS W!

 

and when the date is retrieved with .DATE the response is 12.25.01.

NON-VOLATILE CLOCK & RAM

The PCF8583 clock chip has 8 clock bytes, 8 alarm bytes and 240 bytes of RAM. Connection of the TDS2020BYN, TDS2020BYD or other battery will make it non-volatile (consumption typically 3.5A including a 128k bytes RAM). The TDS2020F contains circuitry to avoid corruption while the power is going up or down. The system does not make any use of the PCF8583 internal addresses $11 to $FF inclusive, these 239 bytes are available to you as non-volatile RAM. For more accurate timekeeping trim the adjacent capacitor (it is not adjusted before despatch). Set the 1Hz clock output on the NMI pin (a26) to be as accurate as possible using a precision period meter as a reference.

W! and W@ provide the only access you are ever likely to need to the clock registers and STANDBY SUSPEND ADJOURN allow use of the alarm bytes (see LOW POWER OPERATION, page 89).

For details of the PCF8583 chip's registers or the extra RAM it contains see I2C BUS, page 118, and PCF8583 CLOCK CHIP, page 328.

BOARD CLOCK

The raw data which the Forth words use are in the 3 variables TICKS MINS DAYS . These can be accessed directly to give special functions.

The clock works using the Timer 3 Overflow Interrupt. Every 53.333ms this interrupt increments the ticks register, and each minute resets it and increments the minutes register. Once per day the minutes register is reset and the day register is incremented. Most time and date words work with these three variables. The interrupt is written in machine code and takes less than 0.1% of the processor time. Although timer 3 is used for this purpose it is also essentially free for most other purposes concurrently, for example both output captures and the input capture are unused by the timekeeping function.

Some applications need exact one second (or multiple) timing. If bit 1 of address hex FD05 is set and Timer 3 Overflow Interrupt is disabled by -TIMER the system keeps the board clock using the Non Masked Interrupt of the chip clock. The variable TICKS now contains seconds instead of 53.333ms increments. E.g.

 

-TIMER $FD05 1 ONE

 

Real time down to the nearest microsecond is available from the board clock. Provided it is not in the seconds mode as described above, read 16 bits from address FFB2 (the free running timer 3) to get fractions of one 'tick'. Every count represents 813.8ns. For example the following gets a 32-bit double number to the stack-it repeats only every minute:

 

-TIMER $FFB2 @ TICKS @ +TIMER

 

The word REAL in file #TIMING.TDS uses this principle to give a 48-bit real time, with a resolution of 813.8ns. It repeats only every 7 years.

Note how timer interrupts should be turned off while reading the registers to avoid spurious results, but no time will be lost provided they are re-enabled within 53.3ms.

DELAYS

At the top of this section there are many words to give delays in programs. Some come from the file #TIMING.TDS. Those marked 'real time' use the timers, use these alternatives where accurate timing is needed.

The words REST WAIT and the default version of MS are based on software loops. Those times shown refer to use with the Forth in the microprocessor. They are longer when the TDS2020DV board is present. When interrupts or multitasking have been added they may be slower and indeterminate in duration.

You can also use the Chip Clock to create delays, see LOW POWER OPERATION, page 89 to see how to create an NMI after a time up to a year.

MAKE MUSIC

Library routine #TONES.TDS gives three independent tones generated under interrupt. The program can change the three pitches while it is running. Use it to give user-feedback as jingles, chords, music or sound effects.

 

Go to Triangle Digital Support Home Page Go to top   Next page