Documentos de Académico
Documentos de Profesional
Documentos de Cultura
com/assets/faqs/c16x/#ABOUT
This FAQ was started by Olaf 'Olu' Pfeiffer and is now maintained by the Embedded
Systems Academy: www.ESAcademy.com.
The original of this FAQ is kept in HTML, an ASCII version will no longer be maded
available.
Feel free to send your comments or corrections, error reports or other contributions to
FAQ@ESAcademy.com.
Contents
ABOUT THIS FAQ
Who put this FAQ together?
How can I contribute to this FAQ?
What newsgroups will this FAQ be posted to?
May I distribute this FAQ or post it somewhere else?
How about FAQs on other microcontrollers?
ABOUT THE C16x
The C16x Microcontroller - Overview
Registers, Context Pointer (CP)
Address Space
Interrupt Response
The Pipeline
Pipeline Side-Effects
Clock Speeds
Bus Modes
Memory Access Times
C16x Flavors
MICROCONTROLLER COMPARISONS
Context Switch Times
Comparison of CISC 196 vs RISC 166
SOURCES OF INFORMATION ON THE C16x
Persons, email
Web pages
Mailing lists
C16x PRODUCTS
Free languages and development tools
Commercially available products
C16x DOCUMENTATION
1 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
/faq/c16x
(Server located in California, USA)
WARNING: Older versions of this FAQ are widely spread on the internet. This is the "real"
one with most up-to-date information.
Michael Beach (Hitex UK) - Some of the technical parts are based on his guide "An
Introduction To The C16x Family". It is available in HTML:
/automation/docs/166primer
Robert Teufel, Axel Wolf, Harald Lehmann and many others at Infineon
Thanks for the support! This FAQ benefits from all your inputs.
comp.arch.embedded
comp.realtime
comp.robotics.misc
/automation/faq/
2 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
16 or 32 capture/compare channels
based on two or four 16-bit time bases
4 channel PWM at 78KHz 8-bit resolution
Boolean arithmetic and bit processing
5 general purpose 16-bit timer/counters
Available Peripherals:
3 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
Conventional CPUs spend much time moving data from slow memory areas into active
registers. The RISC offers a very large number of general purpose registers which may be
used for local variables, parameters and intermediates. The C16x provides sixteen 16-bit
general purpose registers (GPRs), each of which may function as an accumulator, indirect
pointer or index. With such a large number of GPR's available, it becomes realistic to keep
all local and intermediate variables within the CPU throughout quite large procedures. This
limits external memory accesses and can yield a great increase in speed.
Further significant benefits are derived from the RISC technique of register windowing. As
stated above, up to 16 registers are available for use by the program. However, by making
the active register bank movable within a larger on-chip RAM, the job of real time multi-
tasking is considerably eased.
Central to this is the concept of a "Context Pointer" (CP), which defines the current absolute
base address of the active bank. Thus a reference to "R0" means the register at the address
indicated by the CP. The 16 registers are then addressed with a 4-bit offset to the CP.
A good example of how the CP is used is with a background task and a real-time interrupt
existing at the same time. When the interrupt occurs, rather than pushing all GPR's onto the
stack, the CP of the current register bank is stacked and simply switched to a new value,
determined at link time, to yield a fresh register bank. This results in a complete context
switch in just one machine cycle but does rule out the use of recursion. A hybrid method,
which permits re-entrancy, uses the stack pointer to calculate the new CP dynamically. Here,
on entering the interrupt, the number of registers now required is subtracted from the current
SP and the result placed in CP, with the old CP stacked. Thus the new register bank is
4 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
located at the top of the old stack, with the old CP and then the new stack following on
immediately afterwards. On exiting the interrupt routine, the original register bank is restored
by POPping the old CP from the stack. The SP is reinstated by adding the size of the new
register bank onto the current SP.
A further RISC refinement is register window overlapping which is when a new procedure is
called, part of the new register bank defined by CP' is coincident with the original at CP:
R3' ; Register for subroutine's locals and intermediates
R2' ; Register for subroutine's locals and intermediates
R7 R1' ; Common register, R7 == R1'
CP' R6 R0' ; Common register, R6 == R0'
R5 ; Register for caller's locals and intermediates
R4 ; Register for caller's locals and intermediates
R3 ; Register for caller's locals and intermediates
R2 ; Register for caller's locals and intermediates
R1 ; Register for caller's locals and intermediates
CP R0 ; Register for caller's locals and intermediates
;============================================================
MODULE 1
; *** Assignment Of GPRs To Local Variables - Caller ***
;============================================================
MODULE 2
; *** Assignment Of GPRs To Local Variables - Sub Routine ***
By using some forethought, the programmer should arrange for any value to be passed to
the subroutine to be located in the common area so that all the normal loading and
unloading of parameters is avoided. This technique can be used in either absolute or
SP-relative register bank modes.
To get the best from a RISC's registers, the location of data needs careful consideration:
although highly orthogonal, the limited number of addressing modes provided for MUL and
DIV for example, can appear somewhat restrictive. Fortunately though, most operands
involved will already be in registers, so eliminating the need for many addressing
techniques.
Address Space
The C16x family has
an segmented
address space of up
to 16MB (only 256KB
5 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
on some devices).
Code segments are
of 64KB size, data
pages of 16KB size.
Additionally, 64KB
non segmented
address space is
available.
Memory access
with PEC
The memory accesses the Peripheral Event Controller can do, are limited to the first 64k
segment. When using a derivative with internal code memory, it seems that PEC accesses
can not be made to external memory, as the first 64k are occupied by the code memory.
However, by using the programable chip selects, accesses can be redirected to external
memory locations. When reprogramming chip selects, pay special attention to the current
code area. If the chip select currently used to fetch programm code is reprogrammed, it
needs to be ensured that the new memory area used by the reprogrammed chip select
contains valid code. In general, it is recommended to have an exact copy of same code in
both memory locations.
The addressing scheme below shows how the code segments and data pages are
addressed. This is done using the Code Segment Pointer (CSP) and the 4 Data Page
Pointers (DPPx).
6 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
Interrupt Response
In the C16x, branches to interrupts make use of the injected instruction technique and thus
vectoring to service routines are achieved in only min 250ns (400ns typ.). The effect of
complex but necessary instructions such as MUL and DIV (5 and 10 cycles respectively)
might be expected to stretch this, but it is interesting to note that the C16x provides these as
interruptable instructions.
Very fast interrupt service is crucial in high-end applications such as engine management
systems, servo drives and radar systems where real-world timings are used in DSP-style
calculations. As these normally form part of a larger closed control loop, erratic latency times
manifest themselves as undesirable jitters in the controlled variable.
The Pipeline
To maximise the rate at which instructions are executed, RISC CPU's are very heavily
pipelined. On any given machine cycle, the C16x can process up to 4 instructions
simultaneously by overlapping the various steps:
FETCH:
get the opcode from the program store
DECODE:
identify the opcode from a small list and fetch operands
EXECUTE:
perform the operation denoted by opcode and initiate write result
WRITE-BACK:
result is returned to the specified location
Although the instruction takes four machine cycles, it is apparently executed in just one (2
state times). Pipelining has considerable benefits for speeding up sequential code execution
as the bus is guaranteed to be more fully utilised.
Pipeline Side-Effects
However, the fetch and decode phases can simultaneously request access to the bus, if for
example, the final phase of the current instruction is a READ. The External Bus Controller
applies a WRITE, FETCH, READ priority to prevent bus conflicts.
Multiply and divide instructions require 5 and 10 cycles respectively and constitute the only
"complex" opcodes within the RISC. These instructions do not finish in the mandatory four
(one bus) cycles. As it is not practicable to stop the pipeline during longer instructions,
dummy instructions are injected into the decode stage, passing through the remaining
stages as simple NOP instructions.
Branches
While in-line code poses no problems for a pipelined CPU, branches require special steps.
The problem is that by the time the branch instruction has reached the EXECUTE stage, the
next in-line opcode has already been FETCHED. Thus the instruction immediately after the
branch will be executed, followed by a jump to the target address for the branch. This
7 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
peculiarity is termed a "delayed branch" and is used as an alternative to flushing out the
pipeline completely.
The situation with a conditional branch is more complicated as the next instruction may be
totally inappropriate given the result of the conditional test. The only solution is to either add
a NOP or flush the pipeline.
The solution taken in the C16x is to, in the first case, inject a dummy instruction into the
DECODE stage while the real target address is being FETCHED. Thus, a single extra
machine cycle is required to execute the branch. For the conditional branch, the dummy is
only injected if the branch is made, and not for no-branch situations, saving time.
Loop Control
With the parallel nature of the CPU, care has to taken to avoid pipeline "mirages". Most
potential problems originate from the WRITE-BACK stage using addresses that have been
changed by subsequently FETCHED instructions. Although special hardware is provided for
artificially bringing forward operand READs and WRITEs, some pipeline effects must still be
kept in mind.
As an example, the general purpose register R0 is to be loaded with a value at the top of the
stack, after the stack pointer "SP" has been moved to a new address of 0FA40H:
SP = 0FA80H
0FA80H = 0FFH - Value at old top of stack
SP = 0FA40H
0FA40H = 011H - Value at new top of stack
8 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
As the instructions overlap, the value POPed into R0 will be incorrect. By putting an
instruction between the MOV and POP, the value of SP will be already at the new value by
the time the POP gets the value of SP. Note that as WRITE overrules READ, the updating of
SP will occur before the READing of the SP value in the decode stage of POP R0. The
overlapping of instructions produces a similar effect when disabling interrupts:
1 BCLR IEN
2 <start of region which may not be interrupted>
3 .
4 .
5 .
As the actual updating of the IEN register does not occur until machine cycle 3, either NOPs must be inserted in cycles 2 & 3 before the c
Clock Speeds
Today, C16x parts are available with many different clock speeds and devices are available
with or without prescaler and/or PLL, allowing maximum core speeds of 16MHz, 20MHz,
25MHz, 33MHz, 40MHz and 50MHz. Higher speeds are under development.
The original C16x has a divide by two prescaler so that a 40MHz XTAL or oscillator is
required to yield a 20MHz CPU clock. The basic unit of time in the C166 core is a single
state time, corresponding to 50ns at 20MHz. Most C16x instructions execute in two state
times, i.e. 100ns.
Some parts, usually with the 'W'-suffix, have no divide by two and thus can use a 20MHz
clock source directly. Note that these parts must be used with a crystal as they must have a
50% duty cycle clock, which cannot be guaranteed with an oscillator module.
If an oscillator module is used, it must have a rise and fall time of <5ns. As with other high
clock rate CPUs, 40 and 32MHz crystals must be of the parallel resonance type. These can
be tricky to find and so a cheap series resonant crystal used with an 74HC04 inverter could
be an alternative to a full oscillator module.
The C167CR and C167SR are all of the 'W' type in that they can use a 20MHz crystal. They
can also use a 5Mhz crystal and use the on-chip PLL to perform a x4 frequency
multiplication up to the usual 20MHz. The PLL is enabled by a pull down resistor on P0L.
9 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
|
GND
Note: This will work in 80% of all applications. Every design is specific (noise, layout). An
oscillator circuit research/development might be necessary for user specific circuits.
Bus Modes
The C16x has five bus modes:
The basic philosophy behind the bus interface is simplicity: by providing non-multiplexed
modes, it is possible to provide just a ROM and RAM to make a working C16x system.
Derivatives with integrated chip selects can make all decoder logic redundant. Thus, despite
is 20 fold improvement in performance, a C166 digital design can be simpler than an 8031!
One of the C16x's most useful features is its ability to support two different bus
configurations in a single hardware design. Thus while the main code and data areas can be
16 bit non-multiplexed with zero wait states for best speed, slow (and low cost) peripherals
such as RTCs can be addressed with, for example, and 8-bit bus with 3 wait states.
This secondary bus mode is controlled by the BUSCON1 and ADDRESEL1 registers which
set the mode and address range base address respectively. In the C165 and C167, a further
3 secondary bus regions can be defined, each with its own external chip select (CS) pin for
direct connection to peripheral devices' chip enable inputs.
In the following table, times are given for 20 MHz CPU clock rate. Please note: the external
bus speed is optimised by prefetching into the instruction queue!
10 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
C16x Flavors
There are many devices available and new ones are added regulary. The following table
does only contain devices which are usually available "off-the-shelf" through distribution. We
will not add new or announced devices, until they are available in quantities, preferably
through distribution.
Technology: CMOS
11 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
CAPCOM,
C=CAN
ASC, SSC, ADC,
SABC167S-4RM 20 4K 32K ROM 4 16 MB MQFP-144 PWM,
CAPCOM
ASC, SSC, ADC,
ST10R167 ROMless,
20 4K 4 16 MB MQFP-144 PWM,
ST10C167-Q3 32K ROM
CAPCOM, CAN
ASC, SSC, ADC,
128K
SABC167CR-16RM 20 4K 4 16 MB MQFP-144 PWM,
ROM
CAPCOM, CAN
ASC, SSC, ADC,
128K
ST10F167-Q6 20 4K 4 16 MB MQFP-144 PWM,
Flash
CAPCOM, CAN
ASC, SSC, ADC,
256K
ST10F168 25 8K 4 16 MB MQFP-144 PWM,
Flash
CAPCOM
ASC, SSP,
ST10R272 50 1K ROMless 4 16 MB TQFP-100 PWM, MAC,
CAN
ASC = Asynchrounos Serial Interface (UART), SSP = Synchronous Serial Port, SSC =
High-Speed Synchronous Serial Interface, ADC = A/D Converter, PWM = Pulse Width
Modulation Gernerator, CAPCOM = Capture and Compare unit, CAN = Controller Area
Network Interface, MAC = DSP Multiply accumulate, I2C = I Square C unit.
Part numbers starting with SAB are from Infineon Technologies, part numbers starting with
ST are from STMicroelectronics.
For more information on the housings of these microcontrollers and how to adapt test
equipment to these, browser Hitex' adapter web page at
Block Diagramms
The best way to view block diagrams of the C16x devices is using DAvE, Infineon's Digital
Application Engineer: http://www.infineon.com/dave
MICROCONTROLLER COMPARISONS
Comparing microcontrollers is always difficult. Usually each chip manufacturer has
benchmarks showing that their controller is the best. The following comparisons were
published by third party support companies, which all offer products for microcontrollers from
several manufacturers...
12 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
1. The "Context Switch Time" was calculated on the current task that was running, having
its context saved and the higher priority users' task becoming the new running task.
2. The scheduler is written in assembly. So the context switch times stated are not
dependant on any compiler.
3. CMX tried to use "comparable" memory models on each microcontroller. Paging was
not used. No wait states were introduced.
4. The C16x has 2 stack areas (SYSTEM and USER). The RTOS saves and restores the
SYSTEM stack during saving or restoring of a task. The SYSTEM stack is only used to
store the return addresses of nested functions called by a task. Depending on the
number of words used by the system stack, the context switch time may increase. Add
500 nanoseconds for each word in the stack.
The Speed Factor is a theoretic value: if all processors would run with the same internal
speed, they would need "Speed Factor" times longer for the context switching (compared to
the C16x - "of course").
13 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
(*) with C16x, both operands in shift must be held in registers and
hence an additional two states area included for loading number of shifts
into a GPR, Rw.
By considering the simpler instructions which form the bulk of any program, it can be seen
that the CISC requires approximately twice the number of state times of the RISC. For
instructions that change program flow, the CISC overhead is even greater at a factor of 4.
Taken over a complete software system, the RISC advantage should be a reduction in run
times by about 50%.
Persons, email
If you have a question concerning the C16x / ST10 which are NOT answered by this FAQ,
you may want to send it to one of the following email addresses:
Mailing lists
We know of none C16x related mailing list so far - please let us know if you do!
For CAN related topics, there is a mailing list. The archive is at http://www.scruz.net/~cichlid
/can-archive. To subscribe to the list, send an email to can-request@cichlid.com with the
subject "SUBSCRIBE your@email.address".
C16x PRODUCTS
14 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
DAvE
One of the best tools available is DAvE - and he is free. DAvE is Siemens' Digital
Application Engineer and comes on a CD-ROM. DAvE offers a setup wizard helping you to
configure all the peripherals.
A short example: to configure the serial port, simply specify the needed baud rate and select
the functions (like interrupt service routines for transmit, receive and errors) DAvE should
create. Click on the "generate code" button and DAvE generates the C source code -
compilable with Keil or Tasking. For more information on DAvE browse:
http://www.infineon.com/dave.
Free Assemblers
A free MAcro Assembler supporting many embedded microcontrollers including the 80C16x
and ST10 family is available at: http://john.ccac.rwth-aachen.de:8000/as/
Free C compilers
Both Keil and Tasking offer powerfull evaluation versions of their commercial compilers.
Check them out at http://www.keil.com and http://www.tasking.com.
Currently (as of Fall 1999), Hitex Development Tools USA has a special offer for North
American customers. The compiler is included for free with the purchase of their DProbe167
system. For details, see: http://www.hitex.com/hitools/deal.htm.
C16x DOCUMENTATION
Siemens has all Data books and Application notes available on the DAvE CD-ROM.
Including context sensitive and smart search options: http://www.infineon.com/dave.
STMicroelectronics offers their manuals in .PDF files. The data books are available from
their web page http://www.st.com/stonline/books/index.htm.
15 de 16 28/09/17 19:26
80C166 Microcontroller FAQ http://www.esacademy.com/assets/faqs/c16x/#ABOUT
Disclaimer:
This FAQ may not be included in commercial collections or compilations without express
permission from the Embedded Systems Academy.
The information presented was collected from various sources and is presented "as is". The
authors and the Embedded Systems Academy are not responsible for the accuracy of the
contents.
16 de 16 28/09/17 19:26