Datasheet
PIC16HV540
DS40197B-page 28 Preliminary 2000 Microchip Technology Inc.
6.2 Prescaler
An 8-bit counter is available as a prescaler for the
Timer0 module, or as a postscaler for the Watchdog
Timer (WDT) (WDT postscaler not implemented on
PIC16C52), respectively (Section 6.1.2). For simplicity,
this counter is being referred to as “prescaler” through-
out this data sheet. Note that the prescaler may be
used by either the Timer0 module or the WDT, but not
both. Thus, a prescaler assignment for the Timer0
module means that there is no prescaler for the WDT,
and vice-versa.
The PSA and PS2:PS0 bits (OPTION<3:0>) determine
prescaler assignment and prescale ratio.
When assigned to the Timer0 module, all instructions
writing to the TMR0 register (e.g., CLRF 1,
MOVWF 1, BSF 1,x, etc.) will clear the prescaler.
When assigned to WDT, a CLRWDT instruction will clear
the prescaler along with the WDT. The prescaler is nei-
ther readable nor writable. On a RESET, the prescaler
contains all '0's.
6.2.1 SWITCHING PRESCALER ASSIGNMENT
The prescaler assignment is fully under software con-
trol (i.e., it can be changed “on the fly” during program
execution). To avoid an unintended device RESET, the
following instruction sequence (Example 6-1) must be
executed when changing the prescaler assignment
from Timer0 to the WDT.
EXAMPLE 6-1: CHANGING PRESCALER
(TIMER0
→WDT)
1. CLRWDT ;Clear WDT
2. CLRF TMR0 ;Clear TMR0 & Prescaler
3. MOVLW '00xx1111’b ;These 3 lines (5, 6, 7)
4. OPTION ; are required only if
; desired
5. CLRWDT ;PS<2:0> are 000 or 001
6. MOVLW '00xx1xxx’b ;Set Postscaler to
7. OPTION ; desired WDT rate
To change prescaler from the WDT to the Timer0 mod-
ule, use the sequence shown in Example 6-2. This
sequence must be used even if the WDT is disabled. A
CLRWDT instruction should be executed before switch-
ing the prescaler.
EXAMPLE 6-2: CHANGING PRESCALER
(WDT
→TIMER0)
CLRWDT ;Clear WDT and
;prescaler
MOVLW ’xxxx0xxx’ ;Select TMR0, new
;prescale value and
;clock source
OPTION
6.3 Programmable Clock Generator
When the PIC16HV540 is programmed to operate in
the RC oscillator mode, the CLKOUT pin is connected
to the compliment state of TMR0<0>. Use of the pres-
caler rate select bits PSA:PS0 in the OPTION register
will provide for frequencies of CLKIN/8 to CLKIN/1024
on the CLKOUT pin.
EXAMPLE 6-3:
In addition to this mode of operation, TMR0<0> can be
toggled via the bcf and bsf bit type instructions. For this
mode, the T0CS bit in the OPTION register must be set
to 1. This setting configures TMR0 to increment on the
T0CKI pin. To set the CLKOUT pin high, a bcf TMR0,0
instruction is used and to set the CLKOUT pin low, the
bsf TMR0,0 instruction is used. The T0CKI pin should
be pulled high or low to prevent false state changes on
the CLKOUT pin.
Fosc
PRESCALER SETTING/CLKOUT FREQUENCY
CLKIN/1024 CLKIN/8
1Mhz 976 Hz 125 kHz
2Mhz 1953 Hz 250 kHz
3Mhz 2930 Hz 375 kHz
4Mhz 3906 Hz 500 kHz