Beruflich Dokumente
Kultur Dokumente
INTERFACING
By: Zunainah Binti Hamid
Learning Outcomes:
1. Identify the minimum hardware
connection so that the PIC microcontroller
can operate.
2. Identify the bits of configuration register to
select features that are appropriate to the
hardware used.
3. Describe the features of external devices
that can be interfaced with PIC
microcontroller.
4. Identify I/O pin of PIC used for interfacing.
INTRODUCTION TO HARDWARE
INTERFACING
In PIC18, depending on the device selected and
features enabled, there are up to five ports
available.
All pins of the I/O ports are multiplexed with one
or more alternate functions from the peripheral
features on the device.
In general, when a peripheral is enables, that
pin may not be used as a general purpose I/O
pin
Refer datasheet on I/O multiplexed features
pg136
Learning Outcomes:
1. Explain the digital input/output in
PIC
2. Give examples of simple digital I/O
circuit
3. Give examples of C Program to read
and write digital signal at I/O pins.
4. Explain the Analog-to-Digital
Converter (ADC) module in the PIC.
Learning Outcomes:
5. Give examples of C program to read
analogue signal from external
devices.
6. Explain the Pulse Width
Modulation (PWM) feature in the PIC
7. Give examples of C program to
create PWM output
Learning Outcomes:
8. Explain the Universal Synchronous
Receiver/Transmitter (USART) setting in
the PIC according to the external
devices features
9. Give examples of C program to
configure USART setting in the PIC
according to the external devices
features.
ADC MODULE
Analog to Digital Converter (ADC) is a
device that converts an analog quantity
(continuous voltage) to discrete digital
values.
Very useful when processing on physical
quantities, which are normally analog in
nature (speed, pressure, temperature etc.).
Most of the PIC Microcontrollers have built
in ADC Module with 8-input channel.
ADC MODULE
In PIC18, ADC allows conversion of
analog input signal to a 10-bit binary
signal.
Analog input are multiplexed into a
single sample and hold circuit. The
connected to converter circuit
(Successive Approximation
Conversion).
Then, a 10-bit binary result stores
into the ADC registers (ADRESL &
EXAMPLE OF ANALOG
DEVICES
1.
2.
3.
4.
5.
Light Sensors
Temperature Sensors
Touch Screens
Microphones for audio recording
And many more.
ADC REGISTERS
PIC ADC has the following registers :
ADCON0 ADC Control Register 0
ADCON1 ADC Control Register 1
ADCON2 ADC Control Register 2
ADRESH ADC Result High Register
ADRESL ADC Result Low Register
ADCON0 REGISTER
ADCON0 REGISTER
The CHS <4:0> bits are used to select the
ADC input channel .
Example, by setting all these bits to
0011 means channel 3 or AN3 port was
selected
ADCON0=0b00001101 // ADC channel AN3
ADCON1 REGISTER
ADCON1 REGISTER
To tell ADC peripheral either
internal/external voltage references.
0 = internal reference voltage
ADCON1=0b00000000; // Use Internal
Voltage Reference (Vdd and Vss)
ADCON2 REGISTER
ADCON2 Register
To set 10-bit ADC result
representation in ADRESL and
ADRESH)
To select ADC acquisition time
To set ADC conversion clock
ADFM = 1 for right justify, 0 for
LEFT justify
EXAMPLE OF C
PROGRAM TO
READ ANALOG
SIGNAL
EXAMPLE OF C
PROGRAM TO
READ ANALOG
SIGNAL
PWM RESOURCES
PWM APPLICATIONS
1. Motor Speed Control
2. Servo Control
3. Varying the brightness of an LED
PWM CALCULATION
PWM Period = Total amount of ON
& OFF time
PWM Resolution = The max
number of steps that can be present
in a single PWM Period.
Duty Cycle = The proportion of the
ON time to the OFF time and
expressed in %.
PWM OPERATION
In PWM, the period, duty cycle, and
resolution are controlled by the
following registers:
i.
ii.
iii.
iv.
PRx
TxCON
CCPRxL
CCPxCON
CCPxCON REGISTER
PWM Period
PWM Period is specified by the PRx
register .
The PWM Period can be calculated
using :
PWM RESOLUTION
C Code
EUSART
In Lab 6
In Lab 5