Course Introduction Purpose This course provides an overview of the standard peripheral functions that the microcontrollers in the M16C series provide. Objectives Learn about the features and operation of the Programmable I/O ports. Understand the functions and modes of the various on-chip timers. Discover how the Serial I/O function operates. Content 28 pages 4 questions Learning Time 40 minutes 1
Programmable I/O Ports Pull Up Selection Direction Register Function Select Register Port Control Register Data Bus Port Latch I/O Pin Input to Peripheral Function Analog Input/Output Basic open drain port CMOS Port 2
I/O Port Registers 3
PROPERTIES On passing, 'Finish' button: On failing, 'Finish' button: Allow user to leave quiz: User may view slides after quiz: User may attempt quiz: Goes to Next Slide Goes to Slide After user has completed quiz After passing quiz Unlimited times
Highly-Functional On-chip Timers Up to eleven 16-bit timers with input and output functions All timers can be connected in cascade Various operating modes are available Wide range of applications can be handled Input Modes Output Modes Event Counter Two-phase Pulse Signal Processing Pulse Period Measurement Pulse Width Measurement M16C MCU One Shot timer 8-bit PWM output 16-bit PWM output Three-phase PWM output 5
Timer Types, Operating Modes 6
Timer A Databus high-order bits f1 or f2 f8 f32 fc32 TAi In TB2 overflow TA overflow Clock source ion Polarity ion TAk overflow Timer One Shot PWM Timer (gate function) Event Counter Clock ion To external trigger circuit Clock ion TABSR Down count UDF Databus low-order bits Low-order 8 bits Reload Counter Up-count/ Down count (always counts down, except in Event Counter mode) High-order 8 bits Pulse out TAi Out Toggle flip-flop 7
Timer B Databus high-order bits f1 or f2 f8 Clock source ion f32 fc32 Timer Pulse Period Measurement Pulse Width Measurement Event Counter Clock ion Databus low-order bits Low-order 8 bits Reload Counter High-order 8 bits TBi IN Polarity switching, edge pulse TABSR TBSR Can be ed only in Event counter mode Counter Reset circuit TBj overflow 8
Timer S Request by matching G1BTRR & base timer Request by matching G1PO0 & base timer BTS Request from INT1 pin Base timer reset f1 or f2 Two-phase pulse input BCK1 to BCK0 Divider Base timer Base timer overflow request Base timer reset Base timer reset request Base timer interrupt INPC10 INPC11 G1TM0, G1PO0 G1TM1, G1PO1 PWM output OUTC10 OUTC11 INPC12 INPC13 G1TM2, G1PO2 G1TM3, G1PO3 PWM output OUTC12 OUTC13 INPC14 INPC15 G1TM4, G1PO4 G1TM5, G1PO5 PWM output OUTC14 OUTC15 INPC17 INPC16 debounce Gate function Gate function Prescaler function Prescaler function G1TM6, G1PO6 G1TM7, G1PO7 PWM output OUTC16 OUTC17 9 Interrupt request signal
Timer S Request by matching G1BTRR & base timer Request by matching G1PO0 & base timer BTS Request from INT1 pin Base timer reset f1 or f2 Two-phase pulse input BCK1 to BCK0 Divider Base timer Base timer overflow request Base timer reset Base timer reset request Base timer interrupt INPC10 INPC11 G1TM0, G1PO0 G1TM1, G1PO1 PWM output OUTC10 OUTC11 INPC12 INPC13 G1TM2, G1PO2 G1TM3, G1PO3 PWM output OUTC12 OUTC13 INPC14 INPC15 G1TM4, G1PO4 G1TM5, G1PO5 PWM output OUTC14 OUTC15 INPC17 INPC16 debounce Gate function Gate function Prescaler function Prescaler function G1TM6, G1PO6 G1TM7, G1PO7 PWM output OUTC16 OUTC17 10 Interrupt request signal
PROPERTIES On passing, 'Finish' button: On failing, 'Finish' button: Allow user to leave quiz: User may view slides after quiz: User may attempt quiz: Goes to Next Slide Goes to Slide After user has completed quiz After passing quiz Unlimited times
Timer Mode The timer counts an internally or externally generated count source. Operation: When the timer underflows, it generates an interrupt and toggles an output pin (Timer A only), then reloads the contents before continuing to count. Timer Mode Register (TAMR or TBMR) 00h 04h Timer AB Start/Stop Register (TABSR) 00h 01h Reload FFFF 0002 Count Source f1 f2 f8 f32 fc32 TAin pin (gate) 0 1 FFFF 0001 0000 0002 Counter Count Start flag (TABSR ) 12 TAout pin Timer Interrupt
Event Counter Mode The timer counts an external signal fed to TAi pin. Operation: When the timer underflows, it reloads the contents before continuing to count. Timer Mode Register (TAMR or TBMR) 00h 05h Timer AB Start/Stop Register (TABSR) 00h 01h Reload Register FFFF 0002 TAi / TBi pin 10 FFFF 0001 0000 0002 Counter Timer Interrupt External Count Source or Under/Overflow from another timer Count Start flag (TABSR ) 13 TAout pin
One Shot Timer Mode The timer, when triggered, outputs one pulse of a specific width. Timer Mode Register (TAMR or TBMR) 00h 06h Timer AB Start/Stop Register (TABSR) Count Source f1 f8 f32 f2 fc32 00h 01h Count Start flag 01 Reload FFFF 0002 FFFF 0001 0000 0002 021010210 Counter TAout pin Triggered by TAin pin or Overflow/Underflow from another timer 14 One-shot Output is high when counting and low when not counting. Reload value determines width of pulse.
Pulse Width Modulation Mode The timer outputs a stream of pulses; each pulse can be set to a specific width. 1/fi X (2 16-1) Count source Input signal to TAiIN pin PWM pulse output from TAiOUT pin 1 / fj X n Trigger is not generated by this signal IR bit of TAiIC Fj: Frequency of count source (f1, f2, f8, f32, fc32) Set to 0 upon accepting an interrupt request or by setting bit in software Note: n = 000016 to FFFE16. 15
Pulse Period, Width Measurement The timer measures the pulse period or pulse width of an external signal applied to the TBin pin. Count source Measurement pulse Reload <-- counter transfer timing Timing when counter reaches 0000 Transfer Counter reset to 0000 Transfer Counter reset to 0000 Timer has overflowed Timer Start /Stop bit Interrupt request flag Timer Overflow flag in Mode 16
Waveform Generation (Timer S) The timer produces output waveforms whose characteristics are determined by values set in s. Examples: Single-Phase Waveform output Phase-Delayed output Set/Reset Waveform output Base timer Waveform Generation a+1 Set value Waveform Generation a Set value YYYY 16 (YYYY 16 is the setting value of base timer reset.) 0000 16 Single-Phase Waveform Output Phase Delayed Waveform Output Set/Reset Waveform Output 17
Time Measurement (Timer S) The timer determines the time elapsed between events. INPC1 input pin FFFF Base timer n p m 0000 Time Measurement m n p Interrupt request bit Cleared by user 18
PROPERTIES On passing, 'Finish' button: On failing, 'Finish' button: Allow user to leave quiz: User may view slides after quiz: User may attempt quiz: Goes to Next Slide Goes to Slide After user has completed quiz After passing quiz Unlimited times
Three-Phase Motor Control 3-Phase Inverter PWM Output Applied to a Motor-Control System M16C MCU NMI Emergency stop signal TIMERS 3-phase inverter PWM output U _ U V _ V Motor driver 2-phase pulsesignal processing High-speed A/D converter W W Phase A Phase B Encoder signal input Current monitoring Phase detector (resolver) Position detection Motor 20
Three-Phase Controller Design Timer B2 Deadtime Control Timer A4 Phase U Output Control Unit U Phase Timer A1 Timer A2 V Phase W Phase 21
Motor Timer B2 Deadtime Control Timer A4 Phase U Output Control Unit U Phase Timer A1 Timer A2 V Phase W Phase 22
Serial I/O Up to 5 serial I/O channels Channels may support: Both UART (clock-asynchronous) and clock-synchronous modes Clock-synchronous mode only Special communications formats (I 2 C, IEBus, SIM) Bi-directional data communications supported. UART/clock-synchronous serial I/O: Character length: 7/8/9 bits, as ed Parity bit: as odd, even, or none Stop bit: 1 or 2 bits, as ed 8-bit clock synchronous I 2 C-bus subset operation is available IEBus and SIM subset operation also available Clock synchronous serial I/O: 8-bit clock synchronous MCU MCU UART0 UART1 M16C MCU UART2 SI03 SI04 MCU MCU MCU 23
Connections, Baud Rates Transmitter IC Receiver IC Receiver/Transmitter IC #1 Receiver/Transmitter IC #2 RxD TxD Clk CTS RTS RxD TxD Clk RTS CTS RxD TxD CTS RTS RxD TxD RTS CTS Connection example for synchronous communication (Maximum data rate in clock synchronous mode: 5M bits per second) In the UART asynchronous mode, data rates up to and above 57,600 bits per second are achievable, especially with M16C system clock frequencies above 16MHz or with special crystal frequencies chosen to minimize bit error rates. In the clock synchronous mode, the maximum date rate is 5 Megabits per second. This limit is determined by the receive-data setup and hold time in the M16C MCU, plus the external clock input s minimal cycle time, which is 200 nanoseconds at 5V. Baud Rate (bps) 2400 9600 24 Connection example for asynchronous communication Baud rates and Baud Rate Generator settings in UART mode BRG s Count source 600 f8 f8 f1 System clock: 16MHz BRG s set value:n 207(CF 16 ) 51(33 16 ) 103(67 16 ) Actual time (bps) 601 2404 9615 BRG s set value:n 95(5F 16 ) 23(17 16 ) 45(2F 16 ) 7.3728MHz Actual time (bps) 600 2400 9600 19200 f1 51(33 16 ) 19231 23(17 16 ) 19200 38400 f1 25(19 16 ) 38461 11(0b 16 ) 38400 57600 f1 16(10 16 ) 58823 07(08 16 ) 57600
UART Channel Main Clock, PLL or Ring Oscillator 1/2 1/8 f1sio or f2sio f8sio (UARTx) RxD0 RxD polarity reversing circuit 1/4 f32sio TxD0 f1sio or f2sio f8sio f32sio Baud Rate Generator Internal 1/(n0+1) External 1/16 (Clock Synchronous type) 1/16 UART reception UART transmission Clock Synchronous type Reception Control Circuit Transmission Control Circuit Receive clock Transmit clock Transmit/ Receive Unit Clock Synchronous type (when internal clock ed) 1/2 Clock Synchronous type (when internal clock ed) Clock Synchronous type (when external clock ed) CLKO Clock Polarity Reversing ckt CTS/ RTS disabled CTS/RTS RTS CTS from other UART 25
Clock Synchronous Channel If the clock source is chosen to be external, then the clock is input from the CLKi pin. 1/2 f1sio or f2sio Databus Main Clock, PLL or Ring Oscillator 1/8 1/4 f8sio f32sio Synchronous circuit 1/2 1/(n+1) Baud Rate Generator CLK i Clock Polarity Reversing ckt SIO counter i SI/O interrupt request Sout i LSB MSB Sin i SIO counter i 8 26
PROPERTIES On passing, 'Finish' button: On failing, 'Finish' button: Allow user to leave quiz: User may view slides after quiz: User may attempt quiz: Goes to Next Slide Goes to Slide After user has completed quiz After passing quiz Unlimited times
Course Summary Programmable I/O ports Timers Serial I/O 28