SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

174085193 pic-prgm-manual
174085193 pic-prgm-manual174085193 pic-prgm-manual
174085193 pic-prgm-manualArun Shan
 
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 converterMohamed Ali
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontrollerRAMPRAKASHT1
 
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 CourseFastBit Embedded Brain Academy
 
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-cZakaria Gomaa
 
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 onwardsCharlton Inao
 
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 LibrariesCorrado Santoro
 
Microcontroller Instruction Set atmel
Microcontroller Instruction Set atmelMicrocontroller Instruction Set atmel
Microcontroller Instruction Set atmelRuderocker Billy
 
AVR Fundamentals
AVR FundamentalsAVR Fundamentals
AVR FundamentalsVinit Vyas
 
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 developmentFastBit Embedded Brain Academy
 
Plc (analog and special io)
Plc (analog and special io)Plc (analog and special io)
Plc (analog and special io)Mohamed A Hakim
 
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 Coreijsrd.com
 
Overview of LPC213x MCUs
Overview of LPC213x MCUsOverview of LPC213x MCUs
Overview of LPC213x MCUsPremier Farnell
 
Embedded c & working with avr studio
Embedded c & working with avr studioEmbedded c & working with avr studio
Embedded c & working with avr studioNitesh Singh
 
Introduction to Stellaris Family Microcontrollers
Introduction to Stellaris Family MicrocontrollersIntroduction to Stellaris Family Microcontrollers
Introduction to Stellaris Family MicrocontrollersPremier Farnell
 

La actualidad más candente (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
 

Destacado (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 a Lecture 3a analog to digital converter

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 LPC2148Omkar Rane
 
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)antonio michua
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
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 recordG Lemuel George
 
PWM Step-down Converter(NJM2309)
PWM Step-down Converter(NJM2309)PWM Step-down Converter(NJM2309)
PWM Step-down Converter(NJM2309)Tsuyoshi Horigome
 
lab_ADC.pdf
lab_ADC.pdflab_ADC.pdf
lab_ADC.pdfboukomra
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converterCorrado Santoro
 
2016 03-03 marchand
2016 03-03 marchand2016 03-03 marchand
2016 03-03 marchandSCEE Team
 
Radio frequency identification system
Radio frequency identification systemRadio frequency identification system
Radio frequency identification systemAminu Bugaje
 
5.3 Data conversion
5.3 Data conversion5.3 Data conversion
5.3 Data conversionlpapadop
 
Analog to Digital converter in ARM
Analog to Digital converter in ARMAnalog to Digital converter in ARM
Analog to Digital converter in ARMAarav Soni
 
ANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORAnil Yadav
 

Similar a 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
 

Último

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 

Último (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 

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