0% found this document useful (0 votes)
102 views40 pages

8-, 16-, 24-And 32-Bit Timers: CY8C29/27/24/22xxx Data Sheet

progam

Uploaded by

thanggimme.phan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views40 pages

8-, 16-, 24-And 32-Bit Timers: CY8C29/27/24/22xxx Data Sheet

progam

Uploaded by

thanggimme.phan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

53.

General Purpose Timers

8-, 16-, 24- and 32-bit Timers


Timer v2.3
Copyright © 2000-2003. Cypress MicroSystems, Inc. All Rights Reserved.

CY8C29/27/24/22xxx Data Sheet


PSoC™ Blocks API Memory (Bytes) Pins (per
Resources Digital Analog CT Analog SC Flash RAM External I/O)
CY8C29/27/24/22xxx
8-bit 1 0 0 70 0 1
16-bit 2 0 0 93 0 1
24-bit 3 0 0 141 0 1
32-bit 4 0 0 158 0 1
CY8C26/25xxx
8-bit 1 0 0 106 0 1
16-bit 2 0 0 142 0 1
24-bit 3 0 0 200 0 1
32-bit 4 0 0 226 0 1

Features and Overview


• 8-, 16-, 24- or 32-bit general purpose timer uses one, two, three or four PSoC blocks, respectively
• Source clock rates up to 48 MHz
• Automatic reload of period on terminal count
• Capture for clocks up to 24 MHz.
• Terminal count output pulse may be used as input clock for other analog and digital functions
• Interrupt option on terminal count, capture, or when counter reaches a preset value
The 8-, 16-, 24- and 32-bit Timer User Modules provide down counters with programmable period and
capture ability. The clock and enable signals can be selected from any system time base or external
source. Once started, the timer operates continuously and reloads its internal value from the period
register upon reaching terminal count. The output pulses high in the clock cycle following terminal count.
Events can capture the current Timer count value by asserting the edge-sensitive capture input signal.
Each clock cycle, the Timer tests the count against the value of the compare register for either a “Less
Than” or “Less Than or Equal To” condition. Interrupts may be generated based on terminal count and
compare signals. The CY8C29/27/24/22xxx device families offer two additional features. The interrupt
options include “interrupt on capture” and, in addition, the compare signal may be routed onto the row
busses.

September 7, 2004 1
User Module Data Sheet

Period Down Compare


Register Counter Register
n
2:1 Interrupt
Data n
Compare
n Comparator Out
Capture 16:1 Capture Count
4
1:4 Row Bus
Clock 15:1

Load TC 1:4
Terminal
Count Out

CY8C29/27/24/22xxx Timer Block Diagram, Data Path width n = 8, 16, 24 or 32

Functional Description
The Timer User Module employs from one to four digital PSoC blocks, each contributing 8 bits to the total
resolution. To form timers that exceed 8 bits, consecutive blocks are linked so their internal carry, terminal
count and compare signals are synchronously chained. This concatenates the 8-bit Count, Period and
Compare registers (Data registers DR0, DR1 and DR2, respectively) from block to block to provide the
required resolution. In this way, Timers wider than 8 bits operate as a single monolithic synchronous timer.
The Timer API provides functions callable from C and assembly to stop and start operation of the Timer
and to read and write the various data registers. A Control register starts and stops the Timer User
Module. Writing the Period register, while the Timer is stopped, causes the Period register value to be
copied into the Count register. While the Timer is stopped, the output is asserted low.
When a Timer is started, the Count register is decremented by 1 on each rising edge of the clock. On the
rising clock edge following the zero count, the Count register is reloaded from the Period register. On the
next falling edge, the terminal count event is triggered and the output is asserted high for one-half clock
cycle or, optionally, in the CY8C29/27/24/22xxx device families, for one full clock cycle. In this way, the
Timer acts as a clock divider. Its period and frequency are related to the period and frequency of the
source clock by a factor equal to the value of the Timer’s Period register plus 1.
OutputPeriod = SourceClockPeriod × ( PeriodRegisterValue + 1 ) Equation 1

A period value of zero will output the input source clock shifted by one-half clock cycle, producing a divide-
by-one clock. In the CY8C29/27/24/22xxx device families, the terminal count pulse width must be set to
one-half cycle.
The duty cycle of the terminal count output is as follows.
0.5
DutyCycle = ------------------------------------------- Equation 2
PeriodValue + 1

Alternatively, when the terminal count pulse width is set to a full cycle, the duty cycle will be twice as long.
1
DutyCycle = ------------------------------------------- Equation 3
PeriodValue + 1

The Period register value is a parameter that may be assigned using the Device Editor. In addition, it can
be modified at run-time using the API. The Period register will be copied into the Count register
automatically in the cycle after the value of the Count register reaches zero (terminal count). Thus, if the

2 September 7, 2004
General Purpose Timers

period is changed by means of the API, the new value does not take effect immediately. To make an
immediate change at run time, the correct procedure is to stop the Timer, write a new period value and
then restart the Timer.
On every input clock, the count in the Count register is compared to the value stored in the Compare
register. The comparison performs a "Less Than" or "Less Than or Equal To" test, according to an option
assigned to the CompareType parameter in the Device Editor. When the comparison condition is met, a
compare event is triggered on the next clock.
In the CY8C29/27/24/22xxx device families, the Timer User Module provides the Compare output signal
as an auxiliary output. This active-high signal is asserted on the rising edge of the clock cycle following the
cycle in which compare condition is satisfied. This auxiliary output cannot be directly connected to the
adjacent digital PSoC block; however, it can be connected to other digital PSoC blocks or to the GPIO pins
through the local row output busses.
When the capture input is asserted high, the transition is synchronized to the system clock and the value
in the Count register will be transferred to the Compare register.In the CY8C29/27/24/22xxx family, if the
interrupt type is set to “capture”, an interrupt will occur following the capture event. The Count value can
then be read using the ReadTimer API function.An interrupt will occur on a “compare true” event if the
following conditions are met.
1. In the CY8C29/27/24/22xxx family the interrupt type must be set to trigger on “capture”.
2. The Timer interrupt must be enabled
3. Global interrupts must be enabled
The elapsed time is computed as follows.
ElapsedTime = ClockPeriod × ( PeriodValue – CounterValue ) Equation 4

An interrupt can be enabled to trigger on either the terminal count or on compare events and, in the
CY8C29/27/24/22xxx family of PSoC devices, on the capture signal itself.In the CY8C29/27/24/22xxx, set
the interrupt to trigger on the capture event when using the external capture signal to perform event timing.
Set the interrupt to trigger on the terminal count, when performing elapsed timing measurements.
For algorithms that require reading the Timer countdown value on-the-fly without affecting the Count or
Compare registers, the ReadTimerSaveCV() API can be called. This function will read the Count register
value while preserving the Compare register contents. This function has some potential latency side
effects as noted in the API section of this user module.
The capture mechanism allows an external event to be timed with a limiting bound on the maximum time,
before an action should occur. This is performed as follows.
1. Set the Period register with a period value equal to the maximum value.
2. Set the Compare register with the maximum time limit count computed as follows.
MaxTimeLimit
MaxTimeLimitCount = PeriodValue – --------------------------------------- Equation 5
ClockPeriod

3. In the CY8C29/27/24/22xxx family set the interrupt to trigger on “capture”.


4. Start the timer when appropriate.
5. Read the Compare register when the interrupt is triggered.

Timing
External pins, routed to the counter by the global bus feature of the PSoC device, can clock the Timer. The
following figure illustrates the timing for the Timer User Modules.

September 7, 2004 3
User Module Data Sheet

Clock
Period Reg M
Capture Signal
CompareValue
N M-2
Reg
Start Bit

Capture Signal
Counter Load of Period
Counter Reg M M-1 M-2 N+1 N N-1 1 0 M M-1 M-2 N+1 N N-1 1 0 M M-1 M-2 M-3 M-4
Compare True Compare False Compare True
Compare Event
Terminal Count

Period = M+1
Duty Cycle = 0.5 / (M+1)
Terminal Count,
Output

Timing Diagram

AC Electrical Characteristics

Timer AC Electrical Characteristics

Parameter Typical Limit Units Conditions and Notes


Maximum input frequency -- 4812 MHz Vdd=5.0V2
Maximum output frequency -- 241 MHz Vdd=5.0V and 48 MHz input clock
-- 123 MHz Vdd=3.3V and 24 MHz input clock

Electrical Characteristics Notes


1. If the input or output is routed through the global buses, then the frequency is limited to a maximum of 12 MHz.
2. If the timer is used with an active capture function, then the input clock frequency limit is 24MHz.
3. Fastest clock available to PSoC blocks is 24 MHz at 3.3V operation.

Placement
The Timer consumes one digital PSoC block per 8 bits of resolution. When more than one block is
allocated, all will be placed consecutively by the Device Editor in order of increasing block number from
least-significant byte (LSB) to most significant (the MSB). Each block is given a symbolic name displayed
by the device editor during and after placement. The API qualifies all register names with user assigned
instance name and block name to provide direct access to the Timer registers through the API include
files. The block names used by the various widths are given in the following table.

Symbolic PSoC Block Names

PSoC Blocks 8-Bit Timer 16-Bit Timer 24-Bit Timer 32-Bit Timer
1 TIMER8 TIMER16_LSB TIMER24_LSB TIMER32_LSB
2 TIMER16_MSB TIMER24_ISB TIMER32_ISB1
3 TIMER24_MSB TIMER32_ISB2
4 -- -- -- TIMER32_MSB

4 September 7, 2004
General Purpose Timers

Parameters and Resources


Once a Timer User Module has been selected and placed using the Device Editor, values may be selected
and altered for the following parameters.

Clock
The Clock parameter is selected from one of 15 sources. These sources include the 48 MHz oscillator
(5.0V operation only), 24V1, 24V2, other PSoC blocks, and external inputs routed through global inputs
and outputs.

Capture
This parameter is selected from one of 16 sources. A rising edge on this input causes the Count register to
be transferred to the Compare register. The software capture mechanism will not operate correctly if this
parameter is set to a value of one or is held high externally.

TerminalCountOut
The terminal count output is an auxiliary Counter output. This parameter allows it to be disabled or
connected to any of the row output busses. This parameter appears only for members of the CY8C29/27/
24/22xxx family of PSoC devices.

CompareOut
The compare output may be disabled (without interfering with interrupt operations) or connected to any of
the row output busses. It is always available as an input to the next higher digital PSoC block and to the
analog column clock selection multiplexers, regardless of the setting of this parameter. This parameter
appears only for members of the CY8C29/27/24/22xxx family of PSoC devices.

Period
This parameter sets the period of the timer. Allowed values are between 0 and 232-1. This value is loaded
into the Period register. The period is automatically reloaded when the counter reaches zero or the timer is
enabled from the disabled state. This value may be modified using the API.

CompareValue
This parameter sets the count point in the timer period when a compare event is triggered. This value is
loaded into the Compare register. Allowed values are between zero and the period value. This value may
be modified using the API.

CompareType
This parameter sets the compare function type “less than” or “less than or equal” as described in the
functional description, above.

InterruptType
This parameter specifies whether the terminal count event or the compare event triggers the interrupt. The
interrupt is enabled using the API.

ClockSync
In the PSoC devices, digital blocks may provide clock sources in addition to the system clocks. Digital
clock sources may even be chained in ripple fashion. This introduces skew with respect to the system

September 7, 2004 5
User Module Data Sheet

clocks. These skews are more critical in the CY8C29/27/24/22xxx PSoC device families because of
various data-path optimizations, particularly those applied to the system busses. This parameter may be
used to control clock skew and ensure proper operation when reading and writing PSoC block register
values. Appropriate values for this parameter should be determined from the following table.

ClockSync Value Use


Sync to SysClk Use this setting for any 24 MHz (SysClk) derived clock source that is divided by two or more.
Examples include VC1, VC2, VC3 (when VC3 is driven by SysClk), 32KHz, and digital PSoC
blocks with SysClk-based sources. Externally generated clock sources should also use this
value to ensure that proper synchronization occurs.
Sync to SysClk*2 Use this setting for any 48 MHz (SysClk*2) based clock unless the resulting frequency is 48
MHz (in other words, when the product of all divisors is 1).
Use SysClk Direct Use when a 24 MHz (SysClk/1) clock is desired. This does not actually perform synchroniza-
tion but provides low-skew access to the system clock itself. If selected, this option overrides
the setting of the Clock parameter, above. It should always be used instead of VC1, VC2,
VC3 or digital Blocks where the net result of all dividers in combination produces a 24 MHz
output.
Unsynchronized Use when the 48 MHz (SysClk*2) input is selected.
Use when unsynchronized inputs are desired. In general this use is advisable only when
interrupt generation is the sole application of the Counter.

TC_PulseWidth
This parameter provides the means of specifying whether the terminal count output pulse is one clock
cycle wide or one half clock cycle wide.

Interrupt Generation Control


The following two parameters InterruptAPI and IntDispatchMode are only accessible by setting the Enable
Interrupt Generation Control check box in PSoC Designer. This is available under Project >> Settings... >>
Device Editor.

InterruptAPI
The InterruptAPI parameter allows conditional generation of a User Module’s interrupt handler and
interrupt vector table entry. Select “Enable” to generate the interrupt handler and interrupt vector table
entry. Select “Disable” to bypass the generation of the interupt handler and interrupt vector table entry.
Properly selecting whether an Interrupt API is to be generated is recommended particularly with projects
that have multiple overlays where a single block resource is used by the different overlays. By selecting
only Interrupt API generation when it is necessary the need to generate an interrupt dispatch code might
be eliminated, thereby reducing overhead.

IntDispatchMode
The IntDispatchMode parameter is used to specify how an interrupt request is handled for interrupts
shared by multiple user modules existing in the same block but in different overlays. Selecting
“ActiveStatus” causes firmware to test which overlay is active before servicing the shared interrupt
request. This test occurs every time the shared interrupt is requested. This adds latency and also
produces a nondeterministic procedure of servicing shared interrupt requests, but does not require any
RAM. Selecting “OffsetPreCalc” causes firmware to calculate the source of a shared interrupt request only
when an overlay is initially loaded. This calculation decreases interrupt latency and produces a
deterministic procedure for servicing shared interrupt requests, but at the expense of a byte of RAM.

6 September 7, 2004
General Purpose Timers

InvertEnable
This parameter determines the sense of the enable input signal. When “Normal” is selected, the enable
input is active-high. Selecting “Invert” causes the sense to be interpreted as active-low. InvertEnable
applies only to the CY8C29/27/24/22xxx family of PSoC devices.

Application Programming Interface


The Application Programming Interface (API) routines are provided as part of the user module to allow the
designer to deal with the module at a higher level. This section specifies the interface to each function
together with related constants provided by the “include” files.
Note In this, as in all user module APIs, the values of the A and X register may be altered by calling an
API function. It is the responsibility of the calling function to preserve the values of A and X prior to
the call if those values are required after the call. This “registers are volatile” policy was selected
for efficiency reasons and has been in force since version 1.0 of PSoC Designer. The C compiler
automatically takes care of this requirement. Assembly language programmers must ensure their
code observes the policy, too. Though some user module API function may leave A and X
unchanged, there is no guarantee they will do so in the future.

8-Bit Timer API


Application Programming Interface (API) routines are provided as part of the user module to allow the
designer to deal with the module at a higher level. The following are the API programming routines
provided for Timer8.

(CONSTANT) Timer8_PERIOD
Description:
Represents the value chosen for the Period field of the Timer8 in the Device Editor. The value can
have a range between 0 and 255.

(CONSTANT) Timer8_COMPARE_VALUE
Description:
Represents the value chose for the PulseWidth field of the Timer8 in the Device Editor. The value can
have a range between 0 and 255.

(FUNCTION) Timer8_EnableInt
Description:
Enables the interrupt mode operation. Note, however, that global interrupts must also be enabled
before interrupts will actually be serviced.
C Prototype:
void Timer8_EnableInt(void);
Assembly:
call Timer8_EnableInt
Parameters:
None
Return Value:
None

September 7, 2004 7
User Module Data Sheet

Side Effects:
This routine modifies the appropriate interrupt enable register in IO space. The A and X registers may
be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer8_DisableInt
Description:
Disables the interrupt mode operation.
C Prototype:
void Timer8_DisableInt(void);
Assembly:
call Timer8_DisableInt
Parameters:
None
Return Value:
None
Side Effects:
This routine modifies the appropriate interrupt enable register in IO space. The A and X registers may
be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer8_Start
Description:
Starts the Timer8 operation. The Count register will be decremented on the next clock cycle.
C Prototype:
void Timer8_Start(void);
Assembly:
call Timer8_Start
Parameters:
None
Return Value:
None
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer8_Stop
Description:
Stops the Timer8 operation.
C Prototype:
void Timer8_Stop(void);

8 September 7, 2004
General Purpose Timers

Assembly:
call Timer8_Stop
Parameters:
None
Return Value:
None
Side Effects:
The output will be set low and subsequent writes to the Period register will cause the Count register to
update with the new period value. The A and X registers may be modified by this or future implementa-
tions of this function. The same is true for all RAM page pointer registers in the Large Memory Model
(CY8C29xxx). When necessary, it is the calling function's responsibility to preserve the values across
calls to fastcall16 functions.

(FUNCTION) Timer8_WritePeriod
Description:
Writes the Period register with the period value. The period will be loaded into the Count register, when
the zero-count condition is reached or immediately if the Timer8 is currently stopped.
C Prototype:
void Timer8_WritePeriod(BYTE bPeriod);
Assembly:
mov A, [bPeriod]
call Timer8_WritePeriod
Parameters:
bPeriod: A value between 0 and 255, to set the Timer8 period. It is passed in the Accumulator.
Return Value:
None
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer8_WriteCompareValue
Description:
Modifies the value of the Timer’s Compare register. In order to avoid unexpected side effects, the
Timer should be disabled (not yet enabled via the Start API function or by first calling the Stop API
function).
C Prototype:
void Timer8_WriteCompareValue(BYTE bCompareValue);
Assembly:
mov A, [bCompareValue]
call Timer8_WriteCompareValue
Parameters:
bCompareValue: A value between 0 and 255, to set the Timer8 compare value. It is passed in the
Accumulator.
Return Value:
None

September 7, 2004 9
User Module Data Sheet

Side Effects:
If this function is called while the Timer is running and the compare value is equal to or greater than the
current value of the Count register, then a compare event can occur. This could cause an interrupt, if
both the interrupt type is set to trigger on the compare event and the Timer interrupt is enabled. The A
and X registers may be modified by this or future implementations of this function. The same is true for
all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the
calling function's responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer8_bReadCompareValue
Description:
Reads the Timer8 Compare register.
C Prototype:
BYTE Timer8_bReadCompareValue(void);
Assembly:
call Timer8_bReadCompareValue
mov [bCompareValue],A
Parameters:
None
Return Value:
The Compare register content is returned in the Accumulator.
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer8_bReadTimerSaveCV
Description:
Reads the current Timer8 Count register value, while preserving the Compare register. This performs
a software-solicited, hardware-synchronous counter capture operation. This function should only be
used if the contents of the Compare register must be preserved. If the Compare register contents do
not need to be preserved, then using the bReadTimer() function is preferred. Note that this API routine
used to be called bReadCounter.
C Prototype:
BYTE Timer8_bReadTimerSaveCV(void);
Assembly:
call Timer8_bReadTimerSaveCV
mov [bCount], A
Parameters:
None
Return Value:
The Count register content is returned in the Accumulator.
Side Effects:
In order to read the value of the Count register, its value must be momentarily transferred to the Com-
pare register before it can be returned. This causes the compare condition to become true immediately
or on the next Timer input clock cycle depending on whether the CompareType parameter is set to
“Less than or Equal to,” or “Less Than,” respectively. If (or when) the user module and global interrupts
are enabled, the interrupt will be serviced, quite possibly before this API function has returned to the

10 September 7, 2004
General Purpose Timers

caller and even before it has restored the Compare register to its previous state. Interrupts are
momentarily diabled. Finally, in order to restore the Compare register, the user module itself is tempo-
rarily disabled . This may cause the Count register to miss one or more counts. The A and X registers
may be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer8_bReadTimer
Description:
Reads the current Timer8 Count register value. This performs a software-solicited, hardware-synchro-
nous counter capture operation. This is the preferred method of reading the Count register, providing
that the Compare register is not required to be preserved. Note that this API routine used to be called
bCaptureCounter.

C Prototype:
BYTE Timer8_bReadTimer(void);
Assembly:
call Timer8_bReadTimer
mov [bCount], A
Parameters:
None
Returns:
Count register contents. It is returned in the Accumulator.
Side Effects:
Compare register contents are lost. The compare condition becomes true immediately or on the next
Timer input clock cycle depending on whether the CompareType parameter is set to “Less than or
Equal to,” or “Less Than,” respectively. If (or when) the user module and global interrupts are enabled,
the interrupt will be serviced, quite possibly before this API function has returned control to its caller.
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

16-Bit Timer API


Application Programming Interface (API) routines are provided as part of the user module to allow the
designer to deal with the module at a higher level. The following are the API programming routines
provided for Timer16.

(CONSTANT) Timer16_PERIOD
Description:
Represents the value chosen for the Period field of the Timer16 in the Device Editor. The value can
have a range between 0 and 65535.

(CONSTANT) Timer16_COMPARE_VALUE
Description:
Represents the value chose for the PulseWidth field of the Timer16 in the Device Editor. The value can
have a range between 0 and 65535.

September 7, 2004 11
User Module Data Sheet

(FUNCTION) Timer16_EnableInt
Description:
Enables the interrupt mode operation. Note, however, that global interrupts must also be enabled
before interrupts will actually be serviced.
C Prototype:
void Timer16_EnableInt(void);
Assembly:
call Timer16_EnableInt
Parameters:
None
Return Value:
None
Side Effects:
This routine modifies the appropriate interrupt enable register in IO space. The A and X registers may
be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer16_DisableInt
Description:
Disables the interrupt mode operation.
C Prototype:
void Timer16_DisableInt(void);
Assembly:
call Timer16_DisableInt
Parameters:
None
Return Value:
None
Side Effects:
This routine modifies the appropriate interrupt enable register in IO space. The A and X registers may
be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer16_Start
Description:
Starts the Timer16 operation. The Count register will be decremented on the next clock cycle.
C Prototype:
void Timer16_Start(void);
Assembly:
call Timer16_Start
Parameters:
None

12 September 7, 2004
General Purpose Timers

Return Value:
None
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer16_Stop
Description:
Stops the Timer16 operation.
C Prototype:
void Timer16_Stop(void);
Assembly:
call Timer16_Stop
Parameters:
None
Return Value:
None
Side Effects:
The output will be set low and subsequent writes to the Period register will cause the Count register to
update with the new period value. The A and X registers may be modified by this or future implementa-
tions of this function. The same is true for all RAM page pointer registers in the Large Memory Model
(CY8C29xxx). When necessary, it is the calling function's responsibility to preserve the values across
calls to fastcall16 functions.

(FUNCTION) Timer16_WritePeriod
Description:
Writes the Period register with the period value. The period will be loaded into the Count register, when
the zero-count condition is reached or immediately if the Timer16 is currently stopped.
C Prototype:
void Timer16_WritePeriod(WORD wPeriod);
Assembly:
mov X, [wPeriod] ; place MSB in X
mov A, [wPeriod+1] ; place LSB in A
call Timer16_WritePeriod
Parameters:
wPeriod: wPeriod is a value between 0 and 216-1, to set the Timer16 period. MSB is passed in the X
register and LSB is passed in the Accumulator.
Return Value:
None
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

September 7, 2004 13
User Module Data Sheet

(FUNCTION) Timer16_WriteCompareValue
Description:
Modifies the value of the Timer’s Compare register. In order to avoid unexpected side effects, the
Timer should be disabled (not yet enabled via the Start API function or by first calling the Stop API
function).
C Prototype:
void Timer16_WriteCompareValue(WORD wCompareValue);
Assembly:
mov X, [wCompareValue] ; place MSB in X
mov A, [wCompareValue+1] ; place LSB in A
call Timer16_WriteCompareValue
Parameters:
wCompareValue: wCompareValue is a value between 0 and the Period register value, to set the
Timer16 compare value. MSB is passed in the X register and LSB is passed in the Accumulator.
Return Value:
None
Side Effects:
If this function is called while the Timer is running and the compare value is equal to or greater than the
current value of the Count register, then a compare event can occur. The value of the compare register
may vary somewhat unpredictably as the Compare register is distributed across multiple PSoC blocks
and written one byte at a time. The order in which the bytes are written is not specified and subject to
change. This could cause an interrupt, if both the interrupt type is set to trigger on the compare event
and the Timer interrupt is enabled. The A and X registers may be modified by this or future implemen-
tations of this function. The same is true for all RAM page pointer registers in the Large Memory Model
(CY8C29xxx). When necessary, it is the calling function's responsibility to preserve the values across
calls to fastcall16 functions.

(FUNCTION) Timer16_wReadCompareValue
Description:
Reads the Timer16 Compare registers.
C Prototype:
WORD Timer16_wReadCompareValue(void);
Assembly:
call Timer16_wReadCompareValue
mov [wCompareValue], X ; MSB returned in X
mov [wCompareValue+1], A ; LSB returned in A
Parameters:
None
Return Value:
wCompareValue: Compare register contents. MSB is passed in the X register and LSB is passed in the
Accumulator.
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

14 September 7, 2004
General Purpose Timers

(FUNCTION) Timer16_wReadTimerSaveCV
Description:
Reads the current Timer16 Count register value, while preserving the Compare registers. This per-
forms a software-solicited, hardware-synchronous counter capture operation. This function should
only be used if the contents of the Compare register must be preserved. If the Compare register con-
tents do not need to be preserved, then using the wReadTimer() function is preferred. Note that this
API routine used to be called wReadCounter.

C Prototype:
WORD Timer16_wReadTimerSaveCV(void);
Assembly:
call Timer16_wReadTimerSaveCV
mov [wCount], X ; MSB returned in X
mov [wCount+1], A ; LSB returned in A
Parameters:
None
Return Value:
wCount: Count register contents. MSB is passed in the X register and LSB is passed in the Accumula-
tor.
Side Effects:
In order to read the value of the Count register, its value must be momentarily transferred to the Com-
pare register before it can be returned. This causes the compare condition to become true immediately
or on the next Timer input clock cycle depending on whether the CompareType parameter is set to
“Less than or Equal to,” or “Less Than,” respectively. If (or when) the user module and global interrupts
are enabled, the interrupt will be serviced, quite possibly before this API function has returned to the
caller and even before it has restored the Compare register to its previous state. Interrupts are
momentarily diabled. Finally, in order to restore the Compare register, the user module itself is tempo-
rarily disabled . This may cause the Count register to miss one or more counts. The A and X registers
may be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer16_wReadTimer
Description:
Reads the current Timer16 Count register value. This performs a software-solicited, hardware-syn-
chronous counter capture operation. This is the preferred method of reading the Count registers, pro-
viding that the Compare registers are not required to be preserved. Note that this API routine used to
be called wCaptureCounter.

C Prototype:
WORD Timer16_wReadTimer(void);
Assembly:
call Timer16_wReadTimer
mov [wCount], X ; MSB returned in X
mov [wCount+1], A ; LSB returned in A
Parameters:
None

September 7, 2004 15
User Module Data Sheet

Returns:
wCount: Count register contents. MSB is passed in the X register and LSB is passed in the Accumula-
tor.
Side Effects:
Compare register contents are lost. The compare condition becomes true immediately or on the next
Timer input clock cycle depending on whether the CompareType parameter is set to “Less than or
Equal to,” or “Less Than,” respectively. If (or when) the user module and global interrupts are enabled,
the interrupt will be serviced, quite possibly before this API function has returned control to its caller.
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

24-Bit Timer API


Application Programming Interface (API) routines are provided as part of the user module to allow the
designer to deal with the module at a higher level. The following are the API programming routines
provided for Timer24.

(CONSTANT) Timer24_PERIOD
Description:
Represents the value chosen for the Period field of the Timer24 in the Device Editor. The value can
have a range between 0 and 16777215.

(CONSTANT) Timer24_COMPARE_VALUE
Description:
Represents the value chose for the PulseWidth field of the Timer24 in the Device Editor. The value can
have a range between 0 and 16777215.

(FUNCTION) Timer24_EnableInt
Description:
Enables the interrupt mode operation. Note, however, that global interrupts must also be enabled
before interrupts will actually be serviced.
C Prototype:
void Timer24_EnableInt(void);
Assembly:
call Timer24_EnableInt
Parameters:
None
Return Value:
None
Side Effects:
This routine modifies the appropriate interrupt enable register in IO space. The A and X registers may
be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions.

16 September 7, 2004
General Purpose Timers

(FUNCTION) Timer24_DisableInt
Description:
Disables the interrupt mode operation.
C Prototype:
void Timer24_DisableInt(void);
Assembly:
call Timer24_DisableInt
Parameters:
None
Return Value:
None
Side Effects:
This routine modifies the appropriate interrupt enable register in IO space. The A and X registers may
be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer24_Start
Description:
Starts the Timer24 operation. The Count register will be decremented on the next clock cycle.
C Prototype:
void Timer24_Start(void);
Assembly:
call Timer24_Start
Parameters:
None
Return Value:
None
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer24_Stop
Description:
Stops the Timer24 operation.
C Prototype:
void Timer24_Stop(void);
Assembly:
call Timer24_Stop
Parameters:
None
Return Value:
None

September 7, 2004 17
User Module Data Sheet

Side Effects:
The output will be set low and subsequent writes to the Period register will cause the Count register to
update with the new period value. The A and X registers may be modified by this or future implementa-
tions of this function. The same is true for all RAM page pointer registers in the Large Memory Model
(CY8C29xxx). When necessary, it is the calling function's responsibility to preserve the values across
calls to fastcall16 functions.

(FUNCTION) Timer24_WritePeriod
Description:
Writes the Period register with the period value. The period will be loaded into the Count register, when
the zero-count condition is reached or immediately if the Timer24 is currently stopped.
C Prototype:
void Timer24_WritePeriod(DWORD dwPeriod);
Assembly:
mov X, dwPeriod ; move address of period into X
call Timer24_WritePeriod
Parameters:
dwPeriod: The value is from 0 to 224-1.
Return Value:
None
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer24_WriteCompareValue
Description:
Modifies the value of the Timer’s Compare register. In order to avoid unexpected side effects, the
Timer should be disabled (not yet enabled via the Start API function or by first calling the Stop API
function).
C Prototype:
void Timer24_WriteCompareValue(DWORD dwCompareValue);
Assembly:
mov X, dwCompareValue ; move address of compare value into X
call Timer24_WriteCompareValue
Parameters:
dwCompareValue: The value is from 0 to the period value.
Return Value:
None
Side Effects:
If this function is called while the Timer is running and the compare value is equal to or greater than the
current value of the Count register, then a compare event can occur. The value of the compare register
may vary somewhat unpredictably as the Compare register is distributed across multiple PSoC blocks
and written one byte at a time. The order in which the bytes are written is not specified and subject to
change. This could cause an interrupt, if both the interrupt type is set to trigger on the compare event
and the Timer interrupt is enabled. The A and X registers may be modified by this or future implemen-
tations of this function. The same is true for all RAM page pointer registers in the Large Memory Model

18 September 7, 2004
General Purpose Timers

(CY8C29xxx). When necessary, it is the calling function's responsibility to preserve the values across
calls to fastcall16 functions.

(FUNCTION) Timer24_ReadCompareValue
Description:
Reads the Timer24 Compare registers.
C Prototype:
void Timer24_ReadCompareValue(DWORD * pdwCompareValue);
Assembly:
mov X, pdwCompareValue ; move address of return value into X
call Timer24_ReadCompareValue
Parameters:
pdwCompareValue: Pointer to a buffer to hold the Compare register data. The X register is loaded with
the ram address where the return value is to be stored.
Return Value:
None (see Side Effects).
Side Effects:
The value of the Compare register is stored in the location specified by the actual parameter. The A
and X registers may be modified by this or future implementations of this function. The same is true for
all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the
calling function's responsibility to preserve the values across calls to fastcall16 functions. Currently,
only the IDX_PP page pointer register is modified.

(FUNCTION) Timer24_ReadTimerSaveCV
Description:
Reads the current Timer24 Count register value, while preserving the Compare registers. This per-
forms a software-solicited, hardware-synchronous counter capture operation. This function should
only be used if the contents of the Compare register must be preserved. If the Compare register con-
tents do not need to be preserved, then using the ReadTimer() function is preferred. Note that this API
routine used to be called ReadCounter.

C Prototype:
void Timer24_ReadTimerSaveCV(DWORD * pdwCount);
Assembly:
mov X, pdwCount ; move address of return value into X
call Timer24_ReadTimerSaveCV
Parameters:
None
Return Value:
Count register contents. Returned in specified buffer.
Side Effects:
In order to read the value of the Count register, its value must be momentarily transferred to the Com-
pare register before it can be returned. This causes the compare condition to become true immediately
or on the next Timer input clock cycle depending on whether the CompareType parameter is set to
“Less than or Equal to,” or “Less Than,” respectively. If (or when) the user module and global interrupts
are enabled, the interrupt will be serviced, quite possibly before this API function has returned to the

September 7, 2004 19
User Module Data Sheet

caller and even before it has restored the Compare register to its previous state. Interrupts are
momentarily diabled. Finally, in order to restore the Compare register, the user module itself is tempo-
rarily disabled . This may cause the Count register to miss one or more counts. The A and X registers
may be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions. Currently, only the IDX_PP
page pointer register is modified.

(FUNCTION) Timer24_ReadTimer
Description:
Reads the current Timer24 Count register value. This performs a software-solicited, hardware-syn-
chronous counter capture operation. This is the preferred method of reading the Count registers, pro-
viding that the Compare registers are not required to be preserved. Note that this API routine used to
be called CaptureCounter.

C Prototype:
void Timer24_ReadTimer(DWORD * pdwCount);
Assembly:
mov X, pdwCount ; move address of return value into X
call Timer24_ReadTimer
Parameters:
None
Returns:
Count value is returned in the specified buffer.
Side Effects:
Compare register contents are lost. The compare condition becomes true immediately or on the next
Timer input clock cycle depending on whether the CompareType parameter is set to “Less than or
Equal to,” or “Less Than,” respectively. If (or when) the user module and global interrupts are enabled,
the interrupt will be serviced, quite possibly before this API function has returned control to its caller.
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions. Cur-
rently, only the IDX_PP page pointer register is modified.

32-Bit Timer API


Application Programming Interface (API) routines are provided as part of the user module to allow the
designer to deal with the module at a higher level. The following are the API programming routines
provided for Timer32.

(CONSTANT) Timer32_PERIOD
Description:
Represents the value chosen for the Period field of the Timer32 in the Device Editor. The value can
have a range between 0 and 4294967295.

(CONSTANT) Timer24_COMPARE_VALUE
Description:
Represents the value chose for the PulseWidth field of the Timer32 in the Device Editor. The value can

20 September 7, 2004
General Purpose Timers

have a range between 0 and 4294967295.

(FUNCTION) Timer32_EnableInt
Description:
Enables the interrupt mode operation. Note, however, that global interrupts must also be enabled
before interrupts will actually be serviced.
C Prototype:
void Timer32_EnableInt(void);
Assembly:
call Timer32_EnableInt
Parameters:
None
Return Value:
None
Side Effects:
This routine modifies the appropriate interrupt enable register in IO space. The A and X registers may
be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer32_DisableInt
Description:
Disables the interrupt mode operation.
C Prototype:
void Timer32_DisableInt(void);
Assembly:
call Timer32_DisableInt
Parameters:
None
Return Value:
None
Side Effects:
This routine modifies the appropriate interrupt enable register in IO space. The A and X registers may
be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer32_Start
Description:
Starts the Timer32 operation. The Count register will be decremented on the next clock cycle.
C Prototype:
void Timer32_Start(void);
Assembly:
call Timer32_Start

September 7, 2004 21
User Module Data Sheet

Parameters:
None
Return Value:
None
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

(FUNCTION) Timer32_Stop
Description:
Stops the Timer32 operation.
C Prototype:
void Timer32_Stop(void);
Assembly:
call Timer32_Stop
Parameters:
None
Return Value:
None
Side Effects:
The output will be set low and subsequent writes to the Period register will cause the Count register to
update with the new period value. The A and X registers may be modified by this or future implementa-
tions of this function. The same is true for all RAM page pointer registers in the Large Memory Model
(CY8C29xxx). When necessary, it is the calling function's responsibility to preserve the values across
calls to fastcall16 functions.

(FUNCTION) Timer32_WritePeriod
Description:
Writes the Period register with the period value. The period will be loaded into the Count register, when
the zero-count condition is reached or immediately if the Timer32 is currently stopped.
C Prototype:
void Timer32_WritePeriod(DWORD dwPeriod);
Assembly:
mov X, dwPeriod ; move address of period value into X
call Timer32_WritePeriod
Parameters:
dwPeriod: The value is from 0 to 232-1.
Return Value:
None
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions.

22 September 7, 2004
General Purpose Timers

(FUNCTION) Timer32_WriteCompareValue
Description:
Modifies the value of the Timer’s Compare register. In order to avoid unexpected side effects, the
Timer should be disabled (not yet enabled via the Start API function or by first calling the Stop API
function).
C Prototype:
void Timer32_WriteCompareValue(DWORD dwCompareValue);
Assembly:
mov X, dwCompareValue ; move address of compare value into X
call Timer32_WriteCompareValue
Parameters:
dwCompareValue: The value is from 0 to the period value.
Return Value:
None
Side Effects:
If this function is called while the Timer is running and the compare value is equal to or greater than the
current value of the Count register, then a compare event can occur. The value of the compare register
may vary somewhat unpredictably as the Compare register is distributed across multiple PSoC blocks
and written one byte at a time. The order in which the bytes are written is not specified and subject to
change. This could cause an interrupt, if both the interrupt type is set to trigger on the compare event
and the Timer interrupt is enabled. The A and X registers may be modified by this or future implemen-
tations of this function. The same is true for all RAM page pointer registers in the Large Memory Model
(CY8C29xxx). When necessary, it is the calling function's responsibility to preserve the values across
calls to fastcall16 functions.

(FUNCTION) Timer32_ReadCompareValue
Description:
Reads the Timer32 Compare registers using “pass-by-reference” parameter.
C Prototype:
void Timer32_ReadCompareValue(DWORD * pdwCompareValue);
Assembly:
mov X, pdwCompareValue ; move address of return value into X
call Timer32_ReadCompareValue
Parameters:
pdwCompareValue: Pointer to a buffer to hold the Compare register data. The X register is loaded with
the ram address where the return value is to be stored.
Return Value:
The value of the Compare register is returned in specified buffer.
Side Effects:
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions. Cur-
rently, only the IDX_PP page pointer register is modified.

September 7, 2004 23
User Module Data Sheet

(FUNCTION) Timer32_ReadTimerSaveCV
Description:
Reads the current Timer32 Count register value, while preserving the Compare registers. This per-
forms a software-solicited, hardware-synchronous counter capture operation. This function should
only be used if the contents of the Compare register must be preserved. If the Compare register con-
tents do not need to be preserved, then using the ReadTimer() function is preferred. Note that this API
routine used to be called ReadCounter.

C Prototype:
void Timer32_ReadTimerSaveCV(DWORD * pdwCount);
Assembly:
mov X, pdwCount ; X points to the return buffer
call Timer32_ReadTimerSaveCV
Parameters:
None
Return Value:
pdwCount: Count register contents. The X register is loaded with the address of the return buffer.
Side Effects:
In order to read the value of the Count register, its value must be momentarily transferred to the Com-
pare register before it can be returned. This causes the compare condition to become true immediately
or on the next Timer input clock cycle depending on whether the CompareType parameter is set to
“Less than or Equal to,” or “Less Than,” respectively. If (or when) the user module and global interrupts
are enabled, the interrupt will be serviced, quite possibly before this API function has returned to the
caller and even before it has restored the Compare register to its previous state. Interrupts are
momentarily diabled. Finally, in order to restore the Compare register, the user module itself is tempo-
rarily disabled . This may cause the Count register to miss one or more counts. The A and X registers
may be modified by this or future implementations of this function. The same is true for all RAM page
pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it is the calling function's
responsibility to preserve the values across calls to fastcall16 functions. Currently, only the IDX_PP
page pointer register is modified.

(FUNCTION) Timer32_ReadTimer
Description:
Reads the current Timer32 Count register value. This performs a software-solicited, hardware-syn-
chronous counter capture operation. This is the preferred method of reading the Count registers, pro-
viding that the Compare registers are not required to be preserved. Note that this API routine used to
be called CaptureCounter.

C Prototype:
void Timer32_ReadTimer(DWORD * pdwCount);
Assembly:
mov X, pdwCount ; X points to the return buffer
call Timer32_ReadTimer
Parameters:
None
Returns:
pdwCount: Pointer to a buffer to hold the Count register data. The X register is loaded with the address

24 September 7, 2004
General Purpose Timers

of the return buffer.


Side Effects:
Compare register contents are lost. The compare condition becomes true immediately or on the next
Timer input clock cycle depending on whether the CompareType parameter is set to “Less than or
Equal to,” or “Less Than,” respectively. If (or when) the user module and global interrupts are enabled,
the interrupt will be serviced, quite possibly before this API function has returned control to its caller.
The A and X registers may be modified by this or future implementations of this function. The same is
true for all RAM page pointer registers in the Large Memory Model (CY8C29xxx). When necessary, it
is the calling function's responsibility to preserve the values across calls to fastcall16 functions. Cur-
rently, only the IDX_PP page pointer register is modified.

Sample Code
8-Bit Timer Sample Firmware Source Code
In the following examples, the correspondence between the C and assembly code is simple and direct.
The values shown for period and compare value are each “off-by-1” from the cardinal values because the
registers are zero-based; i.e., zero is the terminal count in their down-count cycle. Passing a simple one
byte parameter in the A register rather than on the stack is a performance optimization used by both the
assembler and C compiler for user module APIs. The C compiler employs this mechanism for “INT” types
instead of pushing the argument on the stack when it sees the #pragma fastcall declarations in the
Timer8.h file.
The following is assembly language source that illustrates the use of the APIs.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description:
; This sample shows how to create an interrupt every 1 ms.
;
; The interrupt should be set to interrupt on the terminal count event.
; The capture input should be connected to LOW.
; The clock should be connected to 24V2(VC2), with the 24V1(VC1) clock
; divisor set to 16 and the 24V2(VC2) divisor set to 15.
;
; So PERIOD Count = 1 ms / ( 1/24 MHz * (16 * 15 )) - 1= 99
;
; Parameters: none
; Returns: none
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

include "M8C.inc" ; include the global include file

include "TIMER8.inc" ; include the Timer8 API include file

Setup1msPulse:
mov A, 99 ; set the period to be 100 counts of the clk
call TIMER8_WritePeriod
call TIMER8_EnableInt ; enable the timer interrupt mask
M8C_EnableGInt ; enable the global interrupt mask
call TIMER8_Start ; start the timer – timer will start to
ret ; count when the enable input is asserted

The same code in C is as follows.


/************************************************************************
* This sample shows how to create an interrupt every 1 ms.

September 7, 2004 25
User Module Data Sheet

*
* The interrupt should be set to interrupt on the terminal count event.
* The capture input should be connected to LOW.
* The clock should be connected to 24V2(VC2), with the 24V1(VC1) clock
* divisor set to 16 and the 24V2(VC2) divisor set to 15.
*
* So PERIOD Count = 1 ms / ( 1/24 MHz * (16 * 15 )) - 1= 99
*
* Parameters: none
* Returns: none
************************************************************************/
/* include the global header file */
#include "M8C.h"

/* include the timer8 API header file */


#include "TIMER8.h"

/* function prototype */
void Setup1msPulse(void);

/* Divide by eight function */


void Setup1msPulse(void)
{
/* set period to 100 clocks */
TIMER8_WritePeriod(99);

/* ensure interrupt is enabled */


TIMER8_EnableInt();

/* enable the global interrupts */


M8C_EnableGInt;

/* start the counter! */


TIMER8_Start();
}

16-Bit Timer Sample Firmware Source Code


In the following examples, the correspondence between the C and assembly code is simple and direct.
The values shown for period and compare value are each “off-by-1” from the cardinal values because the
registers are zero-based; i.e., zero is the terminal count in their down-count cycle. Passing a simple one
byte parameter in the A register rather than on the stack is a performance optimization used by both the
assembler and C compiler for user module APIs. The C compiler employs this mechanism for “INT” types
instead of pushing the argument on the stack when it sees the #pragma fastcall declarations in the
Timer16.h file.
The following is assembly language source that illustrates the use of the APIs.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description:
; This sample shows how to capture an event with a bounded time limit.
; The count resolution is 30.5 us, with a bounded time limit of 1.99
; seconds.
;
; The interrupt should be set to interrupt on the Compare – Less than
; equal. The capture input should be connected to the event that is
; being measured. The clock should be connected to the 32.768K internal
; clock.
;

26 September 7, 2004
General Purpose Timers

; Computed time lapse is: (65,535 – wCount ) / 32,768.


;
; The foreground routine sets and starts the timer. The interrupt
; level routine captures the value.
;
; Parameters: none
; Returns: none
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

include "M8C.inc" ; include the global include file


include "TIMER16.inc" ; include the Timer16 API include file

area bss (RAM,REL)


_wElapsedTime::
wElapsedTime:: BLK 2

area text (ROM,REL)

CapturePulse::
mov [wElapsedTime], 0
mov [wElapsedTime+1], 0
mov A, FFh ; set the period to the maximum
mov X, FFh
call TIMER16_WritePeriod
mov X, 0 ; set the compare to trigger at 1
mov A, 0
call TIMER16_WriteCompareValue
call TIMER16_EnableInt ; enable the timer interrupt mask
M8C_EnableGInt ; enable global interrupts
Call TIMER16_Start ; start the timer – timer will start to
.WaitForCapture:
mov A, [wElapsedTime]
or A, [wElapsedTime+1]
jz .WaitForCapture

.TimerDone:
;Evaluate captured value here!
;If wElapsedTime is not > 1 then compute elapsed time.
;else if wElapsedTime is 1 or 0 then event did not occur within
;time limit.

; return to caller when complete


ret

The interrupt level routine, located in the file capture_int.asm, is as follows.


Capture_ISR:
; Interrupt has occurred! Read and then stop the timer.
push X
push A
call TIMER16_wReadTimer
mov [_wElapsedTime+1], A
mov [_wElapsedTime], X
call TIMER16_Stop
pop A
pop X
reti

The same code in C is as follows. Note that the interrupt routine must be written in assembly.

September 7, 2004 27
User Module Data Sheet

#include "M8C.h"
#include "TIMER16.h"

WORD wElapsedTime;

void CapturePulse( void )


{
TIMER16_WritePeriod(0xffff);
TIMER16_WriteCompareValue(0x0001);
TIMER16_EnableInt();
M8C_EnableGInt;
TIMER16_Start();
while( wElapsedTime == 0 );

/* Process the data here */


}

24-Bit Timer Sample Firmware Source Code


In the following examples, the correspondence between the C and assembly code is simple and direct.
The values shown for period and compare value are each “off-by-1” from the cardinal values because the
registers are zero-based; i.e., zero is the terminal count in their down-count cycle. Passing a simple one
byte parameter in the A register rather than on the stack is a performance optimization used by both the
assembler and C compiler for user module APIs. The C compiler employs this mechanism for “INT” types
instead of pushing the argument on the stack when it sees the #pragma fastcall declarations in the
Timer24.h file.
The following is assembly language source that illustrates the use of the APIs.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description:
; This sample shows how to capture an event with a bounded time limit.
; The count resolution is 1 us, with a bounded time limit of 16 seconds.
;
; The interrupt should be set to interrupt on the Compare – Less than
; equal. The capture input should be connected to the event that is
; being measured. The clock should be connected to 24V2(VC2). The
; 24V1(VC1)divider should be set to 8 and the 24V2(VC2)divider set to 3.
;
; Computed time lapse is: (16,777,216 – dwCount ) / 1 MHz
;
; The foreground routine sets and starts the timer. The interrupt
; level routine captures the value.
;
; Parameters: none
; Returns: none
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

include "M8C.inc" ; include the global include file


include "TIMER24.inc" ; include the Timer24 API include file

area bss (RAM,REL)


_dwElapsedTime::
dwElapsedTime:: BLK 4

area text (ROM,REL)

CapturePulse::
mov X, SP ; create a stack frame for arguments

28 September 7, 2004
General Purpose Timers

add SP, 4

mov [dwElapsedTime], 0
mov [dwElapsedTime+1], 0
mov [dwElapsedTime+2], 0
mov [dwElapsedTime+3], 0
mov [X], 00h ; set the period to the max count
mov [X+1], FFh
mov [X+2], FFh
mov [X+3], FFh
call TIMER24_WritePeriod
mov [X], 00h ; set the compare value to trigger at 16 sec
mov [X+1], 0Bh ; (16,777,216 – 16,000,000) = 777,216
mov [X+2], DCh
mov [X+3], 00h
call TIMER24_WriteCompareValue
call TIMER24_EnableInt ; enable the timer interrupt mask
M8C_EnableGInt ; enable global interrupts
mov X, dwElapsedTime ; point X to dwElapsedTime
call TIMER24_Start ; start the timer – timer will start to
.WaitForCapture:
mov A, [X+1]
or A, [X+2]
or A, [X+3]
jz .WaitForCapture

.TimerDone:
;Evaluate captured value here!
;If dwElapsedTime is not > 1 then compute elapsed time.
;else if wElapsedTime is 1 or 0 then event did not occur within time
;limit.

; return to caller when complete


add SP, -4
ret

The interrupt level routine, located in the file captureint.asm, is as follows.


Capture_ISR:
; Interrupt has occurred! Read and then stop the timer.
push X
push A
mov X, _dwElapsedTime
call TIMER24_ReadTimer
call TIMER24_Stop
pop A
pop X
reti

The same code in C is as follows. Note that the interrupt routine must be written in assembly.
#include "M8C.h"
#include "TIMER24.h"
DWORD dwElapsedTime;

void CapturePulse( void )


{
TIMER24_WritePeriod(0xffffff);

September 7, 2004 29
User Module Data Sheet

TIMER24_WriteCompareValue(0x0bdc00);
TIMER24_EnableInt();
M8C_EnableGInt;
TIMER24_Start();
while( dwElapsedTime == 0 );

/* Process the data here */


}

32-Bit Timer Sample Firmware Source Code


In the following examples, the correspondence between the C and assembly code is simple and direct.
The values shown for period and compare value are each “off-by-1” from the cardinal values because the
registers are zero-based; i.e., zero is the terminal count in their down-count cycle. Passing a simple one
byte parameter in the A register rather than on the stack is a performance optimization used by both the
assembler and C compiler for user module APIs. The C compiler employs this mechanism for “INT” types
instead of pushing the argument on the stack when it sees the #pragma fastcall declarations in the
Timer32.h file.
The following is assembly language source that illustrates the use of the APIs.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description:
; This sample shows how to capture an event with a bounded time limit.
; The count resolution is 1 us, with a bounded time limit of 16 seconds.
;
; The interrupt should be set to interrupt on the Compare – Less than
; equal. The capture input should be connected to the event that is
; being measured. The clock should be connected to 24V2(VC2). The 24V1
; (VC1) divider should be set to 8 and the 24V2(VC2) divider set to 3.
;
; Computed time lapse is: (0xFFFFFFFF – dwElapsedTime ) / 1 MHz
;
; The foreground routine sets and starts the timer. The interrupt
; level routine captures the value.
;
; Parameters: none
; Returns: none
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

include "M8C.inc" ; include the global include file


include "TIMER32.inc" ; include the Timer32 API include file
area bss (RAM,REL)
_dwElapsedTime::
dwElapsedTime:: BLK 4

area text (ROM,REL)


CapturePulse::
mov X, SP ; create a stack frame for arguments
add SP, 4

mov [dwElapsedTime], 0
mov [dwElapsedTime+1], 0
mov [dwElapsedTime+2], 0
mov [dwElapsedTime+3], 0
mov [X], FFh ; set the period to a Max count
mov [X+1], FFh

30 September 7, 2004
General Purpose Timers

mov [X+2], FFh


mov [X+3], FFh
call TIMER32_WritePeriod
mov [X], FFh ; set the compare value to trigger at 16 secs
mov [X+1], 0Bh ; 4,294,967,295 – 16,000,000 = 4,278,967,295
mov [X+2], DCh ; -> 0xFF0BDC00
mov [X+3], 00h
call TIMER32_WriteCompareValue
call TIMER32_EnableInt ; enable the timer interrupt mask
M8C_EnableGInt ; enable global interrupts
mov X, dwElapsedTime ; point X to dwElapsedTime
call TIMER32_Start ; start the timer – timer will start to
.WaitForCapture:
mov A, [X+0]
or A, [X+1]
or A, [X+2]
or A, [X+3]
jz .WaitForCapture

.TimerDone:
;Evaluate captured value here!
;If dwElapsedTime is not > 1 then compute elapsed time.
;else if wElapsedTime is 1 or 0 then event did not occur within
;time limit.

; return to caller when complete


add SP, -4
ret

The interrupt level routine, located in the file capture_int.asm, is as follows.


Capture_ISR:
; Interrupt has occurred! Read and then stop the timer.
push X
push A
mov X, _dwElapsedTime
call TIMER32_ReadTimer
call TIMER32_Stop
pop A
pop X
reti

The same code in C is as follows. Note that the interrupt routine must be written in assembly.
#include "M8C.h"
#include "TIMER32.h"

DWORD dwElapsedTime;

void CapturePulse( void )


{
TIMER32_WritePeriod(0xffffffff);
TIMER32_WriteCompareValue(0xff0bdc00);
TIMER32_EnableInt();
M8C_EnableGInt;
TIMER32_Start();
while( dwElapsedTime == 0 );

/* Process the data here */

September 7, 2004 31
User Module Data Sheet

32 September 7, 2004
General Purpose Timers

Configuration Registers
8-Bit Timer Configuration Registers
The 8-bit Timer uses a single digital PSoC block named TIMER8. Each block is personalized and
parameterized through 7 registers. The following tables give the “personality” values as constants and the
parameters as named bitfields with brief descriptions. Symbolic names for these registers are defined in
the user module instance’s C and assembly language interface files (the “.h” and “.inc” files).

Function Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
Compare Interrupt
TIMER8 Data Invert BCEN 1 0 0 0
Type Type
BCEN gates the terminal count output onto the row broadcast bus line. This bitfield is set in the Device
Editor by directly configuring the broadcast line. The Data Invert flag, set through a user module parameter
displayed in the Device Editor, controls the sense of the capture input signal. The CompareType flag
indicates whether the compare function is set to “Less Than or Equal To” or “Less Than.” The
InterruptType flag determines whether to trigger the interrupt on the compare event or on the terminal
count (also see CaptureInt in the Control register). Both CompareType and InterruptType are set in the
Device Editor directly through user module parameters described in the earlier section on the topic.

Input Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
TIMER8 Capture Clock
Capture selects the data input from one of 16 sources. Clock selects the clock input from one of 16
sources. Both parameters are set in the Device Editor.

Output Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
TIMER8 AuxClk AuxEnable AuxSelect OutEnable OutputSelect
The user module “ClockSync” parameter in the Device Editor determines the value of the AuxClk bits.
Though similarly named, the AuxEnable and AuxSelect bits are related, instead, to the OutEnable and
OutSelect bitfields. AuxEnable and AuxSelect permit driving the compare output signal onto one of the
row output busses and are controlled by manipulating the row bus graphically in the Device Editor
Interconnect View. OutEnable is set when the terminal count output is driven onto one of the row output
busses. OutputSelect controls which of the busses will be driven from the compare output.

Count Register (DR0), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
TIMER8 Count
The Count register is the 8-bit down count value decremented by 1 in every clock cycle. Its value is loaded
from the contents of the Period register in the clock cycle following the terminal count (zero value). It can
be read using the Timer8 API.

September 7, 2004 33
User Module Data Sheet

Period Register (DR1), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
TIMER8 Period
Period holds the period value that is loaded into the Count register upon enable or terminal count
condition. It can be set in the Device Editor and the Timer8 API.

Compare Register (DR2), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
TIMER8 Compare Value
Compare Value holds the compare value for use in the comparator to generate the compare event. It can
be set in the Device Editor and the Timer8 API.

Control Register (CR0), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
TIMER8 0 0 0 0 0 0 0 Enable
Enable indicates that the Timer8 is enabled when set. It is modified by using the Timer8 API.

34 September 7, 2004
General Purpose Timers

16-Bit Timer Configuration Registers


The 16-bit Timer uses two digital PSoC blocks. In placement order from left to right they are named
TIMER16_LSB and TIMER16_MSB. Each block is personalized and parameterized through 7 registers.
The following tables give the “personality” values as constants and the parameters as named bitfields with
brief descriptions. Symbolic names for these registers are defined in the user module instance’s C and
assembly language interface files (the “.h” and “.inc” files).

Function Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
Compare Interrupt
MSB Data Invert 0 1 0 0 0
Type Type
Compare
LSB 0 BCEN 1 0 0 0 0
Type
BCEN gates the terminal count output onto the row broadcast bus line. This bitfield is set in the Device
Editor by directly configuring the broadcast line. The Data Invert flag, set through a user module parameter
displayed in the Device Editor, controls the sense of the capture input signal. The CompareType flag
indicates whether the compare function is set to “Less Than or Equal To” or “Less Than.” The
InterruptType flag determines whether to trigger the interrupt on the compare event or on the terminal
count (also see CaptureInt in the Control register). Both CompareType and InterruptType are set in the
Device Editor directly through user module parameters described in the earlier section on the topic.

Input Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
MSB 0 0 1 1 Clock
LSB Capture Clock
Enable selects the input signal of the same name from one of 16 sources. The User Module “Enable”
parameter setting in the Device Editor determines its value. Similarly, the user module “Clock” parameter
setting determines this value.

Output Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
MSB AuxClk AuxEnable AuxSelect OutEnable OutputSelect
LSB AuxClk 0 0 0 0 0 0
The user module “ClockSync” parameter in the Device Editor determines the value of the AuxClk bits.
Though similarly named, the AuxEnable and AuxSelect bits are related, instead, to the OutEnable and
OutSelect bitfields. AuxEnable and AuxSelect permit driving the compare output signal onto one of the
row output busses and are controlled by manipulating the row bus graphically in the Device Editor
Interconnect View. OutEnable is set when the terminal count output is driven onto one of the row output
busses. OutputSelect controls which of the busses will be driven from the compare output.

September 7, 2004 35
User Module Data Sheet

Count Register (DR0), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB Count(MSB)
LSB Count(LSB)
The Count register is the 16-bit down count value decremented by 1 in every clock cycle that the enable
input is active. Its value is loaded from the contents of the Period register in the clock cycle following the
terminal count (zero value). It can be read using the Timer16 API.

Period Register (DR1), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB Period(MSB)
LSB Period(LSB)
The Period register is a write-only register that can be set through the Device Editor and by the Timer16
API. When written, the value is transferred to the Count register if the user module is disabled through the
API. Its value is automatically copied into the Count register in the clock cycle following terminal count.

Compare Register (DR2), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB Compare Val(MSB)
LSB Compare Val(LSB)
The Compare register holds the value against which the Count register is tested in order to generate the
compare output. It can be set by the Device Editor and the Timer16 API.

Control Register (CR0), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB 0 0 0 0 0 0 0 0
LSB 0 0 0 0 0 0 0 Start/Stop
Start/Stop indicates that the Timer16 is enabled when set and disabled when clear. It is modified by using
the Timer16 API.

24-Bit Timer Configuration Registers


The 24-bit Timer uses three digital PSoC blocks. In placement order from left to right they are named
TIMER24_LSB, TIMER24_ISB and TIMER24_MSB. Each block is personalized and parameterized
through 7 registers. The following tables give the “personality” values as constants and the parameters as
named bit-fields with brief descriptions. Symbolic names for these registers are defined in the user module
instance’s C and assembly language interface files (the “.h” and “.inc” files).

36 September 7, 2004
General Purpose Timers

Function Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
Compare Interrupt
MSB Data Invert 0 1 0 0 0
Type Type
Compare
ISB 0 0 0 0 0 0 0
Type
Compare
LSB 0 BCEN 0 0 0 0 0
Type
BCEN gates the terminal count output onto the row broadcast bus line. This bitfield is set in the Device
Editor by directly configuring the broadcast line. The Data Invert flag, set through a user module parameter
displayed in the Device Editor, controls the sense of the capture input signal. The CompareType flag
indicates whether the compare function is set to “Less Than or Equal To” or “Less Than.” The
InterruptType flag determines whether to trigger the interrupt on the compare event or on the terminal
count (also see CaptureInt in the Control register). Both CompareType and InterruptType are set in the
Device Editor directly through user module parameters described in the earlier section on the topic.

Input Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
MSB 0 0 1 1 Clock
ISB 0 0 1 1 Clock
LSB Capture Clock
Enable selects the data input from one of 16 sources. Clock selects the input clock from one of 16
sources. Both parameters are set in the Device Editor.

Output Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
MSB AuxClk AuxEnable AuxSelect OutEnable OutputSel
ISB AuxClk 0 0 0 0 0 0
LSB AuxClk 0 0 0 0 0 0
The user module “ClockSync” parameter in the Device Editor determines the value of the AuxClk bits.
Though similarly named, the AuxEnable and AuxSelect bits are related, instead, to the OutEnable and
OutSelect bitfields. AuxEnable and AuxSelect permit driving the compare output signal onto one of the
row output busses and are controlled by manipulating the row bus graphically in the Device Editor
Interconnect View. OutEnable is set when the terminal count output is driven onto one of the row output
busses. OutputSelect controls which of the busses will be driven from the compare output.

September 7, 2004 37
User Module Data Sheet

Count Register (DR0), Bank 0

Bit 7 6 5 4 3 2 1 0
MSB Count(MSB)
ISB Count(ISB)
LSB Count(LSB)
The Count register is the 24-bit down count value decremented by 1 in every clock cycle that the enable
input is active. Its value is loaded from the contents of the Period register in the clock cycle following the
terminal count (zero value). It can be read using the Timer24 API.

Period Register (DR1), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB Period(MSB)
ISB Period(ISB)
LSB Period(LSB)
The Period register is a write-only register that can be set through the Device Editor and by the Timer24
API. When written, the value is transferred to the Count register if the user module is disabled through the
API. Its value is automatically copied into the Count register in the clock cycle following terminal count.

Compare Register (DR2), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB Compare Val(MSB)
ISB Compare Val(ISB)
LSB Compare Val(LSB)
The Compare register holds the value against which the Count register is tested in order to generate the
compare output. It can be set by the Device Editor and the Timer24 API.

Control Register (CR0), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB 0 0 0 0 0 0 0 0
ISB 0 0 0 0 0 0 0 0
LSB 0 0 0 0 0 0 0 Enable
Enable indicates that the Timer24 is enabled when set and disabled when clear. It is modified by using the
Timer24 API.

32-Bit Timer Configuration Registers


The 32-bit Timer uses four digital PSoC blocks. In placement order from left to right they are named
TIMER32_LSB, TIMER32_ISB1, TIMER32_ISB2 and TIMER32_MSB. Each block is personalized and
parameterized through 7 registers. The following tables give the “personality” values as constants and the

38 September 7, 2004
General Purpose Timers

parameters as named bit-fields with brief descriptions. Symbolic names for these registers are defined in
the user module instance’s C and assembly language interface files (the “.h” and “.inc” files).

Function Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
Compare Interrupt
MSB Data Invert 0 1 0 0 0
Type Type
Compare
ISB2 0 0 0 0 0 0 0
Type
Compare
ISB1 0 0 0 0 0 0 0
Type
Compare
LSB 0 BCEN 0 0 0 0 0
Type
BCEN gates the terminal count output onto the row broadcast bus line. This bitfield is set in the Device
Editor by directly configuring the broadcast line. The Data Invert flag, set through a user module parameter
displayed in the Device Editor, controls the sense of the capture input signal. The CompareType flag
indicates whether the compare function is set to “Less Than or Equal To” or “Less Than.” The
InterruptType flag determines whether to trigger the interrupt on the compare event or on the terminal
count (also see CaptureInt in the Control register). Both CompareType and InterruptType are set in the
Device Editor directly through user module parameters described in the earlier section on the topic.

Input Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
MSB 0 0 1 1 Clock
ISB2 0 0 1 1 Clock
ISB1 0 0 1 1 Clock
LSB Capture Clock
Enable selects the data input from one of 16 sources. Clock selects the input clock from one of 16
sources. Both parameters are set in the Device Editor.

Output Register, Bank 1

Block/Bit 7 6 5 4 3 2 1 0
MSB AuxClk AuxEnable AuxSelect OutEnable OutputSelect
ISB2 AuxClk 0 0 0 0 0 0
ISB1 AuxClk 0 0 0 0 0 0
LSB AuxClk 0 0 0 0 0 0
The user module “ClockSync” parameter in the Device Editor determines the value of the AuxClk bits.
Though similarly named, the AuxEnable and AuxSelect bits are related, instead, to the OutEnable and
OutSelect bitfields. AuxEnable and AuxSelect permit driving the compare output signal onto one of the
row output busses and are controlled by manipulating the row bus graphically in the Device Editor
Interconnect View. OutEnable is set when the terminal count output is driven onto one of the row output
busses. OutputSelect controls which of the busses will be driven from the compare output.

September 7, 2004 39
User Module Data Sheet

Count Register (DR0), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB Count(MSB)
ISB2 Count(ISB1)
ISB1 Count(ISB2)
LSB Count(LSB)
The Count register is the 32-bit down count value decremented by 1 in every clock cycle that the enable
input is active. Its value is loaded from the contents of the Period register in the clock cycle following the
terminal count (zero value). It can be read using the Timer32 API.

Period Register (DR1), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB Period(MSB)
ISB2 Period(ISB1)
ISB1 Period(ISB2)
LSB Period(LSB)
The Period register is a write-only register that can be set through the Device Editor and by the Timer32
API. When written, the value is transferred to the Count register if the user module is disabled through the
API. Its value is automatically copied into the Count register in the clock cycle following terminal count.

Compare Register (DR2), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB Compare Val(MSB)
ISB2 Compare Val(ISB1)
ISB1 Compare Val(ISB2)
LSB Compare Val(LSB)
The Compare register holds the value against which the Count register is tested in order to generate the
compare output. It can be set by the Device Editor and the Timer32 API.

Control Register (CR0), Bank 0

Block/Bit 7 6 5 4 3 2 1 0
MSB 0 0 0 0 0 0 0 0
ISB2 0 0 0 0 0 0 0 0
ISB1 0 0 0 0 0 0 0 0
LSB 0 0 0 0 0 0 0 Enable
Enable indicates that the Timer32 is enabled when set and disabled when clear. It is modified by using the
Timer32 API.

40 September 7, 2004

You might also like