info-0064 embedded systems · a/d converter how does it work? successive approximation concept v...
TRANSCRIPT
![Page 1: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/1.jpg)
INFO-0064 Embedded systems
Exercise session 3
Introduction to microcontrollers III
Kevin Hogan
9 October 2015
![Page 2: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/2.jpg)
Planning for today
• Practical information
• ADC
• PWM
• Application example: Dimmer
![Page 3: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/3.jpg)
Practical information
• Someone from each group, send me an email today, with every member of your group as copy.
• If you still don’t have any group, send me an email.
• Each group will have a small budget to buy components on be.farnell.com or befr.rs-online.com
![Page 4: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/4.jpg)
PWM module
• Pulse Width Modulation
Two parameters:
TPWM : PWM period
d : Duty cycle
We have a modulation of the average value of the signal
25%
TPWM
d
t
Vout
90%
TPWM
d
t
Vout
![Page 5: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/5.jpg)
PWM module
• Pulse Width Modulation
TPWM : PWM period
d : Duty cycle TPWM
d
t
Vout
TPWM
t
Vout Vout
![Page 6: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/6.jpg)
PWM module: PIC18F4620
• 10-bit resolution PWM output = 10-bit duty cycle [0..1023]
• Timer2 is used
• PWM period is set by PR2 register + TMR2 Prescaler
• PWM duty cycle is set by CCPRxL + CCPxCON<5:4>
![Page 7: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/7.jpg)
PWM module: PIC18F4620
movlw 0xFF ;
movwf PIR2 ; set the PWM period
movlw 0x3F ;
movwf CCPR1L ;
bcf CCP1CON , 4 ; set the 10-bit PWM
bcf CCP1CON , 5 ; duty cycle
bcf TRISC , 3 ; RC2 = output
movlw b’00000111’ ;
movwf T2CON ; configure TMR2
movlw b’00001100’ ;
movwf CCP1CON ; set the PWM
![Page 8: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/8.jpg)
PWM exemple: Servomotors
• Servomotor send a given PWM signal to obtain a certain position
• 3 inputs: Vdd, GND, PWM
Exemple: Servo HS-85BB
• Power supply: 4,8V .. 6V DC
• PWM control:• Amplitude: 3V .. 5V• Period = 20 ms• Duty cycle = [600 .. 2400] µs
The period is out of rang! What can we do?
Figures taken from:http://www.servocity.com/html/hs-85bb__mighty_micro.html
![Page 9: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/9.jpg)
PWM exemple: Servomotors
• Servomotor control
PWM using timer
We have to configure the timer in such way that we have enoughresolution to control the PWM.
Timer 16bits: 1,5 interrupts/period
Timer 8bits: 390 interrupts/period
Timer 8bits + Prescaler 1:4:
97 interrupts/period
![Page 10: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/10.jpg)
A/D Converter
A/D ConverterVin [V] N-bit word
Vref [V]
𝑉𝑚𝑒𝑎𝑠 =𝑁 𝑏𝑖𝑡 𝑤𝑜𝑟𝑑
2𝑁𝑉𝑟𝑒𝑓
• Concept
![Page 11: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/11.jpg)
A/D Converter
How does it work?
Successive approximation concept
A/D ConverterVin [V] N bit word
Sample & HoldVin [V]
Comparator
D/A converter
Vref [V] Control logic
Vref [V]
𝑉𝑚𝑒𝑎𝑠 =𝑁 𝑏𝑖𝑡 𝑤𝑜𝑟𝑑
2𝑁𝑉𝑟𝑒𝑓
![Page 12: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/12.jpg)
A/D Converter
• Sample & Hold circuit
In order to minimize the acquisition time, the maximum recommended impedance for analog sources (RS) is 2.5 kOhm for the PIC18F4620! (cf. datasheet)
ES
RS RIC RSS
CHOLD
Source
Sampling Switch
• Based upon a switch which samples the voltage and stays on long enough in order to let the capacitor fully charge.
• The minimum acquisition time (tACQ,MIN) is the time needed to charge the capacitor to the input channel voltage level. It is proportional to the RC circuit time constant τ = (Rs+ Ric+Rss).Chold
t
VIN
VS&H
samples the input signal and holds the value of the voltage constant during the time of the conversion
VIN
VS&H
![Page 13: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/13.jpg)
A/D Converter
How does it work?
Successive approximation concept
VS&H
Comparator D/A
Vref [V]
Control logic
bit0bit1bit2bit3bit4bit5bit6bit7bit8bit9
LSB
MSB
VDA
• VDA = voltage corresponding to the value stored in the register:
VDA = VDA = (register/ 210)*VREF
• Initially, the register is cleared (VDA
= 0 V)• Starting from the MSB to the LSB:
Current bit is set;If VDA < VS&H, current bit stays setIf VDA > VS&H, current bit is clear
• At the end, the value stored in the register corresponds to the converted voltage
![Page 14: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/14.jpg)
A/D Converter
4-bits register exemplet
VIN
t
VREF VS&H
VDA
1 1 0 1
LSBMSB1 0 0 0
VDA = (register/24) * Vref
MSB LSB
1 1 0 0
VDA = Vref/2, VS&H > VDA
bit3 = 1
VDA = (3/4)*Vref, VS&H > VDA
bit2 = 1
1 1 1 0 VDA = (7/8)*Vref, VS&H < VDA
bit1 = 0
1 1 0 1 VDA = (13/16)*Vref, VS&H > VDA
bit0 = 1
![Page 15: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/15.jpg)
A/D Converter: PIC18F4620
• Output = 10-bit digital number = [0 .. 1023]
• 3 SFR are used to control the A/D converter:
• ADCON0: on/off, go/done, channel selection
• ADCON1: Vref, A/D Port configuration bit
• ADCON2: L/R justification, acquisition time & conversion clock
• The result is stored in two SFR: ADRESH (MSB) and ADRESL (LSB)
How to use it?
![Page 16: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/16.jpg)
A/D Converter: PIC18F4620
![Page 17: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/17.jpg)
A/D Converter: PIC18F4620
movlw b'00001110'
movwf ADCON1 ; configure ADCON1
movlw b'00000000'
movwf ADCON0 ; configure ADCON0
movlw b'00000001'
movwf ADCON2 ; configure ADCON2
movlw b'00000001'
movwf ADCON0 ; A/D converter on
; clear interrupt flag for ADC
bcf PIR1 , ADIF
; enable interrupt for ADC
bsf PIE1 , ADIE
; start conversion
bsf ADCON0 , GO
;clear the interrupt flag
bcf PIR1 , ADIF
(use ADRESH and ADRESL)
return
![Page 18: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/18.jpg)
A/D Converter: application exemples
Temperature sensor
Exemple: TMP35
![Page 19: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/19.jpg)
A/D Converter: application exemples
Proximity sensor
Exemple: Sharp GP2Y0A21YK
![Page 20: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/20.jpg)
Application exemple: Dimmer
Goal: control the luminosity of a led with a potentiometer + blinky
How can we implement that?
LED powered by a PWM signal with a varying duty cycle
Voltage of the potentiometer ADC
Acquired voltage becomes the new duty cycle
![Page 21: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/21.jpg)
Application exemple: Dimmer
10k
![Page 22: INFO-0064 Embedded systems · A/D Converter How does it work? Successive approximation concept V S&H Comparator D/A V ref [V] Control logic bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7](https://reader034.vdocuments.site/reader034/viewer/2022050217/5f63644cf82c35195d6ada9d/html5/thumbnails/22.jpg)
Ideas for your project
• Wii Nunchuck
• Line tracking robot
• Spirograph
• Inverted pendulum
• Propeller clock