Allocating Pins/Port Pins In Your Application

Port 0

In all ROMless SAB80C166 designs, this port forms the data bus in non-multiplexed configurations or the combined address/data bus in multiplexed systems. In the FLASH device, this is a general purpose bi-directional IO port.

P0.0 - D0/AD0

P0.15 - D15/AD15

Port 1

In ROMless SAB80C166 designs using the non-multiplexed bus modes, this port forms the data bus in non-multiplexed configurations or the combined address/data bus in multiplexed systems. In the FLASH device, this is a general purpose bi-directional IO port.

Port 2

Besides being general purpose IO pins, Port 2 is equipped with a 16 channel capture and compare unit. This is a means of either generating precisely timed pulses or measuring times for or between events.

Either action is referred to one of two >0.4us per count timers.

In practical terms, the output mode allows up to 16 pulse-width modulated outputs to be produced. These can be configured as 9.5kHz at 8 bit resolution or 1/(1024*0.4)kHz at 10 bits.

By using the PEC system, the update of the duty ratio can be made without CPU intervention. Thus once the table containing the desired waveform has been established, the CPU need play no further part in the PWM generation, other than to calculate the duty ratio.

Both edge-aligned (asymmetrical) and centred (symmetrical) PWM can be produced via the 16 channel capture and compare unit (CAPCOM). The C166 is widely used as an intelligent PWM generator in motor drives and power invertors due to its combination of low-overhead PWM generation and fast core.

Using Mode 1, isolated timed pulse can be generated, as required fields such as ignition and fuel injection control. The SAB80C166 is already used in several high performance engine control systems, including the TAGtronic F1 system.

On the C165, Port 2 hosts 8 very fast response interrupt inputs. These are sampled every 50ns and can guarantee to vector to the service routine in under 250ns. The inputs can be set to trigger on +v, -ve and both edges.

The C167 offers not only another 16 CAPCOM channels but also a dedicated 4 channel PWM module. This is able to generate 78kHz, 8 bit PWM with zero CPU overhead in both asymmetric and symmetric PWM modes. The later capability is useful for electric motor drives.

Baud Rates

Whilst a 40MHz oscillator will give maximum performance, it can be tricky to get "normal" baudrates from the serial ports.

Here are the approximations to the required baudrate at 40MHz and 32MHz:

Baudrates for 40 Mhz

SxBR = 0x003F =>  9600 Baud (9765.625 actual)
SxBR = 0x001F => 19200 Baud (19531.25 actual)
SxBR = 0x000F => 38400 Baud (39062.5 actual)

Baudrates for 32 Mhz

SxBR = 0x0033 =>  9600 Baud (9615.38 actual)
SxBR = 0x0019 => 19200 Baud (19230.77 actual)
SxBR = 0x000C => 38400 Baud (38461 actual)

SxBR is the baudrate counter register of the C166.

At 32MHz, the realisable baudrates are significantly closer to the target figures. The ideal solution is to use a special oscillator of for example, 39.3216MHz to get exactly 9600 baud. However, such devices can be expensive and in most cases the loss of performance in going to 32MHz can be tolerated, especially when the possibility of using cheap 100ns EPROMs is opened up.

The Synchronous Port On The C165/7

The C165/7 only have a single asynchronous serial port with the C166's second port becoming a master/slave synchronous port. Unlike the synchronous modes in the C166's ports, the C165/7 can be both bus Master and Slave. This is intended as a means of allowing the CPU to make use of many industry-standard serial communication standards. These include Philips I2C, Motorola SPI, Profibus, CAN, VAN and others. Some software is required to configure the port to achieve this however. Detailed application notes from Siemens cover these possibilities.

Note: If a second asynchronous port is essential for your application, Hitex can supply a simple software-driven UART routine on request. This is entirely adequate for user interfaces and other undemanding tasks.

Generating PWM With The C166

(i) Assymmetric PWM (edge aligned)

PWM pin goes on when compare register matches the Timer0 value and goes off when timer overflows. The PWM period is determined by the value in the T0REL register. A T0REL value of 0xff00 (-255) yields an 8 bit PWM of period 256*.4us. The PWM on edge only moves when the PWM changes, resulting in an increase of harmonics in motor/transformer windings during duty ratio changes.

[figure]

Example:

  1. Use the User windows in HiTOP166 to setup P2.8 as an edge-aligned PWM.
  2. Use the PWMDEMO program to generate edge-aligned PWM controlled by a potentiometer on analog channel 0. See appendix B for program listing.
  3. Use the PWM program to generate three phase sine waves on P2.8, P2.9 and P2.10 with edge-aligned PWM.
(ii) Symmetrical PWM (centre aligned)

PWM pin goes on when compare register matches the Timer0 value. By using the double register compare mode the PWM pin can be made to go low again when the timer is equi-distant from the reload start count. This yields a PWM waveform in which both the on and off edges move together. Thus a symmetrical PWM is created. This PWM format is to be preferred for driving inductive loads.

Note that the on compare register = -count and the off compare register = reload count + count.

The PWM period is defined by the value in the T0REL register. A T0REL value of 0xff00 (-255) yields an 8 bit PWM of period 256*.4us.

[figure]

Example:

  1. Use the SPWMDEMO program to generate centre-aligned PWM controlled by a potentiometer. See appendix C for program listing.
  2. Use the SYMPWM program to generate three phase sine waves on P2.8, P2.9 and P2.10 with centre-aligned PWM.

Port 3

In addition to providing general purpose IO, this port is connected to the GPT1 and GPT2 timer blocks. These 6 timers can be combined in varous ways to implement gated timers, counters, input capture, output compare, PWM and pulsetrain generation, plus complex software timing functions. The 80C165 has no port 2 CAPCOM unit and so these general purpose timers are of special significance. They allow the C165 to generate and detect real time events, despite its more microprocessor-like appearance. In essence, the C165 is very similar to an 80C32 except it is 20 times faster and indeed, it is alredy under consideration by several existing 80C32 users as an easy performance upgrade.

Example

Generate a 1s interrupt on timer3 to flash an LED on P2.8 on an 80C165. Send a seconds count down serial port 0.

See appendix D for program listing

Port 4

A general purpose digital IO port whose two bits are the A16 and A17 address lines in segmented designs. In the C165, it forms the upper 8 address lines, A16 - A23.

Port 5

10 bit analog input port or general purpose digital input only port with Schmitt trigger inputs. Pins may be allocated to either function freely.

Example:

Read a analog channel 0 using user window in HiTOP166

C165

6 bit Schmitt-trigger input port

Port 6

General purpose bi-directional IO port with push-pull or open drain outputs. Also carries chip select lines for memory decoding and external device enabling.

C165/7 Only

Port 7

General purpose bi-directional IO port with push-pull or open drain outputs. Also input/ouput pins for second capture compare unit, channels 28 to 31.

C167 Only

Port 8

General purpose bi-directional IO port with push-pull or open drain outputs. Also input/ouput pins for second capture compare unit, channels 16 to 23.

C167 Only


[Back] [Contents] [Next]