ST52x400/440/441 are 8-bit Intelligent Control
Units (ICU) of th e ST Five Family, w hich are able
to perform both boolean and fuz z y al gorithms in
an efficient manner, in order to reac h the best performances that the two methodologies allow.
ST52x400/440/441 is produced by STM icroelectronics using the reliable high performa nce CMOS
process, including integrated-on-chip peripherals
that allow maximization of system reliability,
decreasingsystem costs and minimizing the
number of externa l components.
The flexible I/O configuration of ST52x400/440/
441 allows for an interface with a wide range of
external devices, like D /A converters or power
control devices.
ST52x400/440/441 pins are configurable, allowing
the user to set the input or output signals on each
single pin.
A hardware multiplier (8 bit by 8 bit with 16 bit
result) and divider (16 bit over 8 bit with 8 bit
result and 8 bit remainder) is available to implement complex functions by using a s ingle inst ruction, optimizing program memory utilization and
computational speed.
Fuzzy Logic dedicated structures in ST52x400/
440/441 ICU’s c an be exploited to model complex
sys
tems with high accuracy in a useful and easy way.
Fuzzy Expert Systems for overall system manage ment and fuzzy Real time Controls can be
designed to increas e performances at highly com petitive costs.
The linguistic approach charac terizing Fuzzy
Logic is based on a set of IF-THEN rules, which
describe the control behavior, as well as on Membership Functions, which are associated to input
and output variables .
Up to 334 Membership Functions, with triangular
and t ra pez oidal sh apes , or singleton value s are
available to describe fuzzy variables.
The T IMER/PWM peripheral allows the management of pow er devices and timing signals, implementing different operating modes and high
frequency PWM (Pulse W ith Modulation) c ontrols.
Input Capture and Out put Compare functions are
available on the TIMER.
The programmable Timer has a 16 bit Internal
Prescaler and an 8 bit Counter.It can use internal
or external START/STOP signals and clock.
An internal programmable WATCHDOG is available to avoid loop errors and to res et the ICU.
An Anal og Comparator with a 6 channel multiplexer is a vailable on ST52x440/441 family
devices. This analog peripheral allows easy implementation of a high resolution A /D conversion. By
using only an ex ternal capacitor this peripheral
may b e configured in order to achieve up to 12 bit
A/D converter resolution. It includes a 2.5 V bandgapreference forA/D conversion calibration,
which can be used externally for s ignal conditioning.
An on-chip TRIAC driver peripheral allows the
direct management of power devices, implementing two different operating modes: Burs t Mode
(i.e. Thermal Applications), Phas e Angle Partialization (i.e. Motors Control by Triacs). The TRIAC
Driver also generates a PWM signal.
The ST52x400/440/441 family also includes an
on-chip Power-on-Reset (POR), which provides
an internal chip res et during power up situation
and a Brown-Out Detector (BOD), which resets
the ICU if the vol tage source V
dips below a
DD
minimum value.
In order to op timize energy consumption, two different power saving modes are available: Wait
mode and Halt mode.
ProgramMemory(EPROM/OTP)addressing
capability addresses up to 8 Kbytes of memory
locations to store both program instructions and
permanent data.
EPROM can be locked by the user to prevent
external undesired operations.
Operations may be performed on data stored in
RAM, allowing the direct combination of new input
and feedback data. All bytes of RAM are used like
Register File.
OTP (One Time Programmable) version devices
are fully compatible with t he EPROM windowed
version, which may be used for prototyping and
pre-production phases of development.
A powerful development environment consisting
of a board a nd software tools allows an easy c onfiguration and use of ST52x400/440/ 441.
The VISUAL FIVE
TM
software tool allows development of projects through a user-friendly graphical interface and optimization of generated code.
7/94
ST52T400/T440/E440/T441
1.2 Operational Description
ST52x400/440/441 IC U can work in two modes:
■ Memory Programming P has e
■ Work ing Phase
according to RESET and Vpp signals levels (see
pins description) .
Note: When RESET=0 it is advisable not to use
the sequence “101010“ to port PA ( 7 : 2 ).
1.2.1 M emory Programmi ng Phase.
The ST52x400/440/441 memory is loaded in the
Memory Programming Phase. All fuzzy and standard instructions are written inside the memory.
This phase starts by setting the control signa ls as
illustrated in (see Table 1.1).
When t his phase starts, the ST52x400/440/441
core is settoRESET status; then 12V are
applied to the Vpp pin in order to start EPR OM
programming. A signal applied to PB1 is used to
increment the memory address; the data is supplied to PORT A (see E PROM programming for
further details).
Table 1.1Control Signals Setting
Control
Signal
RESET001
Vpp5V /12V00
Pro-
gramming
ResetWorking
1.2.2 Working Mode.
The processor starts the work ing phase following
the inst ructions, which have been previously
loaded in the memory.
ST52x400/440/441’s internal structure includes a
computational block, CO NTRO L UNIT (CU)/DATA
PROCESSING UNIT (DPU), which allows processing of boolean functions and fuzzy algorithms.
The CU/DPU can manage up to 334 different
Membership Functions for the fuzzy ru les antecedent part. The rule consequents are “crisp” val ues (real numbe r s). The maximum number of
rules that can be defined is limited by the dimensions of the implemented standard algorithm.
EPROM is then shared between fuzzy and standard algorithms. The Membership Function data is
stored inside the f irst 1024 memory locations. The
Fuzzy rules are parts of the program instructions.
The Control Unit (CU) reads the in format ion and
the status deriving from the peripherals.
Arithmetic calculus can be performed on these
values by using the internal CU and the 128/256
bytes of RAM, which supports all computations.
The peripheral input can be fuzzy and/or arith metic output, or the values contained in Data RAM
and EPROM locations.
ST52x400/440/441 pins can be set in digital input
mode, digital output mode or in Alternate Functions. The pin configuration is ac hieved by means
of the configuration registers. The functions of the
ST52x400/440/441 pins are described bel ow:
V
Main Power Supply Voltage (5V ± 10%).
DD.
. Digital circuit Ground. All Vss pins must be
V
SS
connected to ground (see ST52 T400 pin-out).
ACSTRT, ACSYNC(*). These pins are us ed to
synchronize the 16-bit counter of the Analog Comparator with an external ramp generator. The
ACSTRT input is us ed to start the counter. The
ACSYNC output is set when the counter is ready
to start a new count.
BG(*). A Bandgap Reference value of 2.5V is
available on this p in. It can be used for analog signal conditioning.
GNDA. Analog c ircuit ground of the Analog Comparator. Must be tied to V
. Main Power Supply for internal E PROM pro-
V
PP
SS
.
gramming and MODE selector. During the Programming phase V
Working phase V
must be set at 12V. In the
PP
must be equal to VSS.
PP
OSCin and OSCout. These pins are internally
connected to the on-chip osc illator circuit. A quartz
crystal or a ceramic resonator can be connected
between these t wo pins in order to allow the correct operations of ST52x400/440/441 with various
stability/cost trade-offs. An external clock signal
canbeappliedtoOSCin:inthiscaseOSCout
must be grounded.
RESET. This signal is used to reset the
ST52x400/440/441 and re-initialize the regist ers
and control signals. It also allows the user to
select the working mode of the device.
PA0-PA7, PB0-PB7,PC0-PC4. These lines are
organized as I/O ports. Each pin can be configured as an input or output. During the Programming phase the ports are used for EP R OM data
read/write operations.
TOUT, TOUTN.These pins output the signal generated by the TIMER peripheral. The T0OUTN
signal is the complement of the T0OUT one.
TRES, TSTRT, TCLK . These pins are related to
the TIMER peripheral and are used for Input Capture and event counting. The TRES pin is used to
set/reset theTimer; theTSTRT pin is used to start/
stop the counter. The Timer can be driven by the
internal clock or by an external signal connected
to the TCLK pin.
TROUT, MAIN1,MAIN2. These pins are related to
the TRIAC DRIVER peripheral. TROUT outputs
the signal generated by t he peripheral. In order to
drive a TRIA C directly w it hout the use of additional c omponents, the TROUT pin can supply up
to 50 mA (2V voltage drop). MAIN1 and MAIN2
pins are used to detect the zero crossing of the
Power Line voltage.
(*) Not available in ST52x400 devices
AC0-AC5(*). These pins are used to input the
analog signals to the Analog Comparator. An analog multiplexer is available to switch these inputs
to the Analog Comparator.
CS(*). This pin outputs the current generated in
the Analog Comparator peripheral by a current
generator, allowing charging of an external capacitor to obtain a v oltage ramp for the A / D conversion.
18/94
ST52T400/T440/E440/T441
Signals
2 INTERNAL ARCHITECTURE
ST52x400/440/441 is composed of the following
blocks and peripherals:
■ Cont rol Unit (CU)
■ Dat a P roc es sing Unit (DPU)
■ ALU
■ Decision Processor (DP)
■ EPROM
■ 256 Byte RAM
■ Clock Oscillator
■ Analog Multiplexer and Analog Comparator
■ 1PWM/Timer
■ 1 Triac/PWM Driver
■ Digital I/O port
2.1 Control Unit and Data Processi ng Unit
The Control Unit (CU) formally includes five m ain
blocks. Each block decodes a set of instructions,
generating the appropriate control signals. The
mainpartsoftheCUareshowninFigure2.1.
The five different parts of the CU manage Loading, Logic/Arithmetic, Jump, Control and Decision
Processor (DP) instructions s ets.
The block called “Collector” manages the signals
deriving from the different parts of the CU then
defines the signals fo r the Data Processing Unit
(DPU) and for the different peripherals of the ICU.
The block called “Arbiter” manages the different
parts of the CU in order to have only one part of
the system activat ed during working mode.
The CU structure is highly flexible, designed with
the objective of easily adapt ing the core of the
microcontroller to market needs. New instructions
sets or new peripherals can be easily included
without changing the structure of the microcontroller, maintaining code compatibility.
The C U reads and decodifies the instructions
stored on the EPROM (Fetch). According to the
instructions type, the Arbiter activates one of the
main blocks of the CU. Afterwards, all the control
signals for the DPU are generat ed.
A set of 55 d ifferent arithmetic, DP and logic
instructions is available. T he arithmetic instructions operate to all the RAM addresses without the
need of using special registers.
The DPU receives, stores and sends the instructions coming from the EPROM, RAM or from the
peripherals in order to execute them .
2.1.1 Program Counter .
The Program Counter (PC) is a 13-bit regi ster that
contains the address of t he next memory location
to be proc es s ed by the core. This memory location may be an opcode, an operand or an address
of an operand.
Figure 2.1 CU Block Diagram
MicroCode
A
R
B
I
T
E
R
Clock Master
Loading
Instruction Set
Logic Arithmetic
Instruction Set
Jump
Instruction Set
Control
Instruction Set
Decision Processor
Instruction Set
C
O
L
L
E
C
T
O
R
Control
19/94
ST52T400/T440/E440/T441
add_EPR
S
C
Figure 2.2 Data Processing Unit (DPU )
U
EPROM
INPUTS
PERIPHERALS
M
U
X
ADDRESS RAM
STACK POINT
PROGRAM COUNTER
RAM
128 Bytes
ACCUMULATOR
FLAGS REG.
PERIPHERAL
REGISTERS
MULTIPLEXER
ALU
Figure 2.3 CU/DPU Block Diagram
E
P
R
Microcode
O
M
RAM
C
U
Con tr ol S ig n a ls
EPR OM Address
RAMData8Bit
RAM A ddr.
8Bit
RAM
Data Out
8Bit
D
P
U
To Peripherals
From
P erip he ra ls
20/94
ST52T400/T440/E440/T441
P
ERIPHERALBLO
ONCHIP
RAL
E
ONF
I
REG
IST
ERS
P
ERIPHERAL
P
ERIPHERALBLO
D
C
LDPR
The 13-bit length allows the direct addressing of
8192 bytes in the program space: jump and call
instruction support the absolute addressing in all
the memory.
After having read the curren t instruction address,
the PC value is incremented. Th e result of this
operation is shifted back into the PC.
The PC can be changed in the following ways:
■ J P (Jump) instruction PC = Jump Address
■ InterruptPC = Interrupt Vector
■ RETI instructionPC = Pop (stack)
■ ResetPC = Reset Vector
■ Norm al InstructionPC = PC + 1
2.1.2 Flags.
The ST52x400/440/ 441 core includes different
sets of flags that correspond to 2 different modes:
normal mode and interrupt mode. Each set of
flags consist of a CARRY flag (C), ZERO flag (Z)
and SIGN f lag (S). One set of f lags (CN, ZN, SN)
is used during normal operation and one is used
during interrupt mode (CI, ZI, SI). Formally, the
user has to manage only one set of flags: C, Z and
S.
The ST52x400/440/441 core uses the flags that
correspond to the actual mode: as soon as an
interrupt is gen erated , the ST FIVE core uses the
interrupt flags instead of the normal flags.
Each interrupt lev el has its own set of flag s, which
is saved in the Flag Stack during interrupt servic-
ing.
These flags are restored from th e Flag Stack automatically when a RETI instruction i s executed.
If the ICU was in the normal mode before an interrupt, a fter the RETI instruction is executed, the
normal flags are restored.
Note:
A CALL subroutine is a normal mode execution. For this reason a RET instruction, consequent to a CALL instruction, doesn’t affect the
normal mode set of flags.
Flags are not cleared during context switchin g and
remain in the state they were located in at the end
of the last i nterrupt routine switching.
The Carry flag is set when an overflow o ccurs during arithmetic operations, otherwise it is cleared.
The Sign flag is set when an und erflow occurs
during arithmetic operations, otherwise it is
cleared.
2.2 Address Spaces
ST52x400/440/441 has four separate address
spaces:
■ RAM: 128 or 256 Bytes
■ 20 Input Registers
■ 6 Output Registers
■ 21 Configuration Registers
■ Program memory:up to 8K Bytes
The Program Memory will be described in further
details in the EPROM section
Figure 2.4 Address Spaces Description
PROGRAM MEMORY
NON VOLATILEMEMORY
LDRE
LDCE
LDPE
DATARAM
INPUT REGISTERS
ST FIVE CORE
LDFR
LDRI
DP
REGISTERS
PROGRAM
COUNTER
CU
DPU
ALU
PERIPHE
OUTPUT
R
GISTER
GURATION
C
L
R
S
CK
CK
BLOCK
21/94
ST52T400/T440/E440/T441
2.2.1 Ram and Stack.
RAM consists of 128 (G0/G1/F0/F1 types) or 256
(G2/G3/F2/F3 t y pes ) general purpos e 8-bit regis ters.
All the registers in RAM can be specified by using
a decimal address, e.g. 0 identifies the first register of RAM.
To read or write in the RAM registers, the LOAD
instructions must be used (see Table 2.5).
When the instructions like Interrupt request or
CALL are executed, a STACK is us ed to push the
PC. The STACK is push directly in the RAM. For
each level of stack 2 bytes of RAM are used. The
values of this stack are stored from the last RAM
register (address 255). The maximum level of
stack must be less than 128. When a subroutine
call or interrupt request occurs, the c ontents of
each level is shifted into the next level while the
content of the PC is shifted into the first level.
When a subroutine or interrupt return o ccurs (RE T
or RETI instructions), the first level register is
shifted back into the PC and the value of each
level is popped back into the previous level. These
operating modes are illustrated in Figure 2.5.
2.2.2 Input Registers Benc h.
The Input Registers (IR) bench c ons ists of 20 8-bit
registers containing data derivi ng from the peripherals and parallel p orts.
All the registers can be sp ecified by using a decimal address, e.g. 0 identifies th e first regist er of
the IR.
The assembler instruction:
the value in the
inp
LDRI reg,inp_teg
loads
IR to the register (RAM location) identified by the address reg.
The first input register is dedicated to store the
value of t he stack pointer. The next 12 registers of
the IR are dedicated to the 6 (for ST52X440G/
441G) or the 4 converted values (for ST52X440F/
441F) in c as e of converted values coming from
the Analog Comparator (in S T52x400 devices
these registers are not used ). Each of these values are s tored on two bytes because of the resolution of the A/D conv ersion process. The last 7
registers contain data from t he I/O ports and
PWM/Timers. Table 2.1 summarizes the IR
address and the relative peripheral. In order to
simplify the concept a mnemonic name is
assigned to the registers. The s ame name is used
in VISUAL FI VE development tools.
Figure 2.5 S tack Operation
WHEN RETI OR RET
OCCURS
REG 0
REG 1
REG 2
REG 3
REG 4
REG 5
REG 252
REG 253
REG 254
REG 255
PROGRAM COUNTER
RAM
WHENCALLOR
INTERRUPT REQ.
OCCURS
Stack
Pointer
STACK LEVEL n
..........................
STACK LEVEL 2
STACK LEVEL 1
22/94
ST52T400/T440/E440/T441
2.2.3 Co nfi gu ration Registers.
The ST52x400/440/441 Configuration Registers
allow the configuration of all the blocks of the ICU.
Table 2.2 describes the functions and the related
peripherals of t he 21 C onfiguration Registers
available: in o rder to simplify the concept a mnemonic name is assigned to each Configuration
Register. The same name is used in VISUAL
TM
FIVE
development tools. By using the load
instructions the Configuration R egisters may be
set by using values stored in the Program Memory
(EPROM) or in the RA M.
The assembler instruction
the Configuration Register
of memory location
LDCE conf,mem
conf
with the contents
mem
, inside the currently set
loads
memory page.
The assembler instructions
the Configuration Register
of the register (RAM location)
LDCR conf,reg
conf
with the contents
reg
.
loads
Use and meaning of e ach register will be
described in further details in the corresponding
section.
2.2.4 Output Registers.
The O utpu t Registers (OR) consist of 6 registers
containing data for the ICU peripherals including I/
OPorts.
All registers can be specified by using a decimal
address, e.g. 1 identifies the second OR.
By using the LOA D type inst ruc ti ons the Output
Registers (OR) may be set with values st ored in
the Program Memory (LDPE) or in the RAM
(LDPR).
The assembler instruction
the OutputRegister
ory location
mem
out
, inside the currently set memory
page. The assembler instruction
LDPE out,mem
with the cont ents of mem-
LDPR out,reg
loads the Output Register out with the contents of
reg
register (RAM location)
.
Table 2. 3 des c ribes the OR: in order to simplify the
concept a mnemon ic name is assigned to e ach of
the Output Registers. The same name is us ed in
VISUAL FIVE
TM
development tools. Use and
meaning of each register will b e described in further details in t he c orresponding section.
Table 2.1 Input Registers
IR MNEMONIC NAMEPERIPHERAL REGISTERADDRESS
STACK_POINTERSTACK POINTER0
AC_CHAN0H(*)Analog Comparator CHANNEL 0 High Byte1
AC_CHAN0L(*)Analog Comparator CHANNEL 0 Low Byte2
AC_CHAN1H(*)Analog Comparator CHANNEL 1 High Byte3
AC_CHAN1L(*)Analog Comparator CHANNEL 1 Low Byte4
AC_CHAN2H(*)Analog Comparator CHANNEL 2 High Byte5
AC_CHAN2L(*)Analog Comparator CHANNEL 2 Low Byte6
AC_CHAN3H(*)Analog Comparator CHANNEL 3 High Byte7
AC_CHAN3L(*)Analog Comparator CHANNEL 3 Low Byte8
AC_CHAN4H (*)(**)Analog Comparator CHANNEL 4 High Byte9
REG_CONF 10PWM/TRIACPWM/TRIAC Working mode Configuration
REG_CONF 11PORT CPORT C digital pin I/O direction
REG_CONF 12PORT APORT A Alternate function settings
REG_CONF 13PORT BPORT B digital pin I/O direction
REG_CONF 14(*)PORT BPORT B settings for digital or analog pin
REG_CONF 15(*)ANALOG COMPARATORAnalog Comparator Prescaler settings
REG_CONF 16(*)ANALOG COMPARATORAnalog Comparator in A/D working mode
REG_CONF 17INTERRUPTInterrupt priorities
REG_CONF 18INTERRUPTInterrupt priorities
REG_CONF 19TRIACTRIAC Pulses Width Configuration
REG_CONF 20TRIACTRIAC Pulses Width Configuration
(*) Not used on ST52x400xx versions
PWM/TIMER Prescaler configuration and
output waveform selection.
PWM/TRIAC Prescaler configuration and
output waveform selection.
Table 2.3 Output Registers
OR MNEMONIC NAMEPERIPHERAL REGISTERADDRESS
PORT_APORT A OUTPUT REGISTER0
PORT_BPORT B OUTPUT REGISTER1
PORT_C (**)PORT C OUTPUT REGISTER2
PWM_COUNTTIMER/PWM COUNTER Value3
PWM_RELOAD (*)PWM/TIMER RELOAD Value4
not used5
not used6
not used7
not used8
TRIAC_COUNTTRIAC DRIVER COUNTER Value9
(*)Used if Peripheral has beenprogrammed inPWM Mode (**) Not used onST52x400F/440F/441Fversions
24/94
2.3 Fu zzy Computation
ST FIVE’s Fuzzy main features are:
■ Up to 8 Inputs with 8-bit resolution;
■ 1 Kbyte of Program/Data Memory available to
store more than 300 to Membership Functions
(Mbfs) for each Input;
■ Up to 128 Outpu ts with 8-bit resolution;
■ Possibility to process fuzzy rules with an
UNLIMITED number of antecedents
■ UNLIMITED number of Rules and FuzzyBlocks.
The limits on the number of Fu zzy Rules and
fuzzy Blocks are only related to the program memory size.
2.3.1 Fuzzy Inference .
The block diagram illustrated in Figure 2.7
describes the different steps performed during a
fuzzy algo rithm. The ST FIVE Core allows the
implementation of a MAMDANI type fuzzy inference with crisp consequents. Inputs for fuzzy
inference are stored in 8 dedicated Fuzzy input
registers. The instruction LDFR is used to set the
input fuzzy registers with values stored in the Register File. The result of a fuzzy inference is stored
directly in a location of the Register File.
ST52T400/T440/E440/T441
Figure 2.6 Alpha Weight Calculation
1
ij
α
2.3.2 Fuzzyfication Phase.
In this phase the in tersection (alpha weight)
between the input values and the related Mbfs is
performed (Figure 2.6).
8 Fuzzy input regist ers are available for fuzzy
inferences.
After loading the input values by using the LDFR
assembler instruction, the user can start fuzzynference by using the assembler instructionFUZZY.
During fuzzyfication: input data is transformed in
the activation level (alpha weight) ofthe Mbfs. i
j-th Mbf
i-th INPUT VARIABLE
Input Value
Figure 2.7 Fuzzy Inference
FUZZYFICATION
Input Values
11
1m
INFERENCE
n1
nm
PHASE
1
2
DEFUZZYFICATION
N rules -1
Nrules
Output Values
25/94
ST52T400/T440/E440/T441
X
2.3.3 Inference Phase.
The Inference Phase manages the alpha weights
obtained during the fuzzyfication phase to c ompute the truth value (
Ω) for each rule.
This is a calculation of th e maximum (for the OR
operator) and/or minimum (for the AND operator)
performed on alpha values according to the logical
connectives of fuzzy rules.
Several conditions may be linked together by linguistic con nec tive s AND/OR, NOT operator and
brackets.
The truth value ω and the related output singletonmove t o the Defuzzyfication phase in order to
complete the inferenc e calculation.
Figure 2.8 Fuzzyfication
IF
INPUT 1
1
IF
INPUT 1
1
IS X1 OR
X1
IS X1 AND
X1
Input 1
Input 1
INPUT 2
α2
OR = Max
INPUT 2
α2
IS X2 THEN .......
X2
Input 2
IS X2 THEN ......
X2
Input 2
Figure 2.9 Output Membership Functions
i0
j-th Singleton
ij
X
i-th OUTPUT
in
1
ω
ij
ω
i0
ω
in
0
X
2.3.4 Defuzzyfication.
In this phase the output crisp values are determined by implementing the conseq uent part of the
rules.
Each consequent Singleton X
weight values ω
, calculated by the Fuzzy Infer-
i
is multiplied by its
i
ence Unit, in order to compute the upper part of
the defuzzification.
Each output value is deduced from the consequent crisp values (X
) by carrying out the follow-
i
ing defuzzification formula:
where:
N
Xijω
j
N
∑
j
ij
ω
ij
Y
=
i
∑
--------------------- -
i = 0,1 ident ifies t he current output variable
N = number of the active rules on the current output
=weight of th e j-t h singleton
ω
ij
Xij = abscissa of the j-th singleton
Fuzzy outputs are stored in the RAM location i-th
specified in the assembler instruction OUT i.
26/94
ST52T400/T440/E440/T441
2.3.5 Input Membership Function.
ST FIVE allows the management of triangular
Mbfs. In order to define an Mbf, three different
types of data must be stored on the Program/Data
Memory:
the vertex of the Mbf: V;
the length of the left semi-base: LVD;
the length of the right semi-base: RVD;
In order to reduce the size of the memory area
and the computational effort the v ertical dimension
of the vertex is set to 15 (4 bits).
By using the previous memorization method different kinds of triangular Membership Functions ma y
be stored. Figure 4.6 illustrates a typical example
of Mbfs that c an be defined in ST FIVE.
Each Mbf is then defined storing 3 bytes in the first
1 Kbyte of the programmemory.
The Mbf is memorized by using the following
instruction:
MBF n_mbf lvd v rvd
where
n_mbf identifies Mbf, l v d, v, and rvd, which are the
parameters that describe the Mbf’s shape.
2.3.6 Output Singleton.
ST FIVE uses a particular kind of membership
function called Singleton for its output variables. A
Singleton doesn’t have a shape, like a traditional
Mbf, and is characterized by a single point identified by the coup le (X, w), where the w is calculated by the Inference Unit as described before.
Often, a Singleton is simply identified with its Crisp
Value X.
2.3.7 Fuzzy Rules.
Rules can have the following structures:
if A op B op C...........then Z
if (A op B) op (C op D op E...)...........then Z
where op is one of the possible linguistic operators (AND/OR)
In the first cas e the rule operators are managed
sequentially; in the second one, the priority of the
operator is fixed by the brackets.
Each rule is codified by using an instruction set,
the inference time for a rule with 4 antecedents
and 1 consequent is about 3 microseconds.
Figure 2.10 Mbfs Parameters
15
0
15
w
0
V
LVDR VD
X
Figure 2.11 Example of valid Mbfs
Input M bf
Input V ariable
Output S ingleton
Output Variable
27/94
ST52T400/T440/E440/T441
The assembler Instruction S et, which manages fu zzy instructions is reported in the following table:
Table 2.4 F uz z y Instruction Set
InstructionDescription
MBF
n_mbf Ivd v rvd
LDP
nm
Stores the Mbf
Fixes the alpha value of the inputnwith the Mbfmand stores it in internal registers
n_mbf
with the shape identified by the parameters
Ivd,v
and
rvd
nm
LDN
FZAND
FZOR
LDKStores the result of the last Fuzzy operation executed in internal registers
SKM
LDMCopies the value of register M in the data stack
crisp
CON
OUT
n_out
FUZZYStarts the Fuzzy algorithm
Calculates the complementary alpha value of the inputnwith the Mbfm. and stores the
result in internal registers
Implements the Fuzzy operation AND between the last two values stored in internal
registers
Implements the Fuzzy operation OR between the last two values stored in internal registers
Loads the result of the last performed Fuzzy operation (stored in the temporary register
K) in the temporary buffer M.
Multiplies the
Performs Defuzzyfication and stores the currently Fuzzy output in the RAM
crisp
value with the last ω weight
n_out
location
28/94
ST52T400/T440/E440/T441
Example 1:
IF Input
is codified by the foll owing instructions:
LDN 1 1calculates the NOT α value of Input
LDP 4 12fixes the α value of Input
FZANDadds the NO T α and α val ues obtained with the operations LDN1 1 and LDP 4 12
LDKstores th e r es ult of the operation FZAND in internal registers
LDP 3 8fixes the α value of Input
FZORimplements the operation OR between the results obtained with the operations LDK and
LDP
CON crisp
Example 2, the priority of the operat or is fixed by the b rackets:
IF (Input
LDP 3fixes the α value of Input3 with Mbf1 and stores the result in internal registers
LDN 4 15calculates the NOT α value of Input
FZANDadds NOT α and α v alues obtained with the operations LDP 3 1 and LDN 4 15 SKM
LDP 1 6fixes the α value of Input
LDN 2 14calculates the NOT α value of Input
FZORimplements the operation OR between the α and NOT α values obtained with the two previ-
LDKstores th e r es ult of the operation OR in internal registers
LDMcopies the value of the memory register M in internal registers
FZORimplements t he operation OR between the last two values stored in internal registers (LDK
CON crisp
IS NOT Mbf1AND Input4is Mbf12OR Input3IS Mbf8THEN Crisp
1
with Mbf1and stores the result in internal registers
1
with M12and stores the result in internal registers
4
with Mbf8and stores the result in internal registers
3
multiplies the result of the last Ω operation with the crisp value Crisp
1
IS Mbf1AND Input4IS NOT Mbf15)OR(Input1IS Mbf6OR Input6IS NOT Mbf14)THENCrisp
3
with Mbf15and stores the res ult in internal registers
4
1
1
stores the result of the operation FZAND in internal registers
with Mbf6and stores the result in internal registers
1
with Mbf14and stores the result in internal registers
6
ous operations (LDP 1 6 and LDN 2 14)
and LDM)
multiplies the result of the last Ω operation with the crisp value Crip
2
2
2
At the end of the fuzzy rul e, by using the instruction OUT RAM_reg, a byte is written. Afterwards, the control of the algorithm goes returns to the CU.
29/94
ST52T400/T440/E440/T441
2.4 Arithmetic Logic Unit
ST52x400/440/441 supplies 46 instructions that
perform comp utations and control the device.
Computational time required for each instruction
consists of one clock puls e for each Cycle plus 2
clock pulses for t he decoding phase. Total computation time for each instruction is reported in Table
2.5
The ALU of the ST52x400/440/441 can perform
multiplication (MULT) and division (DIV). Multiplication is performed by using 8 bit operands storing the result in 2 registers (16 bit values).
Division is performed between a 16 bit dividend
and an 8 bit divider, the result and the remainder
are stored in two 8-bit registers.
WARNING:
If the LSB of the multiplication result
is 0, the Zero flag is set although the result is not
0.
2.4.1 Addressing Modes.
ST52x400/440/441 instructions allow the following
addressing modes:
Inherent: this instruction type does not require an
operand because the opcode specifies all the
information necessary to carry out the instruction.
Examples: NOP, RET.
Immediate: these instructions have an operand a s
a source immediate value. Exampl es: LDRC,
PGSET.
Direct: th e operands of these instructions are
specified wi th the d irect addresses. The operands
can refer, accordi ng to the opcode, to addresses
belonging to the different addressing spaces.
Example: SUB, LDRE.
Indirect: data addresses tha t are required are
found in the locations specified as operands. Both
source and/or destination operands can be
addressed indirectly. The operands can refer,
(according to the opcode) to a ddres ses belonging
to different addressing spac es . Examples: LDRE
(reg1),(reg2).
2.4.2 Instruction Types.
ST FIVE supplies the following instruction types:
■ Load Instructions
■ Arithmetic and Logic Instructions
■ Jump Instructions
■ Interrupt Management Instructions
■ Control Instructions
The instructions are listed in Table 2.5, Table 2.6
and Table 2.7.
- flag not affected
regx, regy: Register File addresses
memx, memy: Program/Data Memory addresses
confx, confy: Configuration Registers addresses
outx: Output Regis ters addresses
inpx: Input Registers addres s es
const: constant value
fuzzyx: Fuzzy Input Register
addr: Program instructions address
Figure 2.12 Multiplication
RAM
0
1
2
i
j-1
j
j+ 1
253
254
255
REG. jREG. i
LSB
X
16Bit
MSB
Figure 2.13 Division
253
254
255
REG. jREG. j+1
REMAINDERQUOTIENT
i-1
i+1
j-1
j
j+1
RAM
0
1
2
i
:
REG. i
32/94
ST52T400/T440/E440/T441
3 EPROM PROGRAMMING
EPROM memory provides an on-chip user-programmable non-volatile memory, which all ows fast
and reliable storage of user data.
EPROM memory can b e locked by the user. In
fact, a memory location, called Lock Cell, is
devoted to lock t he EPROM and to prevent
Table 3.1 EPROM Control Register
OPERATIONREGISTER VALUE
Stand By
Memory
Reading / Verify
Memory Unlock and
Lock Status Reading
Memory
Writing
Memory
Lock
ID CODE
Writing
Memory Lock Status
Reading / Verify
0
1
2
3
4
5
9
memory reading. A software id entifica tion code
(max 64 bytes), called ID CODE may also be written in order to distinguish whi ch software version
is stored in the memory.
There are 64 kbits of memory space with an 8-bit
internal parall elism (8 kbytes) addressed by a 13bit bus. The data bus is of 8 bits.
Memory has a double supply: V
12V±5% in Programming Phas e or to V
Working Phase. V
is equal to 5V±10%.
DD
is equal to
PP
SS
during
TheST52x400/440/441EPROM m emory is
divided into three main blocks (see Figure 3.1):
•
Interrupt Vectors memory block
(3 through 14)
contains the addresses for the interrupt routines. Each address is composed of t hree
bytes.
•
Mbfs Setting memory block
(15 through 1024)
contains the c oordinates of the vertexes of
every Mbf defined in the program. If this part of
the memory is not used to s tore the M bfs setting, it can be use to store the instruction set on
the user program.
•
The Program Instruction Set mem ory block
(1024 t hrough 8191) contains the instruction
set of the us er program.
ID CODE
Reading / Verify
10
Figure 3.1 Program Memory Organization
2000h
PROGRAM INSTRUCTIONS
AND PERMANENT DATA
0400h
PROGRAM INSTRUCTIONS
AND PERMANENTDATA
0015h
0003h
0000h
MEMBERSHIP FUNCTIONS
PARAMETERS
INTERRUPT VECTORS
RESET VECTOR
33/94
ST52T400/T440/E440/T441
O
RYVERIFYMAR
GIN
E
ATA
A
TADATA
O
The locati ons 0, 1 and 2 contain the jump instruction to the first code line. This instruction is automatically inserted by the Assembler tool. The
operations that can be performed on EPROM during the Programming Phase are: Stand By, Memory Writing, Reading and Verify/Margin Mode,
Memory Lock, IDCode Writing and Verify.
The operations above are managed by using the
4-bit EPROM Control Register. The reading phase
is executed with V
Margin Mode phase needs V
=5V±5%, while the verify/
PP
= 12V±5%. The
PP
Blank Check must be a reading operation with
=5V±5%.
V
PP
Table 3.1 illustrates the EPROM Control Register
codes used to select the operation. Programming
of the EPROM Control Register is described
below.
3.1 EPROM Programming Phase Procedure
Programming mode is selected by applying
12V±5% voltage or 5V±5 % voltage to the V
PP
pin
and setting the RESET pin =Vss
If the V
voltage is 5V±5% only reading may be
PP
performed.
RST_ADD (PB0), INC_ADD (PB1), RST_CONF
(PB2), INC_CONF (PB3) and PHASE (PB7) are
the control signals applied during Programming
Mode.
The signals RST_ADD, RST_CO NF and P HA SE
are active on level, the others are active on rising
edge.
The signals RST_AD D a nd PHASE are active low,
signal on RST_CONF is active high.
Data in/out digital signals are t rans ferred through
thepinsofPortA.
The memory may be locked by means of the
Memory Lock Status flag, that is used to enable
EPROM operations.
If Memory Lock Status flag is 1 all EPROM operations are enabled, otherwise, it is only pos sible to
read (and verify) the OTP code and the Memory
Lock Status flag.
Only If EPROM is not locked by means of Lock
Cell (see paragraph EPROM Lo cki ng), may
EPROM operations be enabled, changing the
Memory Lock Status flag from 0 to 1.
The signal RST_ADD (PB0) resets the memory
address register and the Memory Lock Status flag.
Therefore, when the R ST _A DD becomes high,
the memory must be unlocked in order to read or
write.
The signal RST_CONF (PB2) resets the EPROM,
Figure 3 .2 EPROM Programming Timing
D
100nS
DATA
OUT
PA(0:7)
RST_ADD
RST_CONF
INC_ADD
INC_CONF
PHASE
MEMORY UNLOCKMEMORY WRITING
DATAD
DATA
LOCATION ADDRESS =1
DATA
IN
UT
10
S
µ
MEM
OUT
MOD
34/94
ST52T400/T440/E440/T441
INC_ADD (PB1) signal increments the memory
address.Control Register. When RST_CONF is
high, the DATA I/O Port A is in output, otherwise it is always in input.
The si gnal applied on INC_CONF (PB3) i nc rements the EPROM Control Register value. To
select the operation it must be provided as many
signal edges as the v alue to be writte n in the reg ister (see Table 3.1).
The signal on PHASE (PB 7) validates the operation selected by means of the EPROM Control
Register value.
3.1.1 E PROM Operati on. In order to execute an
EPROM operation (s ee Table 3.1), t he corresponding identification value must be loaded in
the EPROM Control Register. The signal timing is
the following: RST_ADD= high and PHASE= high,
RST_CONF changes f r om low to high level, to
resettheEPROMControlRegister,and
INC_CONF signa l generates a number of po sitive
pulses equal to the value to be loaded. After this
sequence, a negative pulse of the PHASE signal
will vali date the selected ope ratio n. The minimum
PHASE signal pulse width must be 10 µsforthe
EPROM Writing O peration and 100 ns for the others.
When RST _CONF is high, the DATA I/O Port A is
enabled in output and the reading/verify operat ion
results are available.
After a writing operation, when RST_CONF is
high, Port A is in output without valid data.
3.1.2 E PROM Locking. The Memory Lock operation, which is identified with the number 4 in the
EPROM Control Register, writes “0" in the Memory Lock Cell.
At the beginning of an External Operation, when
RST_ADD signal changes from low level to high
level, the Memory Lock Status flag is “0", therefore
it is necessary to unlock it before proceeding.
In order to unlock the Memory Lock Status flag the
operation, which is identified with t he numbe r 2 in
the EPROM Control Register must be executed
(see Figure 3.2).
The Memory Lock Status flag can be c hanged.
Therefore, after a Memory Lock operation, external operations cannot be executed except reading
(or verify) the OTP Code and the Memory Lock
Status.
3.1.3 EPROM W riting. Whenthe memory is
blank, all the bits are at logic level “1". The data is
introduced by programming only the zeros in the
desired memory location; however, all input data
must contain both ”1” and “0". The only way to
change “0" into ”1” is to erase t he whole memory
(by exposure to UV light) and reprogram it.
The memory is in Writing mode when the EPROM
Control Register value is 3.
The V
voltage must be 12V±5%, with stable
PP
data on the data bus PB(0:7). The signals timing is
the following (see Figure 3.2):
1) RST_ADD and RST_CONF change from low to
high level,
2) two pulses on INC_CONF signal load the Memory Unlock operation code,
3) a negative pulse (100 ns) on the PHASE signal
validates the Memory Unlock operat ion,
4) a negative pulse on RST_CONF signal resets
the EPROM Control Register,
5) three positive pulses on INC_CONF load the
Memory Writing operation code,
6) a train of positive pulses on INC_AD D signal
increments the memory location address up to the
requested value (generally this is a sequential
operation and only one pulse is used),
7) a negative pulse (10 µs) on the PHA S E s ignal
validates the Memory Writing operation.
3.1.4EPROM Reading/Verify Margin Mode.
ThereadingphaseisexecutedwithV
instead of veri fy phase that needs V
=5V±5% ,
PP
=12V±5%.
PP
The Memory Verify operation is available in order
to verify the co rrectness of the data written. The
Memory Verify M argin Mode operation may be
executed immediately after the writing of eac h
byte and in this case (see Figure 3.2):
1) one positive pulse on RST_CONF signal res ets
the Control Regist er, if it was not already reset
2) one positive pulse on INC_CONF loads the
Memory Reading/Verify operation code,
3) one negative pulse (100 ns) on the PHASE signal validates the Memory Reading/Verify operation,
4) a negative pulse on RST_CONF s ignal puts in
the PB (0:7) port the value stored in the actual
memory address and resets the EPROM Control
Register.
Then, if any error in w riting occurred, the user has
to repeat the EPROM writing.
35/94
ST52T400/T440/E440/T441
3.1.5 Stand by Mode. E PROM has a standby
mode which reduces the active current from 10mA
(Programming mode) to less than 100 µA. Memory is placed in standby mode by setting P HASE
signal at high level or when the EPROM Control
Register value is 0 and PHASE signal is low.
3.1.6 ID code. A software identification code,
called ID code may be written to di stinguish which
software version is stored in the memory.
64 Bytes are dedicated to store this code by using
the address values from 0 to 63.
The ID Code may be read or verified even if the
Memory Lock Status is “0".
The signals timing is the same as that of a normal
operation.
3.2 Eprom Erasure
Thanks to the t rans parent window available i n the
CDIP28W package , its memory contents may be
erased by exposure to UV light.
Erasure begins when the device is expose d to
light with a wavelength shorter than 4000Å. It
should be noted that sunlight, as well as some
types of artificial light, includes wavelengths in the
3000-4000Å range which, on prolonged expos ure,
can cause erasure of memory contents. It is thus
recommended that EPROM devices be fitted with
an opaque label over the window area in order to
prevent unintentional eras ure.
The recommended erasure procedure f or EPROM
devices consists of exposure to short wave UV
light having a wavelength of 2537Å. The min imum
recommended integrated dose (intensity x expo-
sure time) for compl ete erasure is 15Wsec/cm
This is equi v alent to an erasure time of 5-10 minutes using a UV source having an intensity of
12mW/cm
2
at a distance of 25mm (1 inch) from
the device window.
2
.
36/94
4 INTERRUPTS
IAC/FI
/
P
NT_EX
T15161718
9
0INT_T
RIAC/PR
T
NTER
R
S
R
T
I
O
The Cont rol Unit (CU) responds to peripheral
events and external events v ia its interrupt channels.
When such an events occur, if the related interrupt
is not mas k ed and acc ording to a priority order,
the current program execution can be suspended
to allow the CU to execute a specific response
routine.
Each interrupt is associated with an interrupt vector that contains the memory addres s of the
related interrupt service routine. Each vector i s
located in t he Program Space (EPROM Memory)
at a fixed address (see Interrupt Vectors Figure
4.2).
4.1 Interrupt Operation
If there are pending interrupts at the end of an
arithmetic or logic instruc tion, the one with the
highest priority is passed. Passing an interrupt
means to store the arithmetic flags and the current
PC in the stack and execute the associated Interrupt routine, whose address is l oc ated in three
bytes of the E PROM memory location between
address 3 and 20.
The Interrupt routine is perform ed as a normal
code checking, at the end of eac h instruction, if a
higher priority interrupt has to be passed. An Interrupt request with the higher priority stops the
lower priority Interrupt. The Program Counter and
the arithmetic flags are stored in the stack.
With the instruction RETI (Return from Interrupt)
the arithmetic flags and Program Counter (PC) are
restored from the t op of the stack, which was previously described in Section 2.2.1.
An Interrupt request cannot stop fuzzy rule processing, but this is passed o nly after the end of a
fuzzy rule or at the end of a logic, or arithm eti c
instruction.
REMARK:
A fuzzy routine can be interrupted only
in the Main program. Wh en a Fuzzy function is
running inside another interrupt routine an interrupt request can cause side effects in the Control
Unit. For this reason, inorder to use a Fuzzyfunction inside an interrupt routine, the user MUST
include the Fuzzy function between an UDGI
(MDGI) i nstruction and and UEGI (MEGI) instruction (see the following paragraphs), in order to disable the interrupt request during the execution of
the fuzzy function.
ST52T400/T440/E440/T441
Figure 4.1 Interrupt Flow
NORMAL
PROGRAM
FLOW
I
UPT
ERVICE
OUTINE
INTERRUPT
RETI
INS
RUCT
N
Figure 4.2 Interrupt Vectors Mapping
0
1
ESE
2
3
4
INT_AC
5
6
7
8
9
10
11
12
13
14
1
2
NT_TIMER
INT_TR
INT_TRIAC/R
I
WM
INTERRUPT
VECTORS
Figure 4.3 Global Interrupt Request Generation
Global Interrupt
Pending
Global I nterrupt
Request
User Global
Interrupt Mask
Macro Global
37/94
ST52T400/T440/E440/T441
4.2 Global Interrupt Request Enabling
When an Interrupt occurs, it generates a Global
Interrupt Pending (GIP), which can be m as k ed by
software. After a GIP, a Global Interru pt Request
(GIR) will be generated a nd an Interrupt Service
Routine associated to the interrupt with higher priority will start. I n order to avoid possibl e conflicts
between interrupt masking set in the main program, or inside macros, the GIP is masked
through the User Global Interrupt Mask or the
Macro Global Interrupt Mask (see Figure 4.3).
UEGI/UDGI instruction switches the User Gl obal
Interrupt Mask on/off, enabling/disabling the GIR
for the main program.
MEGI/MDGI instructions switches the Macro Global Interrupt Mask on/off in order to ensure t hat
the macro will not be broken.
4.3 Interrupt Sources
ST52x400/440/441 manages interrupt s ignals
generated by the interna l peripherals (PWM/
TIMER, TRIAC Driver and Analog Comparator) or
deriving from t he External Interrupt on pin PA7.
The External Interrupt can be programmed to be
active on the risin g or f all ing edge of INT/PA7 signal by settin g the PEXTINT b it of the Configuration Register to0.
WARNING:
interrupt request is generated.
Each peripheral ca n be programmed in order to
generate the associated interrupt; further details
are described in t he related chapter.Configuration
Register 0 is also used to enable/disable the
Brown-Out (see the related chapter).
Changing the interrupt priority an
Table 4.1 Configuration Register 0
Description
BitNameValueDescription
0
0MSKE
1
0
1MSKAC(*)
1
0
2MSKTM
1
0
3MSKTRF
1
0
4MSKTRR
1
External Interrupt
Masked
External Interrupt
Not Masked
Analog
Comparator
Interrupt
Masked
Analog
Comparator
Interrupt Not
Masked
PWM/TIMER
Interrupt
Masked
PWM/TIMER
Interrupt
Not Masked
TRIAC Falling
Edge Interrupt
TRIAC Falling
Edge Interrupt
Not Masked
TRIAC Rising
Edge Interrupt
Masked
TRIAC Rising
Edge Interrupt
Not Masked
4.4 Interrupt Maskability
The interrupts can be masked by configuring the
Configuration Register 0 by me ans of an LDCR or
an LDCE instruction. The interrupt is enabled
when the bit ass oc iated to the mask interrupt is
“1". V icev ersa , when the bit is ”0", the interrupt is
masked and is kept pending.
For example:
LDRC 10,6(loads the cons tant 6 in the RAM
Register 10)
LDCR 0,10(sets REG_CONF0 with the value
stored in RAM Register 10)
the result is REG_CONF0=00000110, enabling
the interrupts coming from the Anal og Comparator
(INT_AC) and from the PWM/TIMER (INT_PWM/
TIMER).
MSKE: Ex t. Int.
MSKAC: An. Comp . Int.
MSKTM: Timer Int.
MSKTRF: Tri ac Fall. Int.
MSK TRR: Triac Ris. Int.
MSKTRP: Triac Pulse I nt.
PEXTINT: Ext. Int. Ris/Fall.
MSKBR: Brown Out En.
39/94
ST52T400/T440/E440/T441
Figure 4.5 Interrupt Configuration Registers 17 and 18
Inte rrup tsPriority
REG_CON F18
D10D11D12D13D14D15
4.5 Interrupt Priority
Seven priority levels are available: level 6 has the
lowest priority, level 0 has the highest priority.
Level 6 is ass oc iat ed to the Main Program, levels
5 to 1 are programmable by means of the priority
registerscalledREG_CONF17and
REG_CONF18; whereas the higher level is
related to the External Interrupt (INT_EXT).
PWM/Timer, TRIAC/P WM and Analog Block are
identified by a three-bit Peripheral Code (see
Table 4.2); in order to set the
user must write t he peripheral label
INT
The Interruptprioritymust beset at the
beginning of the main progra m, because at the
RESET REG_CONF1=’00000000’, this condition
couldgeneratewrongoperations.F urthe r,
changing the priority levels must be avoided in
interrupt service routines.
When a source provides an Interrupt reques t, and
the request processing is also enabled, the CU
changes the norm al sequential flow of a program
by transferring program cont rol to a selected service routine.
When a n interrupt occurs the CU executes a
JUMP instruction to the address loaded in the
related location of the Interrupt Vector and the
flags are saved.
When the execution ret urns to th e original pro-
ST52T400/T440/E440/T441
gram, the flags are restored and the program continues from the instruction immediately f ollowing
the interrupted instruction.
4.6 Interrupts and Low power mode
All interrupts allow the proc es so r to leave WAIT
mode. Only an External Interrupt request allows
the processor to leave HALT mode: if the interrupt
is masked, the related interrupt routine is not serviced and the program continues from the first
instruction after the HALT instruction.
4.7 Interrupt RESET
When an interrupt reques t is sent but the interrupt
is masked, it isn’t service d and remains pending,
so that when t he interrupt is enabled it is serviced
immediately. In order to avoid this from happening, the pending interrupt request can be res et
with the instruction RINTj, wh ich resets the
interrupt
j
-th wherejidentify the peripherals as
described in the follo wing table (see Table 4.4).
The assembler instruction:
RINT 2
Resets the TRIAC/PWM_F interrupt.
WARNING:
If an interrupt is reset, with the RINT
instruction within its own interrupt routine, the
priority level of the interrupt becomes the lowest
and the routine can be i mmediately interrupted by
a lower priority interrupt request.
Table 4.4 RINT Instruction Code
Peripheral NameValue
Analog Comparator (*)0
PWM/TIMER1
TRIAC/F2
INT_TRIAC/R3
INT_TRIAC/P4
External Interrupt5
(*) Not Used in ST52x400 devices
Figure 4.6 Example of a sequence of Interrupt Requests
PRIORITY
LEVEL
0
1
2
3
4
5
INT2INT0INT4INT1INT3
INT0
INT1
INT2
INT2
INT2
INT3
INT4
6
MAIN PROGRAM
MAIN PROGRAM
41/94
ST52T400/T440/E440/T441
K
5 CLOCK, RESET & POWER SAVING MODE
5.1 Clock System
The ST52x400/440/441 Clock Generator module
generates the internal clock for the internal Control Unit, ALU and on-chip peripherals and is
designed to require a minimum of external components.
The ST52x400 /44 0/441 oscillator circuit generates an internal clock signal with the s ame period
and phas e as at the OSCin input pin. The maximum frequency allowed is 20 MHz.
The system clock may be generated by using
either a quartz crystal, ceramic resonator (CERALOC), or an external clock.
Figure 5.1 Oscillator Connections
The different c lock generator options connection
methods are illustrated in Oscillator Connections.When an external clock is used, it must be
connected to the pin OSCin while OSCout should
be left floating.
The crystal oscillator start-up time is a function of
many variab les: crystal parameters (es pecially
R
), oscillator load capacitance (CL), IC parame-
s
ters, environment temperature, supply voltage.
It must be observed that the crystal or ceram ic
lead and circuit connections mu st be as short as
possible. Typical values for CL1, CL2 are 10pF for
a20MHzcrystal.
CRYSTAL CLOCKEXTERNAL CLOCK
ST52X440
OSCinOSCout
Cl1
10pF
Cl2
10pF
ST52X440
OSCin
CLOC
INPUT
OSCout
42/94
ST52T400/T440/E440/T441
N
ALRESE
T
E
SETBROWN-O
T
5.2 Reset
There are four sources of Reset:
- RESET pin (external source)
- WATCHDOG (internal source)
- POWER ON Reset (Internal s ourc e)
- BROWN OU T Reset (Internal source)
When a Reset event happens, all the registers are
set to the reset value and the user program
restarts from the beginning.
5.2.1 External Reset.
The Reset pin is an input pin. An internal res et
does not affect this pin.
A Reset signal originated by external sou rces is
recognized istantaneously. The RE SET pin may
be used to ensure Vdd has risen to a point where
the MCU can operat e correctly before the user
program is run. In working mode the R es et must
be set to ‘1’ (see Table 1.1)
5.2.2 Reset Operation.
The duration of a RESET c ondition is fixed at
1.000.000 internal CPU clock cycles (or 4096 in
case of BOD).
Following a Power-On Reset ev ent , or after exiting Halt Mode, a 1.000.000 CPU clock cycle delay
period is initiated in order to allow the oscillator to
stabilize and to ensure that recovery has taken
place from the Reset state.
A Pull up resistor of 100 KΩ guarantees that
RESET pin is at level “1” when no HALT or
Power-On events occurred.
If an external resistor is connected to the RESET
pin a minimum value of 10KΩ must be used.
After a RESET procedure is completed, the core
reads the instruction stored in the first 3 bytes of
the EPROM, w hich contains a JUMP instruction to
the EPR OM address containing th e first instruction of the user program. The Assembler tool automatically generates thi s J ump instruction with the
first instruction address.
5.2.3 Power-on Reset (POR).
A Power-On Reset is generated by an on-chip
detection circuit. This circuit ensures that the
device is not started until Vdd has reached the
nominal level of 2.3V and allows the c lock oscillator to stabilize.
Once 2.3V are reached, the Power-On circuit generates an internal RST s ignal that releases the
internal reset to the CPU and invokes a delay
counter of 1.000.000 CPU clock cycles, during
which the device is kept in RESET after Vdd has
risen.
A correct operation of Power-on detector is guaranteed if the slew rate of Vdd is 0.05 V/ms.
Note:
The power s upply must fall below 0 V for
the internal POR circuit to detec t the next rise of
Vdd.
At power on the POR is enabled by default.
POR is des igned exclusively to cope with powerup conditions and should not be used to detect a
drop in the power supply voltage, fo r which the
Brown-out Detector can be used instead.
Figure 5.2 Reset Block Diagram
RESET
Vdd
POWER-ON
RESET
Vdd
Vdd
BROWN-
OUT
WATCHDOG
COUNTER x
1.000.000
COUNTER x
4096
WA
CHDOG R
UT RESE
INTER
T
43/94
ST52T400/T440/E440/T441
5.2.4 Br ow n-Ou t Detector (BOD).
The on-chip Brown-Out Detector circuit prevents
the processor from f alling into an unpredictable
state if the power supply drops below a c ertain
level.
When Vdd drops below the Brown-out detection
level, the B rown-out causes an internal processor reset RST tha t remains active as long as Vdd
remainsbelow the Brown-Out Trigger Level.
Brown-Out resets the entire device except the
Power-on Detector and the Brown-out itself.
Enabling/disabling the B row n-out detector can be
performed by setting the software of the c ont rol bit
BOD of REG_CONF0 (Table 4.1).
When Vdd increases above the Trigger Level, the
Brown-Out reset is turned off after a delay of 4096
CPU clock cycles, which ensures stabilization of
the oscillator.
The Brown-Out falling voltage level typical value is
3.8V and the corresponding rising voltag e activation level is 4.1V.
A minimu m hysteresis of 250mV for the trigger is
guaranteed for spike free brown-out detection.
Brown-Out circuit detects a drop if V dd voltage
stays below the safe threshold for longer than 100
Clock cycles before activation/deactivation of the
Brown-Out in orde r to filter voltage spikes.
Brown-Out function is disabled by default and is
not active when in HALT mode.
5.3.2 Halt Mode.
Halt mode is the MCU’s lowest power consumption mode, which is entered by executing the
HALT instruction. The internal oscillator is turned
off, causing all internal processing t o be s topped,
including the operations of the o n-chip peripherals.
Halt mode cannot be used when the watchdo g
is enabled. If the HALT instruction is executed
while the watchdog system is enab led, it will be
skipped wi tho ut modifying the normal CPU operations.
TheICUcanexitHaltmodeafteranexternalinterrupt or reset. The oscillator is then turned on and
stabilization time i s provided bef ore restarting
CPU operations. Stabilization time is 4096 CPU
clock cycles after t he interrupt and 1 .000.000 after
the Reset.
After the s tart up delay, the CPU restarts operations by serving the external interrupt routine.
Reset makes the ICU exit from HALT mode and
restart, after the delay, from the beginning of the
user program after the delay.
Warning:
if the External Interrupt is disabled, the
ICU exits from the Halt mode and jumps to the
lower priority interrupt routine.
Figure 5.3 WAIT Flow Chart
Remark:
for higher frequencies, the device needs
Supply Voltage higher than the BOD threshold.
For this reason the BOD cannot work in this range
of frequencies. SeeElectrical Characteristic
Chapter in this Datasheet.
5.3 Power Saving Modes
There are two P ower Saving modes: WAIT and
HALT mode. These conditions may be entered by
using the WAIT and HA LT instructions.
5.3.1 Wait Mode.
Wait mode places the MCU in a low power consumption by stopping the CPU. All peripherals and
the watch dog remain active. During WAIT mode,
the Interrupts are enabled. The MCU will remain in
Wait mode until an Interrupt or a RESET occurs,
whereupon the P r ogram jumps to the interrupt
service routine or, if a RESET occurs, at the
beginning of the user program.
Remark:
44/94
in Wait mode the CPU c lock does’t stop.
Figure 5.4 HALT Flow Chart
ST52T400/T440/E440/T441
HALT INSTRUCTION
YES
HALT INSTRUCTION
SKIPPED
OSCILLATOROFF
PERIPHERALS CLOCKOFF
CPU CLOCKOFF
NO
RESET
YES
OSCILLATORON
PERIPHERALS CLOCKON
CPU CLOCKON
1000000 CPU CLOCK
CYCLES DELAY
NO
WATCHDOG
ENABLED
NO
EXTERNAL
INTERRUPT
YES
OSCILLATORON
PERIPHERALSCLOCKON
CPU CLOCKON
4096 CPU CLOCK
CYCLES DELAY
RESET CPU
AND RESTART
USER PROGRAM
NO
RESTART PROGRAM
SERVICING THE
LOWER PRIORITY
INTERRUPT ROUTINE
EXTERNAL
INTERRUPT
ENABLED
YES
RESTART PROGRAM
SERVICING THE
EXTERNAL
INTERRUPT ROUTINE
45/94
ST52T400/T440/E440/T441
6I/OPORTS
6.1 Introduction
ST52x400/440/441 devices offer f lexible individually programmable multi-func ti onal input/output
lines. Refer to Chapter 1 for specific pin allocations.
21 I/O lines, grouped in 3 different ports, are available for ST52x400G/440G/441G devices:
PORT A = 8-bit ports (PA0 - PA7 pins)
PORT B = 8-b it ports (PB0 - PB7 pins)
PORT C = 5-bit port (PC0 - PC4 pins)
13 I/O lines, grouped in 2 different ports are available for ST52x400F/440F/441F devices:
PORT A = 8-bit ports (PA0 - PA7 pins)
PORT B = 5 -bit ports (PB0 - PB3 and PB7 pins)
These I/O lines can be programmed to provide
Digital Input/Output or Analog Input , or to connect
input/output signals to the on-chip peripherals a s
Alternate Pin Functions.
The input buffers are TTL compatible with Schmitt
Trigger in ports A and C while port B is CMOS
compatible without Schmit t trigger and it is used
for the Analog Inputs.
The output buffer ca n s upply up to 8 mA.
All the port pins of 400/440 devices have an
internal pull-up resistor (22
kΩ). The 441 device
doesn’t have inter nal pull-up resistor. This
pull-up resistor is automatically excluded
when th e pin is configured as Analog Input or,
in MAIN1 and MAIN2 pins,when the Triac
Driver is configured in Phase An gle Partialization or Burst mode.
Each single port pin can be programmed in input
or output or Alte rnate Function, so that in the
same port there can be both input and output pins.
The port pins are write/read in parallel at the same
time: when reading output pins, the port buffer
contents are read; when writing an input pin the
value is written in the buffer.
Each port is configured by u sing Configuration
Registers indicated in Table 6.1. The first is used
to define if a pin is an Input or an Output, t he second defines the Alternate functions.
Table 6.1 I/O Port Configuration Register
PORT APORT B
Reg_Conf 4Reg_Conf 13Reg_Conf 11
Reg_Conf 12Reg_Conf 14
Reg_Conf 11**
(*)
Not available in ST52x400F/440F/441F
PORT C
(*)
(**) Only in ST52x440F/441F
Figure 6.1 Ports A and C Functional Blocks
TO INPUTREGISTER
and PERIPHERALS
FROM PERIPHERAL
FROM OUTPUT REGISTER
FROM CONFIGURATION REGISTER
FROM CONFIGURATION REGISTER
46/94
TTL
Vcc
22 k
PORT A PIN
or PORT C PIN
Figure 6.2 Port B Functional Blocks
ST52T400/T440/E440/T441
Vcc
FROMCONFIGURATION REGISTER
TO INPUT REGISTER
TO A/D CONVERTER
FROM OUTPUT REGISTERS
FROM CONFIGURATION REGISTER
6.2 Input Mode
The input configuration is selected setting the correspondingconfigurationregisterbitin
REG_CONF4, REG_CONF13 and, where applicable, REG_CONF11 (see Paragraph I/O Port
Configuration Registers) to “1”. To use Port A and
B pins as digital input, the corresponding bits in
REG_CONF12 and REG_ CONF14 must be set
according to th e values shown in Table 6.4, Table
6.5 and Table 6.6.
Table 6.2 Input Register and I/O Ports
PORT APORT B
IR 14IR 15IR 16
(*)
Not used for ST52x400F/440F/441F
PORT C
(*)
Table 6.3 Output Register and I/O Ports
PORT APORT B
OR 0OR 1OR 2
(*)
Not used for ST52x400F/440F/441F
PORT C
(*)
Digital input data is automatica lly stored in
22 k
CMOS
PORT B PIN
the Input Registers (see Table 6.2), but the single
bit of the Input Register (IR) c annot be read
directly an d the value in a RAM location must be
copied. Digital data is stored in a RAM location by
using the assembler instruction:
LDRI regx,inpy
Then, each single bit can be examined by using
AND and OR operators with a suited mask value.
6.3 Output Mode
The output pin configuration is selected by set ting
the corresponding configuration registe r bit to “0”
(REG_CONF4, REG_CONF13 and, where applicable, REG_CONF11) (see paragraph I/O Port
Configuration Registers). in order to use Port A
and B pins as digital output, the corresponding bits
in REG_CONF12 and REG_CONF14 must be set
according to the values illustrated in Tables - Port
A - REG_CONF 4, - P ort A - REG_CONF 12 and
Analog Inputs REG_CONF 14.
Digital data is transferred to the related I/O Port by
means of the Output register (see Table 6.3), by
using the assembler instructions LDPE or LDPR
that respec t ively take the value to be transferred
to the ports from EPROM and RAM.
47/94
ST52T400/T440/E440/T441
6.4 Alternate Functions.
Port A and B pins in ST52x 400/440/441 are configurabletobeusedwithdifferentfunctions(Alternate Functions) rel ated to the use of peripherals.
Toconfigure a pin in Alternat e Functi on the rela ted
configuration registers must be set according to
the values shown in Tables - Port A - REG_CONF
4, - Port A - REG_CONF 12 and Analog Inputs
REG_CONF 14.
For example: if pin PA5/TCLK has to be used as
an external PWM/Timer Clock, REG_CONF4[(5)]
bit must be s et to ‘1’.
When the signal is an input of an on-chip
peripheral, the related I/O pin has to be configured in Input Mo de.
When a pin of Port B is used as an Analog Input,
the related I/O pin is automatica lly set in threestate. The analog multiplexer (controlled by the
AnalogComparatorConfigurationR egist er)
switches the analog voltage pres ent on the
selected pin to the common analog rail, which is
connected to the ADC input.
It is recommended that the voltage level or loading
on any port pin not b e changed while conversion
is running. Furthermore, it is recommended not to
have clocking pins located close to a selected
analog pin.
Timer/PWM Alternate Functions
Pins of Port A can be configured to be I/Os of the
on-chip TIME R /PWM of ST52x 400/440/441. The
configuration of these pins is performed by using
ConfigurationRe gistersREG_CONF4and
REG_CONF12 (Tables - Port A - REG_CONF 4
and - Port A - REG_CONF 12).
If a pin has to be a TIMER Input (TSTRT, TCLK,
TRES) the related bit of REG_CONF4 must be set
to “1” and of REG_CONF12 mu st be set to “1”.
If, instead it must be a TIMER Output (TOUT,
TOUTN), REG_CONF12 re lated bit must be set to
“0” and the related bit of REG_CO N F4 be set to
“0”.
TRIAC Driver Alternate Function
When using the on-chip TRIAC, to have the
TRIAC Output on pin PA0, bit REG_CONF12[0]
must be set to “0” and REG_CONF4[0] to “0”.
When a s y nc hronizat ion with the Mains voltage is
necessary, in case either the Phase Angle Partialization or the Burst Modes is chosen, to have
MAIN1 and MAIN2 as Inputs on PortA, it is necessarytosetbits1and2ofREG_CONF4to“1”.
Table6.4 -PortA-REG_CONF4
6.5 I/O Port Configuration Regi sters
The I/O mo de for each bit of the three ports are
selected by using Con figuration Registers 4, 12,
13 and 11 (Table 6.1). The structure of these registers is illustrated in tables - Port A - REG_CONF
4, - Port A - REG_CON F 12, - Port B REG_CONF 13, Analog Inputs REG_CONF 14
and - Port C - REG_CONF 11. Each bit of the configuration registers sets the I/O mode of the
related port pin.
Analog Comparator Inputs
Pins PB0-PB7 for ST52x440G/441G and PB0PB3 and PB7 in ST52x440F/441F can be configured to be Analog Inputs by se tting the related bit
in REG_CONF 14 to “1” (Table 6.7) and the
related bit in REG_CONF13 to “1” (Table 6.6).
These analog inputs are connec ted to the on chip
Analog Comparator.
If the B andGap Reference (BG) is needed as an
Output for ST52x440G/441G REG _CONF13[6]
must be set to “0” and REG_CONF 14[6] to “1”.
(*) Not available in ST52x400xx
(**) Not available in ST52x440F/441F
Table6.8 -PortC-REG_CONF11
BitNameValueRelated Pin
0D0XPC0
1D1XPC1
2D2XPC2
3D3XPC3
4D4XPC4
5D51
6D6not used
7D7not used
X = 0 Pin set as Digital Output
X = 1 Pin set as Digital Input
(*)
(*)
(*)
(*)
(*)
(**)
(*) Not available in ST52x400F/440F/441F
Reset Configuration ‘11111111’
(*)
Not used in ST52x400F/440F/441F
(**)
Must be set to 1
49/94
ST52T400/T440/E440/T441
16b
itTimer
StopCount12bitPre
s
L
K
m
erC
/DC
onfigur
ati
onR
ste
6
543
2
tar
t
ConvertedValu
e
7 ANALOG COMPARATOR (ST52X440/441)
7.1 Analog Module Overview
The ST52x440/441 includes an Analog Compara tor (AC) among its peripherals.
The Analog Comparator is endowed with analog
and digital elements in order t o also allow the user
to make use of it as a single slope Anal og to Digi tal converter. In particular, ST52x440/441 is
endowed with:
■ Analog Comparator;
■ 7 channels analog mux (6 external li nes , 1
internal voltage reference);
■ a current source providing 7 programmable
values;
■ 16 bit Timer with a Capture Register and 12 bit
Prescaler;
The Analog Comparator peripheral can also be
used as a sin gle slope A/D, supplying a ramp signal to the pin CS. The selection of the working
mode, as either Analog Com parator or single
slopeA/Dcanbeperformedviathe
REG_CONF3[(0)] bit.
7.2 Comparator Mode
In Analog Comparator mode, REG_CONF3[(0)] is
set to “0”. The AC inputs are available on the
external pins. The reference signal must be connected to the CS pin, the signal to be compared
goes to the analog input AC0.
When the input becomes lower than the reference, the Analog Comparator output changes to
value “1”. The output can be read on the less significative bit of Input Register 1 AC_CHAN0H
(Table 2.1).
7.3 A/D Converter Mode
To use the Analog Comparator f or A/D Conversion, REG_CONF3[( 0)] bit must be set to “1”.
In A/D Mode eit her the insertion of an external
capacitor to pin CS or the connection to an external signal to generate the reference ramp m ay be
chosen.
In the first case REG_CONF16[(1)] bit must be set
to “0”. The internal current generator, utilized t o
charge the capacitor, provides 7 possible current
values,whichcanbeselectedvia
REG_CONF3[(7:5)]. The current v alues are in the
range between0 to 70µAwithstepof10µA.
The capacitor s hould have a low voltage c oeffi-
Figure 7.1 Analog Peripheral Block Diagram
A/DConfigurationRegisters
7 6 5 43210
6 5 43210
7
AC0
AC1
AC2
AC3
AC4
AC5
NDA
G
Bandgape Ref.=2.5V
CS
C
c.
Ti
-
LK
S
+
Current Sel.
7
A
Vcc
10
egi
rs
50/94
ST52T400/T440/E440/T441
cient for optimum res ults (recommended capacitance values range is 10-1000 nF). The optim um
linearity in conversion can be obtained if t he voltage level on the selected input channel does not
exceed a maximum of 3 V. In the second case, if
anexternalrampgeneratorisused,the
REG_CONF16[(1)] bit must be set to “1”.
The 16 bit Timer, directly triggered by the output of
the Analog Comparator, allows the measurement
of the conversion time that is proportional to the
analog value.
The device clock is divided by an internal 12 bit
Prescaler to generate the appropriate Timer clock
that allows the desired resolution to be obtained
with a reasonable conversion time.
When an appropriate value of the capacitor is
selected, the conversion should be complete
before the full count is reached. A timer overflow
flag is set once the Timer r eac hes its maximum
count value.
Generally, the maximum c onversion time of the A/
D converter depends on the capacitor chosen and
the charge current. The maximum conversion time
can be calculated by using the following f ormula:
must be configured to trigger the signal when it
crosses the compared value from low to h igh
(REG_CONF3[(2)]=0); vice versa, usin g a f alling
ramp, the polarity should be set to trigger the s ignalincrossingfromhightolow
(REG_CONF3[(2)]=1).
When the Ca pacitor is used, it generates a rising
ramp. For this reas on the polarity must be configured t otrigger t hecrossing fromlow to
high(REG_CONF3[(2)]=0).
In order to synchronize the ex tern al ramp signal
and the timer, the ACSTRT and ACSYNC pin
have to be used. The input pin ACSTRT is used to
start the timer when the external ramp is started
(ACSTRT=1). The ACSYNC output pin prov ides
the handshake signal, which (when ACSYNC=1)
furnishes information indicating that the timer is
ready to recei ve the start signal.
If the input signal is too high, the counter may
overflow. When this happen s, bit 0 of the Input
Register 13 AC_STATUS (Table 2.1) is s et to 1
and an interrupt is generated at the end of count.
If the counter is configured in down counting, the
bit is set when the counter goes in underflow.
mum voltage recommended for the input signal,
which is 3 V, and ChargeCurrent is the configured
value of the current for charging the capacitor.
To obtain the desired resolution, the prescaler
value has to be set in accordance to the following
formula:
is the number of bits that should contain the converted val ues. Recommended values
for the resolution are in the range between 8-14
bits.
After the Capacitor is charged, it is discharged in a
number of clock cycles equivalent to (
P
+1) x 410.
When the ex ternal ramp generat or is used, a risingramporafallingrampmaybechosen.Inthis
case, the timer counter should be spec if ied to be
either an up counter (REG_CONF3[(3)]=0) or a
down counter (REG_CONF3[(3)]=1).
By using a rising ram p the Analog Comparator
7.3.1 Operating Modes.
In order to avoi d the errors introduced by the A/D
components drift, a periodic conversion of the
internal reference signals can be performed in
order to calibrate the con verted values. Two different internal voltage references are available:
1) Bandgap voltage, t his reference voltage can
also be used externally for analog signal conditioning.
2) GNDA.
Setting the REG_CONF1[(0)] to “1” the peripheral
1–=
converts the reference signal a fter converting
each analog signal. In order to choose the reference, REG_CO NF3[( 1)] should be configured.
To ensure secure and stable measurements, several measurements on the same channel and
mediating the obtained results are recommended.
The conversion of each single channel may be
repeated up to three t imes by configuring the
REG_CONF1[(7:6)].
The analog multiplexer allows the user to work in
four different modes:
– Single Channel Single Conversion
– Single Channel Multiple Conversions
– Multiple Chann els Single Conversion
– Multiple Chann els Multiple Conversions
51/94
ST52T400/T440/E440/T441
The four m odes are selected by configuring
REG_CONF1[(2)] t o choose among the conversion of a sin gle channel or a sequence of channels and REG_CONF1[(1)] toperformthe
conversion once o r continuously.
REG_CONF1[(5:3)] bits allows the user to choose
the channel to be converted in Single Channel
mode or the last channel to be convert ed (starting
from AC0) in Multiple Channels mode.
To start the c onv ers ion, REG_CONF16[(0)] must
be set to “1” and to “0” to stop it.
Note: in Single conversion modes, the Start bit
REG_CONF16[(0)] must be reset to 0 before
starting another conversion; in Com parator Mode
it must be set to ‘”0”.
The Analog Comparator in A/D Converter Mode
supplies an int errupt source. The interrupt signal
can be generated either after t he end o f the each
channel conversion (REG_CONF3[(4)]= 0) or after.
theendoftheconversionsequence
(REG_CONF3[(4)]=1).
000Current generator off
00110 µA charge current
01020 µA charge current
01130 µA charge current
10040 µA charge current
10150 µA charge current
11060 µA charge current
STRT: Converter St
ADMOD: Capacitor/external ramp
Not used
PRES(11:8): Time
p
(7:0)
e
)
53/94
ST52T400/T440/E440/T441
8 WATCHDOG TIMER
8.1 Functional Description
The Watchdog Timer (WDT) is used to detect the
occurrence of a software fault, usu ally generated
by external interference or by unforeseen logical
conditions, which cause s t he application program
to abandon its normal sequence. The WDT circuit
generates an MCU reset on expiry of a programmed time period (Timeout), unless the program refreshes the WDT befor e the end o f the
programmed time period itself.
16 different time delays can be selected by using
the WDT configuration register REG_CONF2 as
in Table 8.2.
WDT is activated by the assembler instruction
WDTRFR.
At the end of the programmed t im e delay, WDT
starts a reset cycle pulling the reset pin low.
During normal operation, when WDT is active, the
application program has to refresh this peripheral
at regular intervals to prevent an M C U r es et . WDT
refresh is performed by the WDTRFR assembler
instruction.
To stop WDT during the user program executions
instruction WDTSLP has to be u sed.
WDT working frequency is equal to Master Cloc k
frequency divided by a fixed P re scal er with a division factor of 500, to obtain WDT CLK signal that
is used to fix t he WDT Timeout period (Figure
8.1).
Table 8.1 Watchdog Timing range (CLKM=20
MHz)
WDT Timeout period (ms)
min0.025
max234.375
With a M aster Clock of 20MHz, for instance, a
WDT Timeout perio d can be defined between
0.025ms and 234.375ms, depending on WDT
REG_CONF2 values.
Timeout delay values at different Master Clock frequencies can be calculated as the product of WDT
clock number pulses (Table 8.2) by WDT CLK
period (Table 8.4).
Warning: c hanging the REG_CONF2 v alue when
the WDT is active, a W D T reset is generated and
the CPU is restarted. To avoid this side effect, use
the
WDTSLP
instruction before changing the
REG_CONF2.
Figure 8.1 Watchdog Block Diagram
REG_CONF 2
WDTR FR
RESET
PRES CLK = CLK MASTER
WDTSLP
D3
D2
PRESCA LE R
D0D1
WTD CLK
WDT
RESET
GENERATOR
RESET
54/94
ST52T400/T440/E440/T441
8.2 Register Description
WDT Timeout period can be set by setting the first
4 bits of REG_CONF2: this allows 16 different values of WDT Clock pulse number to be defined.
The WDT CLK is derived from the Master Clock
divided by 500. Timeout is then obtained by multiplying the WDT CLK pe riod for the number of
pulsesdefinedinconfigurationregister
REG_CONF2. Table 8.4 illustrates the pulse
length for typical values of Master Clock.
Table 8.3 illustrates the timeout WDT values when
Master Clock is 5 MHz.
ST52x400/440/441 on-chip PW M/TIMER peripherals consist of an 8-bit count er with a 16-bit programmable pres caler that provide a maximum
24
count of 2
(Figure 9.1).
The TIMER has two different working modes:
■ Timer Mode
■ PWM (Pulse Width Modulation) Mode that can
be selected by s et ting register REG_CONF5[7]
bit TMODE.
The Timer has an Autoreload Functi on in PWM
Mode. Its output TOUT is available, with its complementary signal TOUTN on external pins by setting PA6 and PA2 bits of RE G_CONF4 and
REG_CONF12 (see tables - Port A - REG_CONF
4 and - Port A - REG_CONF 12).
TheTIMERcanalsouseanexternalSTART/
STOP signal (Input capture), an external RESE T
and external CLOCK signals: PA4/TSTRT, PA6/
TRES and PA5/TCLK pins. To use TSTRT, TRES,
TCLK external signals the related pins PA4, PA6
and PA5 must be configured in Input Mode by setting registers REG _CONF4 and REG_CONF12
(see table - Port A - REG_CONF 4 and - P ort A REG_CONF 12).
The content of the 8-bit counter of the TIMER is
incremented on the Rising Edge of the 16-bit prescaler out put (PRES COUT) and it can be read at
any instant of the counting phase, which is then
saved in a RAM memory location. The PWM/
Timer Counter value can be read from the Input
Register PWM_COUNT (Input Registers 18, see
Table 2.1). The PWM / Timer Status can be read
from the Input R egister PWM_STATUS (In put
Registers 19. See Table 2.1). This register indicates if the TIMER is in START/STOP (bit 1) and
in SET/RESET bit(0).
Figure 9.1 Timer Peripheral Block Diagram
9.1 Timer Mode
Timer Mode is selected by setting the TxMODE bit
of REG_CONF5[ 7].
The TIMER can receive three signals as inputs:
Timer Clock (TCLK), Timer Reset (TRES) and
Timer Start (TSTRT) (Figure 9.1). Each of these
signals can be generated internally or externally
bysettingTSTR,TRST,TCLKbitsof
REG_CONF7 register as illustrated in Table 9.3.
TMRCLK is the Prescaler output, which increments the Counter value on the rising edge. TMRCLK is obtained from the internal c lock sig nal
(CLKM) or from the external signal prov ided on
the PA5/TCLK pin.
NOTE:
The external clock signal, applied on
TCLK pin, must have a frequency, which is at least
two times smaller than t he internal master clock.
The prescaler output can be selected by setting
PRESC bits of REG _CONF6 register (Table 9.2).
TRES resets the content of the TIMER 8-bit
counter to zero. I t is generated internally by setting the TIRST bit of REG_CONF5(Table 9.1).
TSTRT signal starts and stops the Timer counting
only if the peripheral is configured in Timer mode.
It is generated i nternally by setting the TSTR bit of
REG_CONF5(Table 9.1).
TIMER START/STOP can be provided externally
from the TSTRT pin (Input Capture). In this case,
TSTRT signal allows the ICU to work in two different modes by setting the TESTR configuration bit
of REG_CONF5 register.
LEVEL: When the TSTRT signal is high the Timer
starts counting. When the TSTRT is low the counting stops and the current value is stored in the
PWMCOUNT Input Register.
56/94
CLKM
16-BIT PRESCA LER
BIT 0BIT1BIT 2BIT 3BIT 4
BIT 1BIT2BIT6BIT 4BIT 5BIT 7
BIT3BIT 0
BIT 5BIT14BIT 15
17- 1 MU LTIP LEX ER
TMRCLK
8-BITCO UN TER
PRESCx
TxRES
TxSTRT
Figure 9.2 Timer 0 External START/STOP Mode
ST52T400/T440/E440/T441
start
Level
start
Edge
Reset
Clock
Counted
Value
0110443
2
EDGE: After the reset, on the first T STRT rising
edge, the TIM ER starts counting and, at the next
rising edge, it stops. In this manner, t he period of
an external signal may be measured.
The Timer output signal, TIMEROUT, is a signal
with a frequency equal to the 16 bit-P rescal er output signal, TM RCLK, divided by the Output Register PWM_COUNT value (8 bit) (Output Registers
9, Table 2.3), that is the value to count.
TIMEROUT waveform can be of two types:
type 1:
TOUT waveform equal to a square wave
with a 50% duty-cycle
type 2:
TOUT waveform equal to a pulse signal
with the pulse duration equal to the Prescaler output signal.
Figure 9.3 TIMEROUT Signal Type
Prescout*Counter
Timer Output
Type 1
Type 2
start
stop
stop
start
The Timer output signal waveform type can be
selected by setting the correspondent TM RW bit
of REG_CONF6.
9.2 PWM Mode
PWM working mode is obtained by setting the correspondent TMOD E bit of REG_CONF5 to “1”.
TIMEROUT, in PWM Mode, consists of a signal,
with a fixed period, whose duty cycle c an be modified by the us er.
TIMEROUT signal is av ailable on TOUT pin and
TIMEROUT complementary signal is av ail able on
TOUTN pin, setting the relative bits on PORT A,
REG_CONF12[1] and REG_CONF12[2], to “ 0”
and REG_CONF 4[6] and REG_CONF4[2] to “0”.
The PWM TIMEROUT period can be fixed by setting the 16-bit prescaler output and an initial
autoreload 8-bit counter value stored in the Ou tput
Register PWM_RELOAD, as i llustrate d in Figure
9.4. The Output Register PWM_RELOAD value is
automatically reloaded in the Counter when it
restarts counting.
NOTE:
the Start/Stop and Set/Reset signals
should be moved tog ether in PWM mode. If the
Start/Stop bit is reset during the PWM mode working, the TxOUT signal keeps its status until the
next start.
57/94
ST52T400/T440/E440/T441
Figure 9.4 PWM Mode with Auto Reload
255
compare
value
reload
register
0
PWM
Output
t
Ton
T
The 16-bit Prescaler divides the master clock,
CLKM or the external signal TCLK. The Prescaler
output can be select ed setting the PRESC bit of
REG_CONF6.
NOTE:
The external clock signal, applied on
TCLK pin, must have a frequency that is at least
two times smaller than the internal master clock .
When the Count er reaches the Peripheral Register PWM_COUNT value (Compare Value), the
TIMEROUT signal changes from high to low level,
up to the ne xt counter start.
The period of the PWM s ignal is obtained by using
the following formula:
T= (255-PWM_RELOAD)*TMRCLK
where TMRCLK is the outp ut of the 16-bit prescaler. The duty cycle of the PWM signal is
controlled by the Output Register PWM_COUNT:
Ton =(PWM_COUNT- PWM_RELOAD)* TMRCLK
t
NOTE.
If the PWM_RELOAD value increases, the
duty cycle resolution decreases.
By usin g a 20 MHz Master Clock a PWM frequency in the range betwee n 1.2 Hz to 78.43 Khz
may be o btained .
NOTE:
The Timer, before using a new value of the
counter or of the reload, has to complete the previous counting. If the counter/reload v alue is
changed during counting, the new value of the
timer counter is used only at the end of the prev ious counting phase. This happens both in Timer
andinPWMmode.
WARNING:
loading new values of the reload in
the PWM_x_RELOAD registers, t he PWM/Timer is
immediately set on-fly. This can cause som e s ide
effects during the current coun ting cycle. The next
cycles work normally. This occurs both in Timer
andinPWMmode.
If the Output Regi s ter PWM_COUN T value is 255
the TIMEROUT s ignal is always at high level.
If th e Output Regi ster PWM_COUNT is 0, or less
than the PWM_RELOAD value, TIMEROUT signal is always at low level.
58/94
When the Timer is in Reset, or wh en t he dev ice is
reset, the TOUT pin goes t o threestate: it is recommended to use a pull-up or a pull-down resistor
if this output is used to drive an external device.
ST52T400/T440/E440/T441
9.3 Timer Interrupt
The TIMER can be programmed to generate an
Interrupt request until the end of the count or when
there is an Timer Stop signa l (TSTRT). The Timer
can generate programmabl e Interrupts into 4 different modes:
Interrupt mode 1: Int errupt on Timer Stop.
Interrupt mode 2: Interrupt on Rising Edge of
TIMEROUT.
Interrupt mode 3: Interrupt on Falling Edge of
TIMEROUT.
Interrupt mode 4: Interrupt on both edges of
TIMEROUT.
Table 9.1 Configuration Register 5 Description
BitNameValueDescription
0TIRST
1TERST
2TISTR
3TESTR
4
INTE
5
6INTSL
7TMODE
Reset Configuration = “00000000”
0Internal RESET
1Internal SET
0External RESET on Level
1External RESET on Edge
0Internal STOP
1Internal START
0External START on Level
1External STARTon Edge
00TIMER Interrupt on TIMEROUT Falling Edge
01TIMER Interrupt on TIMEROUT Rising Edge
10TIMER Interrupt on Both Edges of TIMEROUT
11- not used
0TIMER Interrupt on Counter Stop
1TIMER Interrupt on TIMEROUT Edges
0TIMER MODE
1PWM MODE
The Interrupt m ode can be selected by means of
INTSL and INTE bits of the R EG _CONF5.
NOTE:
the interrupt on TIMEROUT rising edge is
also generated after the Start .
WARNING:
If the PWM/T imer is configured with
the Interrupt on Stop and the Start/Stop is
configured as external, a low signal in t he STRT
pin determines a PWM/Timer interrupt even if the
peripheral is off. If the interrupt is c onfigured on
falling edge, a reset signal generates an interrupt
request.
59/94
ST52T400/T440/E440/T441
Figure 9.5 Configuration Register 5
REG_CONF 5
TIMER
D7 D6 D5 D4 D3 D2 D1 D0
Reset Configuration = “ 00000000”
TIRST: Timer InternalRESET
TERST:Timer External RESET on Edge/Level
0TIMEROUT Pulse type waveform
1TIMEROUT Square type waveform
Figure 9.6 Configuration Register 6
REG_CONF 6
TIMER
D7 D6 D5 D4 D3 D2 D1 D0
PRESC: Timer Prescaler
TMRW: TIMEROUT waveform
not used
61/94
ST52T400/T440/E440/T441
Table 9.3 Configuration Register 7 Description
BitNameValueDescription
0
TRST
1
2
TSTR
3
4TCLK
5NC0Must be kept to “0”
6NC-Not used
7NC-Not used
Reset Configuration = “00000000”
00TIMER RESET Internal
01TIMER RESET External
10TIMER RESET External or Internal
11Not used
00TIMER START Internal
01TIMER START External
10TIMER START External or Internal
11Not used
0TIMER Clock Internal
1TIMER Clock External
Figure 9.7 Configuration Register 7
REG_CONF 7
TIMER
62/94
D7
D6 D5
D4
D3
D2 D1
D0
TRST: Timer RESET Mode
TSTR: TimerSTART Mode
TCLK: Timer Clock Source
Not used
ST52T400/T440/E440/T441
L
E
9
P
O
456
7
R
EG_CONF1
0
IVE
T
S
E
10 TRIAC/PWM DRIVER
ST52x400/440/441 offers a peripheral able to
generate a TROUT signal on PA0 pi n (able to supply up to 25 mA), to drive an external device, like a
TRIAC, an IGBT or a Power MOS. A Triac/PWM
driver can p erform 3 different working modes
according to REG_CONF10(3:2) bits, MODE (see
Table 10.3):
MODE = “00”:PWM
MODE = “01":Burst Mode Triac Control
(Thermal Regulations)
MODE = “1x":Phase Angle Partializa tion
Triac Control (Motor Control)
The Triac/PWM Driver can be initialized by using a
value fixed by a control algorithm, and stored in
the Registe r File. The value is loaded in the
TRIAC_COUNT register (Output Register 9) by
using the LDPR instruction and it can be read by
using the LDRI instruction address ing the Input
Register 17.
Figure 10.1 illustrates the internal structure of the
Triac/PWM Driver.
PWM Mode
The PWM working mode selection can be
obtained by setting REG_CONF10(3: 2) bits,
MODE, at “00" value.
In this work ing mode, the peripheral provides a
signal with a fixed period and a variable duty cycle
on the TROUT pin.
The PWM period can be generated starting from
the internal master clock or an external clock signal applied in MAIN1 pin.
In both cases, the clock signal is divided by a 16bit Prescaler, m anaged by REG_CO NF8 and
REG_CONF9 (Figure 10.2).
At each period, the duty cycle is fixed by an 8-bit
value loaded in the TRIAC_COUNT register (Output Register 9). The duty cycle is proportional to
the value: loading 50% duty cycle is obtained,
loading 0 the output will be low (off) during all the
period, loading 255 will be high (on).
By Us ing a 20 Mhz clock PWM frequencies in the
range between 1.2 Hz to 78.4 Mhz may be
obtained.
Figure 10.1 TRIAC/PWM Driver Block Diagram
MCLK
16
PRECLK
PULSE
GENERATOR
Tck
PRESCALER
16 bit
MAIN1
MAIN2
REG_CONF8
REG_CONF9
MCLK
EXTCLK
50/60 Hz
TRIAC/PWM DR
Tck
MODE
÷2
01
REG_PERIPH_
CORE
PROGRAMMAB
COUNTER
23
8
STAR
TRIACOUT
R
T
RE
L
63/94
ST52T400/T440/E440/T441
Burst Mode
The Burst principle is based on turning the TR I AC
device on and off for a fix ed integer number of
mains voltage periods, in order to control the
power transferred to the load.
In Burst Mode th e peripheral provides a signal,
with a fixed period T containing an integer nu mber
of pulses correspondi ng to the main voltage zero
crossings, with a Duty Cycle that is proportional to
the number of pulses that keep the TRIAC on (Figure 10.4).
The user can define the period T by means of the
internal 16-bit prescaler, s etting R EG_CONF8 and
REG_CONF9 (Figure 10.2). T is proportional to
the main voltage period and is in the range [5.10,
334233.6]s if the main frequency is 50Hz .
The duty cycle is fixed at each period by an 8-bit
value loaded in the TRIAC_COUNT register (Output Register 9). The duty cycle is proportional to
the value: loading 50% duty cycle is obtain ed,
loading 0 the output will be low (off) during all the
period, loading 255 will be high (on).
The width and the polarity of the pulses can be
programmed ac c ording to the TRIAC device and
the circuit cha racteristics.
In order to work in Burst mode, the pre-post zerocrossing of main v oltage must be detected by
using an external inserting circuitry connected to
the MAIN1 and M AIN2 pins (Figure 10.5).
This kind of TRIAC control is mainly used for thermal regulation.
PhaseAnglePartializationMode
Phase Angle Partialization method is bas ed on
turning on the TRIAC device only for a part (Phase
Angle) of each main voltage period. When the
phase angle is large, the energy (power) sup plied
to the load is low, viceversa when the phase angle
is small, the energy supplied to the load is high.
In order to work in Phase Angle Partialization
mode, the zero-crossing of main voltage must be
detected by using an external inserting circuitry
connected to the MAIN1 and MAIN 2 pins or,
optionally, only on MAIN1 pin (Fi gure 10.10).
In this working mode, the peripheral provides eight
pulses after t he time corresponding to the Phase
Angle on the TROUT pin, obtained by s etting the
TRIAC_COUNT 8-bit register (Output Register 9)
andthePrescaler(REG_CONF8and
REG_CONF9). By modifying the TRIAC_COUNT
register the Phase Angle is con trolled.
10.1 TRIAC/PWM Driver Setting
The TRIAC/PWM Peripheral can be SET or
RESET through REG_CONF10(7) bit TCRST
(Table 10.3) in all three wo rking modes.
If the TRIAC/PWM Peripheral is SET and only inPWM mode, it is possible to START or STOP the
internal c ount er of the peripheral without resetting
it, through REG_CONF10(5) bit TCST (Table
10.3), in order to use the peripheral as an additional Timer. In the other modes the TCST bit
must be kept to “1”.
NOTE:
if TCRST is 0 (reset status) the TROUT
pin output is in tristate.
Figure 10.2 TRIAC/PWM Configuration Registers 8 and 9
64/94
ST52T400/T440/E440/T441
10.2 PWM Mode Settings
By using the 16-bit Prescaler (REG_CONF8 and
REG_CONF9), the PWM period can be generated
by dividing the internal master clock, an external
clock signal applied to pin MAIN 1, or the mains
voltage frequency, using the circuit of Figure
10.10.
NOTE:
The external clock signal applied on
MAIN1 pin must have a frequency t hat is at least
two times smaller than the internal master clock .
The clock source can be selected by using
REG_CONF10(4) bit, CKSL (Table 10.3).
The period T of the PW M s ignal
10.4) can be c alculated with the f ollo wing formula:
Tb
(see Figure
T= 255*Tck
where
the 16-bit prescaler, according to t he value stored
in REG_CONF8 and REG_CONF9 pair (Figure
10.2).
By using a 20 MHz clock master a PWM frequency in the range 1.2 Hz to 78.4KHz may be
obtained (Table 10.1).
The value
user in the TRIAC_COUNT Register (Out put Register 9) by using the LDPR instruction.
corresponding duty cycle can be calculated from
the following formulas:
Ton
depends on the value set by t he
Ton
and the
Ton=TRIAC_COUNT * Tck
Duty=TRIAC_COUNT / 255
The TRIAC_COUNT value can be changed on fly
but it is updated only at the end of the signal
period. If TRIAC_COUNT value is 255 then Toff is
zero and TRO UT signal is always equal to one
during the perio d T.
According to REG_CONF10(0) c onfiguration register bit, POL, the firing pulses polarity m ust be
set.
IN PWM mode, it is possib le to generate a programmable Interrupt in four different ways:
1) No Interrupt;
2) Interrupt on rising edge of the signal Tb
(INT_R).
3) Interrupt on falling edge of the signal Tb
(INT_F)
4) Interrupt on both edges of the signal Tb.
The Interrupt sources described above are always
active;theycanbemaskedthrough
REG_CONF0(5:3) bits, INTSL (see Table 4.1).
NOTE:
If the Interrupt on the rising edge (INT_R)
is not masked through REG_CONF0(4), the f irst
Interrupt after the start occurs with a delay of a
time period T. If TRIAC_COUNT is 255 or 0, the
first interrupt after the start (either INT_R and
INT_F) occurs at time T. In any case for
TRIAC_COUNT equal to 255 or 0, INT_R and
INT_F coincide and occur at each control period T.
Figure 10.3 PWM Working Mode
Ton = INIT_VALUE* Tck
T
b
TRIACOUT
T = 255 * Tck
Toff
65/94
ST52T400/T440/E440/T441
10.3 Burst Mode
When wo rking in Burst mode , the synchronization
withthemainsismandatory,therefore
REG_CONF10(4) bit CKSL must be set t o “1”.
(Table 10.3).
A square wave Tb is generated with a duty cycle
proportional to the power the user needs to transfer to the load. A pul se is generated for each zero
crossing of the mains v oltage included in the Ton
of the fixed period T. Figure 10.4 illustrates the
typical Burst Control working mode. The period T
of the signal Tb (Figure 10.4) is:
T = 255*Tck
The signal Tck is generated by programming the
16-bitPresc alerbyREG_CONF8and
REG_CONF9 (Figure 10.2). Tck is equal to the
mains voltage frequenc y (50 or 60 Hz) divided by
N+1, where N is an integer valu e in the range [0,
16
2
-1].
The value Ton is proportional to the value contained in TRIAC_COUNT Register (Output Register 9)
The num ber of generated pulses N_PULSES in
TROUT pin is equal to:
N_PULSES = 2*[(N+1)*TRIAC_COUNT]
where N is the value stored in the 16-bit prescaler.
Therefore it is:
Ton = TRIAC_COUNT*Tck
The TRIAC_COUNT can be changed on fly and
takes effect from the following pe riod; the Prescaler value N instead is fixed since the beginning
and cannot be changed on fly.
The first pulse is obtained during the first zero
crossing of the main v oltag e and the last one is
generated after clock pulses included in the time
period TRIAC_COUNT *Tck, where Tck is the
Prescaler output, generated by using the main
voltage frequency applied to MAIN1 and MAI N2
pins. This guarantees synchronizat ion with the
mains voltage frequenc y.
Ranges of the Tb signal period depend on the
power line frequ ency and Prescaler (Table 10.2).
In order to drive a Triac i n Burst Mode a pulse
sequence must be generated, which must be centered on the zero crossing of the power line as
illustrated in Figure 10.7. Therefore, the pre z ero
crossing and the post zero cross ing of the power
line must be detected.
To detect the zero-crossing and also obtain the
main voltage frequency, the user must generate
MAIN1 and MAIN2 signals by using the circuit
illustrated in Figure 10.5.
MAIN1 and MAIN2 si gnals are used in the block
called PULSE GENERATOR o f the periph eral
(see Figure 10.1).
Table 10.2 TROUT Signal Period
Power Line
Frequency
50 Hz5.10 s334233.60 s
60 Hz4.25 s278528.05 s
minmax
T
Figure 10.4 Burst Working Mode
Tb
1.5
1
0.5
Power
66/94
Line
0
-0.5
-1
-1.5
T = 255 * Tck
Ton
ST52T400/T440/E440/T441
In particular, the pulses are generated by using
the rising edge of the sign al MAIN1 and the falling
edge of the signal MAIN2. Figure 10.6 illustrate s
the generation of the Triac pulses Tp.
The first firing pulse for the Triac is generated on
the zero crossing of the power line, while the next
pulses are c entered on the zero c ros s ing. Generally, the Triac firing pulses start 1/2 Tp before the
zero crossing and the length of the pulses is Tp,
see Figure 10.6.
The length Tp of the pulses is prog r amm able by
using a16 bit valueUTP,obtained with
REG_CONF19bits,UTPMS B,and
REG_CONF20, UTPLSB (see F igure 10.12 and
Table 10.5):
Figure 10.5 Burst Mode Zero Crossing Circui t
T
P=TCLKM
The value T p is in the r ange [0, 3.2]
*UTP
ms
when the
clock master is 20 MHz.
According to REG_CONF10(0) c onfiguration register bit, POL, the firing pulses polarity may be set;
in order to obtain positive or negative gate Triac
currents, allowing to work respectively in I and IV
quadrants, or in the II and III quadran ts (see Figure 10.6).
The pulses polarity can be changed on fly with
immediate effect.
Working in the II and III quadrant the peripheral
implements the following proc edure:
1) The firing pulse is set to “ 1" on the rising edge
Figure 10.6 Burst Mode Zero Crossing Circui t
1
0.5
Power
Line
0
(0.5)
(1)
Ig
Positive
Triac Gate
Current
Negative
Triac Gate
Current
Ig
½Tp
II and III quadrants
I and IV quadrants
½Tp
Tp
Figure 10.7 Burst ModeZero Crossing
0.5
Main Voltage
TRIACOUT
MAIN1
MAIN2
-0.5
-1.5
0
Tp
-1
TpTp
67/94
ST52T400/T440/E440/T441
of MAIN1.
2) Th e firing pulse is res et to “0" after the time Tp
fixed by program.
3) On the falling edge of MAIN2 the firing pulse is
set to “1"
4) Th e firing pulse is res et to “0" after the time Tp
fixed by program.
It is possible to generate a programmable Interrupt in the following ways:
1) No Interrupt;
2) Interrupt on the rising edge of the signal Tb
(INT_R)
3) Interrupt on the falling edge of the signal Tb
(INT_F)
4) Interrupt on bot h edges of the s ignal Tb.
5) Interrupt on each Triac pulse (INT_P)
If pulse width or TRIAC_COUNT are set to zero,
no pulse on TROUT pin is generated and INT_P
interrupt does not occ ur.
The Interrupt sources desc ribed above are always
active;theycanbemaskedthrough
REG_CONF0(5:3) bits, INTSL (see Table 4.1).
10.4 Phase Angle Partialization Working Mode
In this mode Triac is controlled each semi-period
of the mains voltage. The power transferred to the
load is proportional to the CURRENT FLOW
ANGLE γ. This kind of Triac control is suitable to
drive the Triac with inductive load (i.e. universal or
monophase motors). Figure 10.8 illustrates the
relation between the Phase Angle α and the Current Flow Angle γ .
The peripheral allows to control the Phase Angle
or equivalently time T1 (see Figure 10.9). It is possible to change Time T1 setting the contents of the
TRIAC_COUNT register (Output Register 9). T1 is
proportionaltothevalueloadedinthe
TRIAC_COUNT register.
Different circuits for the zero crossing detection
may be used, but MAIN1 signal rising edge must
always be synchronized with the mains voltage
zero crossing and MAIN2 signal falling edge must
be synchronized with the following mains voltage
zero crossing.
By using the external circuit illustrated in Figure
10.10, only one synchronization signal from the
mains may be used, MAIN1. In this case,
REG_CONF10(6) must be set to “1”, MAIN2 signal coincides internally with MAIN1 and MAIN2 pin
is left free for other functions. If main voltage frequency is equal to 50 Hz, then Tris equal to 20 ms
(Figure 10.9) and T1 is:
being T
T1 =TRIAC_COUNT* T
master clock period and N the Pres-
CKLM
CKLM
*(N+1)
caler value (Configuration Registers 8 and 9).
NOTE:
The user must verify that time T1 is not
larger than a fixed time Tmax (8ms at 50 Hz) in
order to avoid the firing of the Triac in the second
half period of the mains voltage and to choose a
suitable Prescaler value to avoid the shifting of the
pulse sequence in the following semi-period.
In order to avoid problems for the Triac firing when
the load is inductive 8 different pulses are generated by the peripheral (Figure 10.10). Their width,
equal the semiperiod Ti/2, is programmable by
using registers REG_CONF19 (UTPMSB) and
REG_CONF20 (UTPLSB) and is provided by the
formula:Ti/2 = T
NOTE:
the choice of UTP value must be done by
CLKM
*UTP
the user paying attention to the fact that the duration of the 8 pulses train must be such that added
to T1, it does not fall into the second half period of
the mains voltage. In fact by using a clock master
equal to 20 MHz and the full 16 bit value by
ConfReg19 and 20, the pulse width would be in
the range [0.2, 3.28] ms.
The duty cycle of Ti pulse is always 50%. The
choice of the pulse width must be done according
to TRIAC device specifics and must be set from
the beginning of the program. To change width
during program execution it is necessary to
RESET the peripheral.
According to REG_CONF10(0) configuration register bit, POL, the firing pulses polarity must be
set.
A programmable interrupt may be generated in
four different ways:
1) no Interrupt;
2) Interrupt on the rising edge of the signal MAIN1
(INT_R)
3)Interrupt on the falling edge of the signal MAIN2
(INT_F)
4) Interrupt on both the edges of the signal MAIN1
5) Interrupt on rising edge of first pulse after T1
(INT_P)
If UTP is 0, TROUT signal remains at 0 (or 1, if
POL=1), however after the time T1, the interrupt
INT_P is generated.
The Interrupt sources described above are always
active;theycanbemaskedthrough
REG_CONF0(5:3) bits, INTSL (see Table 4.1).
68/94
Figure 10.8 Phase angle Partialization Mode
1.5
V
A2-A1
1
0.5
L
Load
Il
A2
A1
N
(0.5)
(1.5)
(0.5)
1.5
Il
0.5
0
1
(1)
0
(1)
Phase Angle
Table 10.3 Configu ration Register 10
ST52T400/T440/E440/T441
α
γ
Current Flow Angle
BitNameValueDescription
0
0POL
1
Set Positive Output
Pulse Polarity
Set Negative Output
Pulse Polarity
1--Not used
2
MODE
00PWM Mode
01Burst Mode
31XPhase Partialization
0Internal Clock Master
4CKSL
5TCST
1
0Triac Stop
External Clock
on Main1
1Triac Start
Set MAIN2 as
Alternate Function
MAIN2 coinciding with
MAIN1
6IOSL
7TCRST
0
1
0Triac Reset
1Triac Set
Reset Configuration = “00000000”
Table 10.4 Configuration Register 19
BitNameValueDescription
0 - 7UTPMSB
Output Impulse
Width most
significative bit
Table 10.5 Configuration Register 20
BitNameValueDescription
0 - 7UTPLSB
Output Impulse
Width least
significative bit
Reset Configuration = “00000000”
Figure 10.9 Phase Angle Partialization Mode
Mains
1.5
Voltage
0.5
(0.5)
(1.5)
1
0
(1)
Tr/2
T1
Tmax
Tr
Ti
T1
8mS
10 mS20 mSec
69/94
ST52T400/T440/E440/T441
o
d
Figure 10.10 Phase Angle Partialization Zero Crossing Circuit
Figure 10.12 TRIAC/PWM Configuration Registers 19 and 20
PulseWi
d
D
0
REG_CONF19
TRIAC/PWM
D0D1D2D3D4D5D6D7
UTPMSB: Ou tput Pulse Width
REG_CONF20
TRIAC/PWM
D1D2D3D4D5D6D7
ST52T400/T440/E440/T441
UTPLSB:Output
th
71/94
ST52T400/T440/E440/T441
11 ELECT RICAL CHARACTERISTICS
11.1 Parameter Conditions
Unless otherwise specified, all voltages are
referred to V
ss.
11.1.1 Minimum and Maximu m values.
Unless otherwise specified, the minimum and
maximum values are guaranteed in the worst
conditions of environment temperature, suppl y
voltage and frequencies production tes ting on
100% of the devices with an environment al
temperature at T
=25°C and TA=TAmax (given by
A
the selected temperature range).
Data is based on c harac terization results, design
simulation and/ or technology c harac teristics are
indicated in the table footnot es and are not tested
in production. The minimum and max imum values
are based on characterization and refer t o sample
tests, representing the mean value plus or minus
three times the standard deviation (mean ±3Σ).
11.1.2 Typical values.
Unless otherwise specified, typical data is based
on T
=25°C, VDD=5V (for the 4.5≤VDD≤5.5V
A
voltage range). They are provided only as design
guidelines and are not tested.
11.1.4 Loading capacitor. The loading condition
used for pin parameter measurement is illustrated
in Figure 11.1.
11.1.5 Pin input voltage.
Input voltage meas urement on a pin of the dev ice
is described in Figure 11.2
Figure 11.2 Pin input Voltage
ST52 PIN
V
IN
11.1.3 Typical curves.
Unless otherwise specified, all typical curves are
provided only as design guidelines and are not
tested.
Figure 11.1 Pin loading conditions
ST52 PIN
C
L
11.2 Absolute Maximum R atings
Stresses abovethose listed as“absolute maximum
ratings” may cause permanent damage to the
device. This is a stress rating only.
Functional operation of the device under thes e
conditions is not impli ed. Exposure to maximum
rating conditio ns for ex tended periods may affect
device reliability.
72/94
Table 11.1 Voltage Characteristics
SymbolRatingsMaximum ValueUnit
ST52T400/T440/E440/T441
V
DD-VSS
|V
SSA-VSS
V
IN
|
Variation between digital and analog ground pins50mV
Input voltage on any other pin
V
DESD
Electro-static discharge voltage4000
Table 11.2 Current Characteristics
SymbolRatingsMaximum ValueUnit
I
VDD
I
VSS
I
IO
I
INJ(PIN)
Total current in VDDpower lines (source)
Total current in VSSground lines (sink)
Output current sunk by any standard I/O and control pin25
Output current source by any I/Os and control pin-25
Injected current on RESET pin±5
Injected current on OSCin and OSCout pins±5
Supply voltage6.5V
Input voltage on VppVSS-0.3 to 13
1) & 2)
3)
3)
Injected current on VPPpin
VSS-0.3 to VDD+0.3
100
100
±5
V
mA
ΣI
INJ(PIN)
Injected current on any other pin
4)
Total Injected current (sum of all I/O and control pins)
4)
±5
±20
Table 11.3 Thermal Characteristic s
SymbolRatingsMaximum ValueUnit
T
STG
T
J
Notes:
1. Connecting RESET and I/O Pins directly to V
or an unexpected change of I/O configuration occurs (for example, due to the corrupted program counter). In order to guarantee
safe operation, this connection has to be performed via a pull-up or pull-down resistor (typical: 4.7k
Unused I/O pins must be tied in the same manner to VDD or VSS according to their reset configuration.
2. When the current limitation is not possible, the VIN absolute maximum rating must be respected, otherwise refer to I
specification. A positive injection is induced by VIN>VDD while a negative injection is induced by VIN<VSSto I INJ(PIN) specification.
A positive injection is VIN>VDD while a negative injection is induced by V
3. All power (V
4. When several inputs are submitted to a current injection, the maximum ΣI
injectedcurrents(instantaneous values).
DD) and ground (VSS) lines must always be connected to the external supply.
Storage temperature range-65 to +150°C
Maximum junction temperature150°C
DD or VSS could damage the device if the unintentional internal re set is generated
Ωfor RESET, 10K Ωfor I/Os).
IN<VSS.
is the absolute sum of the positive and negative
INJ(PIN)
INJ(PIN)
73/94
ST52T400/T440/E440/T441
11.3 Recommended Operating C ondition
Operating condition: V
Table 11.4 Recommended O perating Conditions
SymbolParameterTest ConditionMin.Typ.MaxUnit
2)
V
DD
Programming Voltage11.41212.6
Oscillator Frequency120MHz
f
OSC
V
V
V
PP
O
SSA
1)2)
Notes:
DD=5V±10%; TA=0/125°C (unless otherwi se specified).
Operating SupplyRefer to Figure 11.32.75.5
Output VoltageV
Analog GroundVSS-0.3V
SS
SS
V
DD
VSS+0.3
V
1. It is reccomendend to insert a capacitor beetwen V
comended values are 10 µF (electrolytic or tantalum) and/or 100 nF (ceram ic).
2. A lower V
decreasing f
DD
(see F igure 11.3). Data illustrated in the figure are characterized but not
osc
and VSSfor improving noise reject ion. Rec-
DD
tested.
Figure 11.3 fosc Maximum Operating Frequency versus VDD supply (*)
20
18
16
14
12
10
Functionality not guaranteed in this area
max (MHz)
8
osc.
f
6
4
Functionality guaranteed in this area
2
0
0
0.5
11.522.533.5
Functionality not guaranteed in this area
4
4.5
5
5.5
Vdd (V)
(*) Only digital parts of the device: the Analog Comparator cannot workwith supply voltage lower
than 4.5 V.
74/94
ST52T400/T440/E440/T441
[
]
]
11.4 Supply Current Character istics
Supply current is mainly afunct ion of the operating
voltage and frequency. Other factors such as I/O
pin loading and s w it c hing rate, oscillator ty pe,
internal code execution pattern and temperature,
also have an impact on the current consumption.
The test condition in RUN mode for all the IDD
measurements are:
OSCin = e xternal square wave, from rail to rail;
OSCout = floating;
All I/O pins tristated pulled to VDD
A=25°C
T
Table 11.5 Supply Current in RUN and WAIT Mode
SymbolParameterConditionsTyp
f
=2 Mhz6.486.48
osc
f
=4 Mhz7.958.16
Supply current in RUN mode
1)
VDD=5V±5%
I
DD
TA=25°C
Supply current in WAIT mode
2)
osc
f
=5 Mhz,9.089.27
osc
f
=1015.515.6
osc
=2028.328.92
f
osc
f
=2 MHz4.44.41
osc
=4 MHz6.06.09
f
osc
f
=5 MHz6.66.89
osc
f
=1012.212.31
osc
f
=2023.023.07
osc
Max
3)
Unit
mA
Notes:
1. CPU running with memory access, all I/O pins in input mode with a static value at V
peripherals switched off; clock input (OSCin driven by external square wave).
2. CPU in WAIT mode with all I/O pins in input mode with a static value at V
switched off; clock input (OSCin driven by external square wave).
3. Data based on characterization results, tested in production at V
Figure 11.4 Typical IDD in RUN vs fosc
35
30
25
20
mA
15
IDD
10
5
0
2.03.04.05.06 .0
VDD [V]
2M Hz4M Hz5M Hz10MHz20M Hz
Figure 11.5 Typical IDD in WAIT vs fos c
30
25
20
15
IDD [mA
10
5
0
2.02.53.03.54.04.55.05.56.0
DDmax
2M Hz4M Hz5MHz10MHz20MHz
(no load), all pe ripherals
DD
and f
oscmax
VDD [V]
.
(no load), all
DD
75/94
ST52T400/T440/E440/T441
Table 11.6 Supply Current in HALT Mode
SymbolParameterConditions
I
DDSupply current in HALT mode
2)
3.0 V≤ VDD ≤ 5.5 V0.60.68 µA
Typ
1)
MaxUnit
Notes:
1. Typical data is based on TA = 25 °C
2. All I/O pins in input mode with a static value at V
DD (no load)
11.5 Brown-Out Detector characteristics
Table 11.7 Brown-out detector
SymbolParameterConditionsMinTypMaxUnit
BOD
BOD
t
BODL
L
H
BOD Threshold low3.8V
BOD Threshold high4.1V
Duration of filtered noise100
clock
cycles
Notes:
1. Data based on characterization results
2. Measurement done with dV/dt fixed
76/94
ST52T400/T440/E440/T441
11.6 Clock and Timing Characteristics
Operating Conditions: V
Table 11.8 General Timing Parameters
SymbolParametersTest ConditionMinTyp.MaxUnit
DD=5V ±5%, TA=0/125°C, unless otherwise specified
f
osc
t
CLH
t
CLL
t
SET
t
HLD
t
WRESET
t
WINT
t
IR
t
IF
t
OR
t
OF
Oscillator Frequency120MHz
Clock High25250
Clock Low25250
SetupSee Fig. 11.65
HoldSee Fig. 11.65
Minimum Reset Pulsef
Minimum Externalf
Input Rise TimeSee Fig. 11.715
Input Fall TimeSee Fig. 11.715
Output Rise TimeC
Output FallC
=20MHz100
osc
=20MHz100
osc
=10pF10
LOAD
=10pF10
LOAD
nS
Figure 11.6 Data Input Timing
t
CLL
t
CLH
50%
t
CP
Data
Clock
50%
t
SETtHLD
50%
Figure 11.7 I/O Rise and Fall Timing
77/94
ST52T400/T440/E440/T441
11.7 Memory Characteristics
Subject to general operating conditions for V
Table 11.9 RAM and Registers
SymbolParameterConditionsMin.Typ.MaxUnit
DD,fosc and TA, unless otherwise specified.
RM
V
Data retention
1)
mode
HALT mode (or
RESET)
1.6V
Table 11.10 E PRO M Program M em ory
SymbolParameterConditionsMin.Typ.MaxUnit
ERASEUV lamp
W
Lamp
wavelength
2537 A
15
Watt,
sec/cm
UV lamp is
placed 1 inch
tERASE
Erase time
2)
from the device
window without
1020min.
any interposed
filters
RETData Retention
t
A =+55°C
T
20years
Notes:
1. Minimum V
DD supply voltage without losing data stored into RAM (in HALT mode or under RESET) or
into hardware registers (only in HALT mode). Guaranteed by construction, not tested in production.
2. Data is provid ed only as a guideline.
2)
78/94
ST52T400/T440/E440/T441
11.8 ESD Pin Protection Strategy
In order to protect an integrated circuit against
Electro-Static Discharge the stress must be
controlled to prevent degradation or destruction of
the circuit elements. Stress generally affects the
circuit elements, which are connec ted to the pads
but can also affect the internal devices when the
supply pads receive th e stress. T he elements that
are to be protected m ust not receive excessive
current, voltage, or heating within their st ructure.
An E S D network combines the different input and
output protections. This network works by allowing
safe discharge paths f or the pi ns subject to ESD
stress. Two critical ESD stress cases are
presented in Figure 11.8 and Figure 11.9 for
standard pins.
11.8.1 Standard Pin Protection
In orderto protect theoutput structure thefollowing
elements are added:
-AdiodetoV
- A protection device between V
In order protect the input structure the following
elements are added:
- A resistor in series with pad (1)
-AdiodetoV
- A protection device between V
Figure 11.8 Safe discharge path subjected to ESD stress
VDD
(3a)
OUT(4)IN
Main path
Path to avoid
(3b)
(3a) and a diode from VSS(3b)
DD
and VSS(4)
DD
(2a) and a diode from VSS(2b)
DD
and VSS(4)
DD
VDD
(2a)
(1)
(2b)
VSS
Figure 11.9 Neg ativ e Stress on a Standard Pad vs. VDD
VDD
(3a)
(4)IN
OUT
Main path
(3b)
VSS
VSS
VDD
(2a)
(1)
(2b)
VSS
79/94
ST52T400/T440/E440/T441
11.9 Port Pin Characteristics
11.9.1 General Characteristics.
Subject to general operating condition for V
DD,fosc,
and TA,unless otherwise specified.
SymbolParameterConditionMin
CMOS type low level input voltage.
Port B pins. (See Fig 11.13)
V
IL
TTL type Schmitt trigger low level
input voltage. Port A and Port C
Typ
1)
MaxUnit
1.5
0.8
pins. (See Fig. 11.12)
CMOS type high level input voltage.
Port B pins. (See Fig 11.13)
V
IH
TTL type Schmitt trigger high level
input voltage. Port A and Port C
3.3
2.2
V
pins. (See Fig. 11.12)
V
hys
I
L
Schmitt trigger voltage hysteresis
Input leakage current
2)
V
SS≤VIN≤VDD
1
±1
µA
I
S
Static current consumption
3)
Floating input mode200
Notes:
1. Unless otherwise specified, typical data is based on T
=25 °C and VDD=5 V
A
2. Hysteresis voltage between Schmitt trigger switching level. Based on characterization res ults, not
tested in production.
80/94
ST52T400/T440/E440/T441
Subject to general operating conditions for VDD,fosc,andTA, unless otherwise specified.
Table 11.11 Output Voltage Levels
SymbolParameterConditionsMinTypMaxUnit
V
OL
V
OH
pin when 8 pins are sunk at same time.
Output high level voltage for standard I/
2)
O pin when 8 pins are sourced at same
Output low level voltage for standard I/O
1)
V
time.
=5V, IIO=+8mA
V
DD
=5V, IIO=- 8mA
V
DD
V
DD
0.5
-
Notes:
1. The I
(I/O ports and control pins) must not exceed I
current sunk must always respects the absolute maximum rating specified in Section 11.2 and the sum of I
IO
VSS
2. The IIOsourced current must always respect the absolute maximum rating specified inSection 11.2 and the sum of I
(I/O ports and control pins) must not exceed I
VDD.
SS
0.4
+
V
IO
IO
Figure 11.10 TTL-Level input Schmitt Trigger
5
V(V)
o
4
3
2
1
0.5 0.8 1.0 1.52.0 2.5
0
V(V)
i
V=5V
DD
T = 25°C
A
(TYPICAL)
Figure 11.11 Port B pins CMOS-level input
5
V(V)
o
4
3
2
1
0
2.03.35.0
V(V)
i
V=5V
DD
T = 25°C
A
(TYPICA L )
81/94
ST52T400/T440/E440/T441
Subject to general operating condition for VDD,fosc, and TA, unless otherwi se specified.
Table 11.12 Output Driving Current
SymbolParameterTest ConditionsMinTypMaxUnit
R
SInput protection resistorAll input Pins1
CSPin CapacitanceAll input Pins5pF
R
puPull-up resistor (*)All input Pins22
(*) ST52T400 and ST52X440 only
Figure 11.12 Port A and Port C pin Equi valent Circuit (ST52T400 and ST52X440 )
DD
V
DD
V
k
Ω
k
Ω
Device
Input/Output
R
PU
S
C
V
SS
V
SS
R
S
IN
V
V
OUT
Figure 11.13 Port B Pin Equivalent Circuit (ST52T400 and ST52X440)
V
PU
DD
SR
VIN
V
OUT
11.10
Device
Input/Output
C
V
DD
R
S
V
SS
V
SS
When the triac-driver is configured in burst-mode or phase partialization the pull-up in main1 and m ain2
pins are disabled.
When the Port B pin is configured as analog input the pull-up is dis abled.
82/94
Figure 11.14 Port A and Port C pin Equivalent Circuit (ST52T441)
V
S
T
V
N
V
DD
Device
Input/Output
S
C
S
R
V
SS
V
Figure 11.15 Port B Pin Equivalent Circuit (ST52T441)
SS
V
V
DD
ST52T400/T440/E440/T441
V
IN
OUT
Device
Input/Output
C
R
S
SS
V
SS
V
I
OU
83/94
ST52T400/T440/E440/T441
11.11 Contro l Pin Characteristics
11.11.1 RESET pin.
Subject to general operating conditions for V
Table 11.13 Reset pin
SymbolParameterConditionsMinTypMaxUnit
V
IL
V
IH
V
hys
Input low level voltage
Input high level voltage
Schmitt trigger voltage hysteresis
DD,fosc, and TA, unless otherwise specified
1)
1)
2)
VDD=5V
VDD=5V
VDD=5V
2.2
2.8
0.6
3)
3)
3)
V
t
FN
t
RST
Duration of filtered noise100
Reset pulse duration500
11.11.2 Power on reset.
Table 11.14 Power on reset
SymbolParameterConditionsMinTypMaxUnit
P
ORPower on reset2.252.302.38
11.11.3 V
Subject to general operating conditions for V
Table 11.15 V
SymbolParameterConditionsMinTypMaxUnit
V
IL
V
IH
PP
pin.
PP
4)
pin
Input low level voltage
Input high level voltage
3)
3)
DD,fosc
, and TA,unless otherwise specified.
V
SS
VDD-0.1
0.2
12.6
nS
V
V
Notes:
1. Data is based on characterization results , not tested in production.
2. Hysteresis v oltage between Schmitt trigger switching level.
Based on characterization results not tested in production.
3. Data is based on design simulation and/or technology characteristics, not tested in production.
Each device is available for product ion in use r
programmable version (OTP) as w ell as in factory
programmed version (FASTROM). OTP devices
are shipped to customers with a default bla nk content FFh, while FASTROM factory programmed
parts contain the code sent by the customer.
There is one common EPRO M version for debug -
Figure 11.16 Device Type Codes
ST52tnnnc mpy
ging and prototyping which features the maximum
memory size and peripherals of the fami ly. Care
must be taken to only use resources available on
the target device. In order to obtain a list of part
numbers see ST5 2T400/T440/E440/T441 Sales
Type List at the beginning of the datasheet.
T
1Kb
1=2Kb
2=4Kb
3=8Kb
P
COU
=20pin
F
G
SUB
400
440
MEMORY TYPE:
=OTP
T
E
=EPROM
FA
RE RANG
5°C
:
:
n
92/94
ST52T400/T440/E440/T441
93/94
Full Product Information at http://www.st.com/five
Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences
of use of such information nor forany infringement of patents or other rights of third parties which mayresult from its use. Nolicense isgranted
by implication or otherwise under any patent or patent rights of STMicroelectronics. Specification mentioned in this publication are subject to
change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not
authorized for use as critical components in life support devices or systems without express written approval of STMicroelectronics.
The ST logo is a registered trademark of STMicroelectronics