3 setting the timer, Nxp semiconductors – NXP Semiconductors UM10301 PCF2123 User Manual
Page 29
NXP Semiconductors
UM10301
User Manual PCF85x3, PCA8565 and PCF2123, PCA2125
UM10301_1
© NXP B.V. 2008. All rights reserved.
User manual
Rev. 01 — 23 December 2008
29 of 52
12.3 Setting the timer
The internal timer is an 8-bit countdown timer which is controlled by the timer control
register. The timer counts down from a software-loaded 8-bit binary value. It can be
clocked by four different source clock frequencies: 4096 Hz, 64 Hz, 1 Hz or 1/60 Hz.
This example for the PCF8563 generates an interrupt after 10 ms:
• Clock to be used 4096 Hz;
• Number of clock pulses needed = 0.01 x 4096 = 40;
• Error = 40 / 4096 Hz – 0.01 = -234 μs;
• Length of I
2
C-bus initialization: 3 start conditions, 3 pulses each + 9 bytes, 9 pulses
each = 90 clocks @ 400 kHz = 225
μs. Creating the clock asynchronously also gives
an error of up to 1 clock pulse (see Chapter 17 “First period inaccuracy when using
the timer”.). The interrupt will generate an output pulse after 9.991 ms or if the
counter is set to 41 the interrupt will start after 10.236 ms.
• The timer is started by the acknowledge of the start timer instruction.
Table 7.
Setting the timer
Sequence of commands / data to be sent
Binary (BCD)
HEX
Register
Address
Comments
generate
I
2
C start condition
1 0 1 0 0 0 1 0
A2
I
2
C slave address, write
0 0 0 0 0 0 0 1
01
word address 1 (control/status register 2)
0 0 0 0 0 0 0 1
01
01
clear all flags, enable timer interrupt
generate
I
2
C start condition (repeated start)
1 0 1 0 0 0 1 0
A2
I
2
C slave address, write
0 0 0 0 1 1 1 1
0F
Word address 0F
HEX
for timer value
0 0 1 0 1 0 0 0
28
0F
Timer value set to 40, 28
HEX
generate
I
2
C start condition (repeated start)
1 0 1 0 0 0 1 0
A2
I
2
C slave address, write
0 0 0 0 1 1 1 0
0E
word address OE for timer control byte
1 0 0 0 0 0 0 0
80
0E
Select clock frequency 4096 Hz and start timer
generate
I
2
C stop condition
Refer to chapter 17 “First period inaccuracy when using the timer” for further details on
timer operation.