SlideShare a Scribd company logo
Microcontroller Lab.
Eng.Khaled Tamizi
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١
PPU IUT Cachan
Mechanical Department
Mechatronic
Analog to Digital Conversion
Bibliography
microcontroller PIC 4550 documentation (PDF file)
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٢
PPU IUT Cachan
microcontroller PIC 4550 documentation (PDF file)
optical sensor CNY 70 documentation (PDF file)
MPLAB_C18 librairies documentation (PDF files)
MPLAB_C18 header file adc.h
MPLAB_C18 c file sources (mccsrctraditionnalpmc)
ADC
10 bits
Vin
N
N
0x000
0x3FF
dVin
analog input
internal digital number
Vin
Introduction
microcontroller
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٣
0x000
Vref- Vref+
210
N = Vin
(Vref+ - Vref-)
precision : Vref+ - Vref-
if N=1 dVin =
1024
Vin
Consequence
Example : Vreff- = 0 and Vref+ = 5 Volt
0x000 ≤ N ≤ 0x3ff 0 ≤ N ≤ 1023 precision = 5V / 1024 = 5 mV
In our microcontroller, Vref+ and Vref- are configurable :
-1st configuration Vref- = 0 and Vref+ = VDD = 5 Volt
we’ll use this one
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٤
-1st configuration Vref- = 0 and Vref+ = VDD = 5 Volt
-2nd configuration Vref- and Vref+ are dedicated external pins (PORT A)
0 < Vref+ < 5V 0<Vref-<5V
Conversion time
ADC
10 bits
Vin
N
ST
starts conversion
conversion in progress
Tcon
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٥
ST DONE
DONE
To whom may be concerned ….
our AD converter is a « successive approximation » one
conversion done, N is avalaible
Some software
In our microcontroller :
- ST is set when the internal bit GO/DONE is set by software
- When the conversion is done, this bit is automatically cleared
- N is then available in a 16 bits register (ADRES right or left justified)
GO/DONE = 1
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٦
GO/DONE = 0 ?
N is read
AD flow chart
Some software
In our microcontroller the AD conversion time per bit is defined as TAD.
The conversion needs 11 TAD for 10-bit conversion.
TAD is selectable by software.
internal configuration bits
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٧
TAD = 64 / 48 MHz = 1.3 µµµµs and Tcon = 1.3 x 11 = 14.3 µµµµs
13 analog input channels
AN0
AN1
AN2
Vin
An internal analog multiplexor allows to
choose 1 analog input channel between 13
AN0, AN1, AN2, AN3, AN4 are connected to PORT A
analog
mux
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٨
AN10
AN11
AN12
input selection
AN0, AN1, AN2, AN3, AN4 are connected to PORT A
AN8, AN9, AN10, AN11, AN12 to PORT B
AN5, AN6, AN7 to PORT E
Tmux = 0.2 µµµµs + (temp – 25°C) 0.02 µµµµs/°C
As temp max = 85°C Tmux max = 0.2 µµµµs + 1.2 µµµµs = 1.4 µµµµs
Rs : source impedance, must be < 2,5 kΩΩΩΩ Rss = 2 kΩΩΩΩ
Electrical analog model for one input
When the analog input is selected, the channel must be sampled and hold :
Vin
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٩
-1st step :
the switch is closed, CHOLD is charged Vin = VDD (1 – e –t/ττττ) with ττττ= (Rs+Ric+Rss)CHOLD
Maximum charging time reached when Vin = VDD 1023 / 1024 (1/2 LSB)
Tc = ττττ ln(2048) = 1.05 µµµµs
- 2nd step : the switch is opened, Vin is read and converted (Tcon)
- 3rd step : CHOLD is discharged
Before conversion, the minimum required sample time (worst case) = 2,45 µµµµs
Some software
The PIC microcontroller provides 2 ways to manage with AD conversion
1st method : « manual »
delay set by software
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٠
The user must ensure that the required time (2.45 µµµµs) as passed between
selecting the desired channel and setting GO/DONE
Some software
The PIC microcontroller provides 2 ways to manage with AD conversion
2nd method : « automatic »
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١١
When GO/DONE is set, the AD module continues to sample the selected input
for the selected acquisition time (TACQ). The conversion then automatically begins.
TACQ is configurable between 0 TAD and 20 TAD
We’ll choose TACQ = 2 TAD = 2.6 µµµµs < 2.45 µµµµs
Our configuration
We use AN0, AN1, AN2, AN3, AN4 (PORT A RA0, RA1, RA2, RA3, RA5)
Vdd
AN0
potentiometer
10K
AN1, AN2, AN3, AN4 are all connected
to a reflective optical sensor
Vdd
AN1 or 2, 3, 4
Vdd
Rd Rt
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٢
AN0
AN0 is connected
to a potentiometer
LED Phototransistor
Microchip C functions
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٣
More in the documentations …..
header file : adc.h
An example : reading the potentiometer
void main(void)
{
int i;
short N;
// Configure ADC
OpenADC(ADC_FOSC_64 & ADC_RIGHT_JUST & ADC_2_TAD,
ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS ,0x0A);
only AN0, AN1, AN2, AN3 are analog inputs
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٤
for(i=0;i<5;i++) // performs 5 acquisitions
{
}
CloseADC();
}
while (BusyADC() == 1); // Wait until conversion is done
N = ReadADC(); // Read N
ConvertADC(); // Start sampling and conversion
Let’s go back to the OpenADC function
OpenADC
(
ADC_FOSC_64
&
ADC_RIGHT_JUST
&
ADC_2_TAD
,
ADC_CH0
&
ADC_INT_OFF
// TAD = 64 TOSC
// N (10 bits) is right justified in a 16 bits register
// TACQ = 2 TAD performs « automatic » conversion
// multiplexor on Channel 0
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٥
ADC_INT_OFF
&
ADC_VREFPLUS_VDD
&
ADC_VREFMINUS_VSS
,
0x0A
);
//0x0A = (00001010)2 only AN0, AN1, AN2, AN3 are used as analog inputs
Prototype :
void OpenADC (unsigned char config1, unsigned char config2, unsigned char portconfig);
// ADC interrupt OFF
// Vref+ = VDD = 5 Volt
// Vref- = VSS = 0 Volt
void main(void)
{
int i;
short N;
OpenADC(ADC_FOSC_64 & ADC_RIGHT_JUST & ADC_2_TAD,
ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS ,10);
for(i=0;i<5;i++)
{
SetChanADC(ADC_CH0); // Channel 0
An example : to change of channel
no more ADC_CH0
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٦
SetChanADC(ADC_CH0); // Channel 0
ConvertADC();
while (BusyADC() == 1);
N = ReadADC();
SetChanADC(ADC_CH1); // Channel 1
ConvertADC();
while (BusyADC() == 1);
N = ReadADC();
}
CloseADC();
}
Workshops
1 - Displaying the value of the potentiometer on the LCD display
2 - Calibrating the optical sensors with the help of the LCD display
3 – The robot goes straight when the jack is off and stops when the floor is white
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٧
3 – The robot goes straight when the jack is off and stops when the floor is white
5 – The robot follows the white line
4 – The potentiometer is used to control the speed of the robot

More Related Content

What's hot

Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR Libraries
Corrado Santoro
 
Microcontroller Instruction Set atmel
Microcontroller Instruction Set atmelMicrocontroller Instruction Set atmel
Microcontroller Instruction Set atmel
Ruderocker Billy
 
Embedded c & working with avr studio
Embedded c & working with avr studioEmbedded c & working with avr studio
Embedded c & working with avr studio
Nitesh Singh
 

What's hot (20)

174085193 pic-prgm-manual
174085193 pic-prgm-manual174085193 pic-prgm-manual
174085193 pic-prgm-manual
 
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
AVR_Course_Day6 external hardware  interrupts and analogue to digital converterAVR_Course_Day6 external hardware  interrupts and analogue to digital converter
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
 
Intrerfacing i
Intrerfacing iIntrerfacing i
Intrerfacing i
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontroller
 
Embedded System Programming on ARM Cortex M3 and M4 Course
Embedded System Programming on ARM Cortex M3 and M4 CourseEmbedded System Programming on ARM Cortex M3 and M4 Course
Embedded System Programming on ARM Cortex M3 and M4 Course
 
GPIO In Arm cortex-m4 tiva-c
GPIO In Arm cortex-m4 tiva-cGPIO In Arm cortex-m4 tiva-c
GPIO In Arm cortex-m4 tiva-c
 
PLC Training Intro
PLC Training IntroPLC Training Intro
PLC Training Intro
 
Pe 5421 plc aftermid week 10 onwards
Pe 5421 plc aftermid week 10 onwardsPe 5421 plc aftermid week 10 onwards
Pe 5421 plc aftermid week 10 onwards
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR Libraries
 
Microcontroller Instruction Set atmel
Microcontroller Instruction Set atmelMicrocontroller Instruction Set atmel
Microcontroller Instruction Set atmel
 
Ab PLC Cables Drivers Sample
Ab PLC Cables Drivers SampleAb PLC Cables Drivers Sample
Ab PLC Cables Drivers Sample
 
89c5131datasheet
89c5131datasheet89c5131datasheet
89c5131datasheet
 
AVR Fundamentals
AVR FundamentalsAVR Fundamentals
AVR Fundamentals
 
Presentation
PresentationPresentation
Presentation
 
Part-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver developmentPart-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver development
 
Plc (analog and special io)
Plc (analog and special io)Plc (analog and special io)
Plc (analog and special io)
 
Synthesis & FPGA Implementation of UART IP Soft Core
Synthesis & FPGA Implementation of UART IP Soft CoreSynthesis & FPGA Implementation of UART IP Soft Core
Synthesis & FPGA Implementation of UART IP Soft Core
 
Overview of LPC213x MCUs
Overview of LPC213x MCUsOverview of LPC213x MCUs
Overview of LPC213x MCUs
 
Embedded c & working with avr studio
Embedded c & working with avr studioEmbedded c & working with avr studio
Embedded c & working with avr studio
 
Introduction to Stellaris Family Microcontrollers
Introduction to Stellaris Family MicrocontrollersIntroduction to Stellaris Family Microcontrollers
Introduction to Stellaris Family Microcontrollers
 

Viewers also liked

Viewers also liked (10)

Lecture 4 i2 c bus & interrupts
Lecture 4   i2 c bus & interruptsLecture 4   i2 c bus & interrupts
Lecture 4 i2 c bus & interrupts
 
Raspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Raspberry Pi - Lecture 4 Hardware Interfacing Special CasesRaspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Raspberry Pi - Lecture 4 Hardware Interfacing Special Cases
 
Braking performance 4
Braking  performance 4Braking  performance 4
Braking performance 4
 
Lecture 1 microcontroller overview
Lecture 1   microcontroller overviewLecture 1   microcontroller overview
Lecture 1 microcontroller overview
 
The Uses of Nanosensors: From Smart Dust to Nano “Mother Ships”
The Uses of Nanosensors: From Smart Dust to Nano “Mother Ships”The Uses of Nanosensors: From Smart Dust to Nano “Mother Ships”
The Uses of Nanosensors: From Smart Dust to Nano “Mother Ships”
 
Hydrolic Fluid purpose & properties (chapter 2)
Hydrolic Fluid purpose & properties (chapter 2)Hydrolic Fluid purpose & properties (chapter 2)
Hydrolic Fluid purpose & properties (chapter 2)
 
Single phase im-lecture_10_1
Single phase im-lecture_10_1Single phase im-lecture_10_1
Single phase im-lecture_10_1
 
Hydraulic pumps performance and Characteristics
Hydraulic pumps performance and CharacteristicsHydraulic pumps performance and Characteristics
Hydraulic pumps performance and Characteristics
 
VEHICLE ROLLOVER ANALYSIS
VEHICLE ROLLOVER ANALYSISVEHICLE ROLLOVER ANALYSIS
VEHICLE ROLLOVER ANALYSIS
 
Sensors, Proximity sensors. Optical – Through-beam, Optical - Diffuse
Sensors, Proximity sensors. Optical – Through-beam, Optical - DiffuseSensors, Proximity sensors. Optical – Through-beam, Optical - Diffuse
Sensors, Proximity sensors. Optical – Through-beam, Optical - Diffuse
 

Similar to Lecture 3a analog to digital converter

Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converter
Corrado Santoro
 
Radio frequency identification system
Radio frequency identification systemRadio frequency identification system
Radio frequency identification system
Aminu Bugaje
 
5.3 Data conversion
5.3 Data conversion5.3 Data conversion
5.3 Data conversion
lpapadop
 

Similar to Lecture 3a analog to digital converter (20)

Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148
 
Analog to Digital Converter
Analog to Digital ConverterAnalog to Digital Converter
Analog to Digital Converter
 
Módulo adc 18f4550
Módulo adc   18f4550Módulo adc   18f4550
Módulo adc 18f4550
 
04 adc (pic24, ds pic with dma)
04 adc (pic24, ds pic with dma)04 adc (pic24, ds pic with dma)
04 adc (pic24, ds pic with dma)
 
Jp
Jp Jp
Jp
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for record
 
8051 FINIAL
8051 FINIAL8051 FINIAL
8051 FINIAL
 
Anup2
Anup2Anup2
Anup2
 
PWM Step-down Converter(NJM2309)
PWM Step-down Converter(NJM2309)PWM Step-down Converter(NJM2309)
PWM Step-down Converter(NJM2309)
 
Em s7 plc
Em s7 plcEm s7 plc
Em s7 plc
 
lab_ADC.pdf
lab_ADC.pdflab_ADC.pdf
lab_ADC.pdf
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converter
 
2016 03-03 marchand
2016 03-03 marchand2016 03-03 marchand
2016 03-03 marchand
 
Radio frequency identification system
Radio frequency identification systemRadio frequency identification system
Radio frequency identification system
 
5.3 Data conversion
5.3 Data conversion5.3 Data conversion
5.3 Data conversion
 
Analog to Digital converter in ARM
Analog to Digital converter in ARMAnalog to Digital converter in ARM
Analog to Digital converter in ARM
 
ANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTOR
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
UiPath New York Community Day in-person event
UiPath New York Community Day in-person eventUiPath New York Community Day in-person event
UiPath New York Community Day in-person event
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
КАТЕРИНА АБЗЯТОВА «Ефективне планування тестування ключові аспекти та практ...
КАТЕРИНА АБЗЯТОВА  «Ефективне планування тестування  ключові аспекти та практ...КАТЕРИНА АБЗЯТОВА  «Ефективне планування тестування  ключові аспекти та практ...
КАТЕРИНА АБЗЯТОВА «Ефективне планування тестування ключові аспекти та практ...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 

Lecture 3a analog to digital converter

  • 1. Microcontroller Lab. Eng.Khaled Tamizi Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١ PPU IUT Cachan Mechanical Department Mechatronic
  • 2. Analog to Digital Conversion Bibliography microcontroller PIC 4550 documentation (PDF file) Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٢ PPU IUT Cachan microcontroller PIC 4550 documentation (PDF file) optical sensor CNY 70 documentation (PDF file) MPLAB_C18 librairies documentation (PDF files) MPLAB_C18 header file adc.h MPLAB_C18 c file sources (mccsrctraditionnalpmc)
  • 3. ADC 10 bits Vin N N 0x000 0x3FF dVin analog input internal digital number Vin Introduction microcontroller Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٣ 0x000 Vref- Vref+ 210 N = Vin (Vref+ - Vref-) precision : Vref+ - Vref- if N=1 dVin = 1024 Vin
  • 4. Consequence Example : Vreff- = 0 and Vref+ = 5 Volt 0x000 ≤ N ≤ 0x3ff 0 ≤ N ≤ 1023 precision = 5V / 1024 = 5 mV In our microcontroller, Vref+ and Vref- are configurable : -1st configuration Vref- = 0 and Vref+ = VDD = 5 Volt we’ll use this one Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٤ -1st configuration Vref- = 0 and Vref+ = VDD = 5 Volt -2nd configuration Vref- and Vref+ are dedicated external pins (PORT A) 0 < Vref+ < 5V 0<Vref-<5V
  • 5. Conversion time ADC 10 bits Vin N ST starts conversion conversion in progress Tcon Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٥ ST DONE DONE To whom may be concerned …. our AD converter is a « successive approximation » one conversion done, N is avalaible
  • 6. Some software In our microcontroller : - ST is set when the internal bit GO/DONE is set by software - When the conversion is done, this bit is automatically cleared - N is then available in a 16 bits register (ADRES right or left justified) GO/DONE = 1 Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٦ GO/DONE = 0 ? N is read AD flow chart
  • 7. Some software In our microcontroller the AD conversion time per bit is defined as TAD. The conversion needs 11 TAD for 10-bit conversion. TAD is selectable by software. internal configuration bits Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٧ TAD = 64 / 48 MHz = 1.3 µµµµs and Tcon = 1.3 x 11 = 14.3 µµµµs
  • 8. 13 analog input channels AN0 AN1 AN2 Vin An internal analog multiplexor allows to choose 1 analog input channel between 13 AN0, AN1, AN2, AN3, AN4 are connected to PORT A analog mux Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٨ AN10 AN11 AN12 input selection AN0, AN1, AN2, AN3, AN4 are connected to PORT A AN8, AN9, AN10, AN11, AN12 to PORT B AN5, AN6, AN7 to PORT E Tmux = 0.2 µµµµs + (temp – 25°C) 0.02 µµµµs/°C As temp max = 85°C Tmux max = 0.2 µµµµs + 1.2 µµµµs = 1.4 µµµµs
  • 9. Rs : source impedance, must be < 2,5 kΩΩΩΩ Rss = 2 kΩΩΩΩ Electrical analog model for one input When the analog input is selected, the channel must be sampled and hold : Vin Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ٩ -1st step : the switch is closed, CHOLD is charged Vin = VDD (1 – e –t/ττττ) with ττττ= (Rs+Ric+Rss)CHOLD Maximum charging time reached when Vin = VDD 1023 / 1024 (1/2 LSB) Tc = ττττ ln(2048) = 1.05 µµµµs - 2nd step : the switch is opened, Vin is read and converted (Tcon) - 3rd step : CHOLD is discharged Before conversion, the minimum required sample time (worst case) = 2,45 µµµµs
  • 10. Some software The PIC microcontroller provides 2 ways to manage with AD conversion 1st method : « manual » delay set by software Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٠ The user must ensure that the required time (2.45 µµµµs) as passed between selecting the desired channel and setting GO/DONE
  • 11. Some software The PIC microcontroller provides 2 ways to manage with AD conversion 2nd method : « automatic » Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١١ When GO/DONE is set, the AD module continues to sample the selected input for the selected acquisition time (TACQ). The conversion then automatically begins. TACQ is configurable between 0 TAD and 20 TAD We’ll choose TACQ = 2 TAD = 2.6 µµµµs < 2.45 µµµµs
  • 12. Our configuration We use AN0, AN1, AN2, AN3, AN4 (PORT A RA0, RA1, RA2, RA3, RA5) Vdd AN0 potentiometer 10K AN1, AN2, AN3, AN4 are all connected to a reflective optical sensor Vdd AN1 or 2, 3, 4 Vdd Rd Rt Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٢ AN0 AN0 is connected to a potentiometer LED Phototransistor
  • 13. Microchip C functions Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٣ More in the documentations ….. header file : adc.h
  • 14. An example : reading the potentiometer void main(void) { int i; short N; // Configure ADC OpenADC(ADC_FOSC_64 & ADC_RIGHT_JUST & ADC_2_TAD, ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS ,0x0A); only AN0, AN1, AN2, AN3 are analog inputs Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٤ for(i=0;i<5;i++) // performs 5 acquisitions { } CloseADC(); } while (BusyADC() == 1); // Wait until conversion is done N = ReadADC(); // Read N ConvertADC(); // Start sampling and conversion
  • 15. Let’s go back to the OpenADC function OpenADC ( ADC_FOSC_64 & ADC_RIGHT_JUST & ADC_2_TAD , ADC_CH0 & ADC_INT_OFF // TAD = 64 TOSC // N (10 bits) is right justified in a 16 bits register // TACQ = 2 TAD performs « automatic » conversion // multiplexor on Channel 0 Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٥ ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS , 0x0A ); //0x0A = (00001010)2 only AN0, AN1, AN2, AN3 are used as analog inputs Prototype : void OpenADC (unsigned char config1, unsigned char config2, unsigned char portconfig); // ADC interrupt OFF // Vref+ = VDD = 5 Volt // Vref- = VSS = 0 Volt
  • 16. void main(void) { int i; short N; OpenADC(ADC_FOSC_64 & ADC_RIGHT_JUST & ADC_2_TAD, ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS ,10); for(i=0;i<5;i++) { SetChanADC(ADC_CH0); // Channel 0 An example : to change of channel no more ADC_CH0 Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٦ SetChanADC(ADC_CH0); // Channel 0 ConvertADC(); while (BusyADC() == 1); N = ReadADC(); SetChanADC(ADC_CH1); // Channel 1 ConvertADC(); while (BusyADC() == 1); N = ReadADC(); } CloseADC(); }
  • 17. Workshops 1 - Displaying the value of the potentiometer on the LCD display 2 - Calibrating the optical sensors with the help of the LCD display 3 – The robot goes straight when the jack is off and stops when the floor is white Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup ١٧ 3 – The robot goes straight when the jack is off and stops when the floor is white 5 – The robot follows the white line 4 – The potentiometer is used to control the speed of the robot