18
Microcontroller Introduction 2-1

Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Microcontroller Introduction

2-1

Page 2: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Data Formats for the Renesas Microcontroller

Byte– 8 bits– signed & unsigned– unsigned range

0 to 255– unsigned char a;

Word

Embedded Systems 2-2

– 16 bits– signed & unsigned– unsigned range

0 to 65535– int b; unsigned int b;

Longword– 32 bits, signed and unsigned, unsigned range 4,294,967,294– long int c; unsigned long int c;

Page 3: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Review of the Renesas Architecture

Microcontroller has:

– General Purpose Registers

– RAM– Flash– EEPROM

Embedded Systems 2-3

– Digital Ports– Analog Ports– Timers– Oscillator– DMA Controller– Reliability

and safety

Page 4: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Memory Map for Renesas Microcontroller

Embedded Systems 2-4

Page 5: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

A C Code “Project”

• You will use an “Integrated Development Environment” (IDE) to develop, compile, load, and debug your code.

• Your entire code package is called a project. Often you create several files to spilt the functionality:– Several C files– Several include (.h) files– Maybe some assembly language (.a30) files

Embedded Systems 3-5

– Maybe some assembly language (.a30) files– Maybe some assembly language include (.inc) files

• A lab, like “Lab7”, will be your project. You may have three .c, three .h, one .a30, and one .inc files.

Page 6: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Compiling a C Program• Entire mechanism is usually called

the “compiler”• Preprocessor

– macro substitution– conditional compilation– “source-level” transformations

• output is still C

• Compiler

CSource andHeader Files

C Preprocessor

Compiler

Source CodeAnalysis

Embedded Systems 3-6

• Compiler– generates object file

• machine instructions

• Linker– combine object files

(including libraries)into executable image

Analysis

Target CodeSynthesis

Symbol Table

Linker

ExecutableImage

LibraryObject Files

Page 7: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Compiler

• Source Code Analysis– “front end”– parses programs to identify its pieces

• variables, expressions, statements, functions, etc.– depends on language (not on target machine)

• Code Generation– “back end”

Embedded Systems 3-7

– “back end”– generates machine code from analyzed source– may optimize machine code to make it run more efficiently– very dependent on target machine

• Symbol Table– map between symbolic names and items– like assembler, but more kinds of information

Page 8: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Digital Input/Output (I/O) Ports

• The fundamental interfacing subsystem

– Port bits can be inputs or outputs– M30626 has fourteen Programmable I/O

Ports (total of 106 digital I/O bits) (P0 to 13 = 8 bits each, P14 = 2)

– For some other MCUs some ports may be limited to only input or output

• Direction register sets bit direction– Port Direction register names PDx

• 1: Output

Embedded Systems 7-8

• 1: Output• 0: Input

• Data register holds actual data– Port data register names: Px

• M16C62P Hardware Manual

Page 9: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Example: P6 Echoes Nibble Data• Configuring port to desired structure

– Top 4 bits (4-7) of P6 are inputs• Clear bits 4-7 of PD6

– Bottom 4 bits of P6 are outputs• Set bits 0-3 of PD6

Embedded Systems 7-9

Por

t 6

Bits 7-4

Bits 3-0

Page 10: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

���������� ������������������������������������������� �����! !"

#$���%�&��"$#�����%�����%�������"�����%����'%�������"����(%����)%������"

Example in C: P6 Echoes Nibble Data• Reading and writing data

– Load data from input port– Move top nibble to bottom– Write data to output port– Jump back to start

• Now let’s invert the data before writing it out– Load data from input port

Embedded Systems 7-10

�����%����*%������"+�������,

!%��"!--%("��%!"

.

– Move top nibble to bottom– Invert it (complement)– Write data to output port– Jump back to start

Page 11: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Sample Code from Demo��������/�0��1��/#$�� ��0�$#��������/�0��1��/#$�� ��0�$#��������/�0��1��/#$�� ��0�$#��������/�0��1��/#$�� ��0�$#��������/�� �����/��������/�� �����/��������/�� �����/��������/�� �����/��������/234�56���/��������/234�56���/��������/234�56���/��������/234�56���/��������/�0 �� ��/��������/�0 �� ��/��������/�0 �� ��/��������/�0 �� ��/

��������7��57���8���#$� 19:1! �����9�$#��������7��57���8���#$� 19:1! �����9�$#��������7��57���8���#$� 19:1! �����9�$#��������7��57���8���#$� 19:1! �����9�$#�������;75�57���*�(��������;75�57���*�(��������;75�57���*�(��������;75�57���*�(��������<���57���*����������<���57���*����������<���57���*����������<���57���*����������57�������#$������1 57��$#�������57�������#$������1 57��$#�������57�������#$������1 57��$#�������57�������#$������1 57��$#�������57���==����������57���==����������57���==����������57���==���

������������������������������������������������������������������������������������������������������������������������������������

�������2>���8�'��������2>���8�'��������2>���8�'��������2>���8�'��������2>���8����������2>���8����������2>���8����������2>���8����������2>'��8����������2>'��8����������2>'��8����������2>'��8���

?1��9!����,?1��9!����,?1��9!����,?1��9!����,��! :��@AB"��! :��@AB"��! :��@AB"��! :��@AB"�1� ��0�C %��'()"�1� ��0�C %��'()"�1� ��0�C %��'()"�1� ��0�C %��'()"

���0��+�0������"���0��+�0������"���0��+�0������"���0��+�0������"���0�57����"���0�57����"���0�57����"���0�57����"���0�����!D��"���0�����!D��"���0�����!D��"���0�����!D��"

������������������������0��0��+�0������"0��0��+�0������"0��0��+�0������"0��0��+�0������"

�����������������������������!D20 �� �56��5��7�C/����1���/�"�����!D20 �� �56��5��7�C/����1���/�"�����!D20 �� �56��5��7�C/����1���/�"�����!D20 �� �56��5��7�C/����1���/�"�����!D20 �� �56��5��7�C/��9� /�"�����!D20 �� �56��5��7�C/��9� /�"�����!D20 �� �56��5��7�C/��9� /�"�����!D20 �� �56��5��7�C/��9� /�"+�������,+�������,+�������,+�������,

�1 ��%�"�E������F� G)�����"�FF��1 ��%�"�E������F� G)�����"�FF��1 ��%�"�E������F� G)�����"�FF��1 ��%�"�E������F� G)�����"�FF�""""

�%�"�%�"�%�"�%�"�7��57�%;75�57�%<���57�%57����"�7��57�%;75�57�%<���57�%57����"�7��57�%;75�57�%<���57�%57����"�7��57�%;75�57�%<���57�%57����"

Embedded Systems 7-11

�������2>'��8����������2>'��8����������2>'��8����������2>'��8���

?1�����0��+�0������,?1�����0��+�0������,?1�����0��+�0������,?1�����0��+�0������,��8��%��8��%��8�'%������"��8��%��8��%��8�'%������"��8��%��8��%��8�'%������"��8��%��8��%��8�'%������"

....

?1�����0�57����,?1�����0�57����,?1�����0�57����,?1�����0�57����,��8��%��*�(%��*��%�������"��8��%��*�(%��*��%�������"��8��%��*�(%��*��%�������"��8��%��*�(%��*��%�������"�7��57�%;75�57�%<���57�%57����"�7��57�%;75�57�%<���57�%57����"�7��57�%;75�57�%<���57�%57����"�7��57�%;75�57�%<���57�%57����"�7��57�%;75�57�%<���57�%57���=="�7��57�%;75�57�%<���57�%57���=="�7��57�%;75�57�%<���57�%57���=="�7��57�%;75�57�%<���57�%57���=="

....

?1��0��0��+�0�����?1���,?1��0��0��+�0�����?1���,?1��0��0��+�0�����?1���,?1��0��0��+�0�����?1���,+�������,+�������,+�������,+�������,

�7��57�%�H2>��I57����J57���=="�7��57�%�H2>��I57����J57���=="�7��57�%�H2>��I57����J57���=="�7��57�%�H2>��I57����J57���==";75�57�%�H2>��I57����J57���==";75�57�%�H2>��I57����J57���==";75�57�%�H2>��I57����J57���==";75�57�%�H2>��I57����J57���=="<���57�%�H2>'�I57����J57���=="<���57�%�H2>'�I57����J57���=="<���57�%�H2>'�I57����J57���=="<���57�%�H2>'�I57����J57���=="

........

�7��57�%;75�57�%<���57�%57����"�7��57�%;75�57�%<���57�%57����"�7��57�%;75�57�%<���57�%57����"�7��57�%;75�57�%<���57�%57����"+�����2>��+�����2>��+�����2>��+�����2>��

�FF"�FF"�FF"�FF"������������������������

�� ��0��:��C/G8��/C��"�� ��0��:��C/G8��/C��"�� ��0��:��C/G8��/C��"�� ��0��:��C/G8��/C��"�����!D20 �� �56��5��7�C:���"�����!D20 �� �56��5��7�C:���"�����!D20 �� �56��5��7�C:���"�����!D20 �� �56��5��7�C:���"�����!D20 �� �56��5��7�C/�0� ��/�"�����!D20 �� �56��5��7�C/�0� ��/�"�����!D20 �� �56��5��7�C/�0� ��/�"�����!D20 �� �56��5��7�C/�0� ��/�"

���������������������� ��0��:��C/G8�'�/C�$'A��#�8*�*(�"�� ��0��:��C/G8�'�/C�$'A��#�8*�*(�"�� ��0��:��C/G8�'�/C�$'A��#�8*�*(�"�� ��0��:��C/G8�'�/C�$'A��#�8*�*(�"�����!D20 �� �56��5��7�C:���"�����!D20 �� �56��5��7�C:���"�����!D20 �� �56��5��7�C:���"�����!D20 �� �56��5��7�C:���"�����!D20 �� �56��5��7�C/9�������/�"�����!D20 �� �56��5��7�C/9�������/�"�����!D20 �� �56��5��7�C/9�������/�"�����!D20 �� �56��5��7�C/9�������/�"

�������������������������7��57�%;75�57�%<���57�%57���=="�7��57�%;75�57�%<���57�%57���=="�7��57�%;75�57�%<���57�%57���=="�7��57�%;75�57�%<���57�%57���==" %�" %�" %�" %�"+�����H2>��#$+!�0�1 �+�0��01�19�+�����H2>��#$+!�0�1 �+�0��01�19�+�����H2>��#$+!�0�1 �+�0��01�19�+�����H2>��#$+!�0�1 �+�0��01�19���$#��$#��$#��$#

FF" FF" FF" FF"....

....

Page 12: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

From Analog to Digital• Embedded systems often need to measure values of physical parameters• These parameters are usually continuous (analog) and not in a digital form

which computers (which operate on discrete data values) can process• A Comparator is a circuit which compares an analog input voltage with a

reference voltage and determines which is larger, returning a 1-bit number• An Analog to Digital converter [AD or ADC] is a circuit which accepts an

analog input signal (usually a voltage) and produces a corresponding multi-bit number at the output.

Embedded Systems 8-12

���

����

��

�����

����

������������������������������������ ������������������������������������������������

Page 13: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

ADC Basic Functionality• n = converted code• Vin = sampled input voltage• V+ref = upper end of input voltage range• V-ref = lower end of input voltage range• N = number of bits of resolution in ADC

Embedded Systems 8-13

( )( )int

2/112

���

���

�+

−−−

=−+

refref

Nrefin

VV

VVn

( )( )int

2/112

���

���

�+−=

+ref

Nin

VV

n if V-ref = 0v

( )

675int

2/15

1230.3 10

=��

���

�+−=

vv

n

Page 14: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

ADC Transfer Function•The ideal output from an A/D converter is a stair-step function (see right)

– Ideal worst case error in conversion is ± 1/2 bit.

– Missing codes or the imperfections where increasing voltage does not result in the next step being output are described as non-

Out

put C

ode

100010011010101111001101

Out

put C

ode

Nominal Quantizedvalue + 1/2 LSB

Embedded Systems 8-14

output are described as non-monotonicity.

– Errors in A/D conversion may be significant particularly if the full range of the analog signal is significantly less than the range of the analog input of the A/D.

Out

put C

ode

Input Voltage000000010010001101000101011001111000

Out

put C

ode

Missing Code

-10 V

1 LSB

10 V

Page 15: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

M30626P ADC Peripheral

• 10 bit successive approximation converter, can operate in 8 bit mode

• Input voltage: 0 to VCC

• Reference voltage applied to VREF pin– Can be disconnected with VCUT bit to save power

• Input Multiplexer: 8 input channels

Embedded Systems 8-15

Page 16: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Input Mux (262, but 626 similar)

Embedded Systems 8-16

Page 17: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

M30262 Converter Overview (626P similar)

Embedded Systems 8-17

Page 18: Microcontroller Introduction - University of North ...jmconrad/ECGR4161-2010... · Microcontroller Introduction 2-1. Data Formats for the Renesas Microcontroller Byte – 8 bits –

Repeated ADC

• The microcontroller performs repeated A/D conversions, and can read data whenever needed

!��1��%�&88"

!��1��%�&�8"

!��1��%�K��"

!��0%�" ##20! 0!�1�?� ��1��� �

Embedded Systems 8-18

!��0%�" ##20! 0!�1�?� ��1��� �

Then in your procedure��9�201 �%!��L�&�'��"