SlideShare a Scribd company logo
Embedded System
ENG.KEROLES SHENOUDA
1
Index (1/4)
 PWM (pulse width Modulation)
 What is PWM
 How Does A Servo Motor Work?
 Lab1/Test Servo Motor By Atmega 32
 DC Motor
 L293D
 Atmega 32 Timer 0 Modes
 Request time equation
 Fast PWM Mode
 Phase Correct PWM Mode
2
Index (2/4) 3
 Timer0_Register Description
 Assignments
Repeat Lab1/2 by using Timer0
 ADC “Analog Digital Converter”.
 ADC introduction
 ADC Application: Embedded
systems receive
 Concepts: Embedded
Communication “PCM”ss
 Sampling (Hand writing)
time domain
Index (3/4) 4
 Sampling (Hand writing)
Frequency Domain
 Quantizer
 Quantizer Types
 Simply we can consider ADC as
 Resolution
 ADC Types
Index (4/4) 5
 ADC Parallel Design
 DAC-Based Designs
 Ramp counter ADC
 Successive Approximation ADC
 Sigma-delta design
 ADC on ATMEGA32
 ADC Features in Atmega32
 Interfacing Sensors
 ADC Registers
 Project: GATEWAY CAR Parking
PWM (pulse width
Modulation)
6
What is PWM ?
 A PWM Signal is a periodic rectangular pulse.
Frequency = 1/T
Duty Cycle = (T_ON/T)
 Pulse width modulation (PWM) is a powerful technique for controlling analog
circuits with a microprocessor's digital outputs. PWM is employed in a wide variety
of applications, ranging from measurement and communications to power control
and conversion.
7
What is need of PWM?
 PWM is mainly used for controlling the speed of DC motors . By pulse width
modulation we can get a variable voltage digitally, that is we get voltages
between 0 and VCC by switching the VCC on and off periodically . Other
applications are fading Led , getting different tones in Buzzer,Contolling the
degree of rotation of Servo motor .
8
How Does A Servo Motor Work?
 Usually a servomotor turns 90° in either direction, i.e. maximum movement can be
180°
 Three wires are taken out of a servo: positive, ground and control wire.
 A servo motor is controlled by sending a Pulse Width Modulated (PWM) signal
through the control wire. A pulse is sent every 20 milliseconds.
 Width of the pulses determine the position of the shaft. For example, a pulse of
1ms will move the shaft anticlockwise at -90°, a pulse of 1.5ms will move the shaft
at the neutral position that 0° and a pulse of 2ms will move the shaft clockwise
at +90
9
How Does A Servo Motor Work?
 Width of the pulses determine the position of the shaft. For example, a pulse of
1ms will move the shaft anticlockwise at -90°, a pulse of 1.5ms will move the shaft at the neutral position that 0°
and a pulse of 2ms will move the shaft clockwise at +90
10
Servo motor
 Servo motor works on PWM (Pulse width
modulation) principle, means its angle of rotation is
controlled by the duration of applied pulse to its
Control PIN. Basically servo motor is made up of DC
motor which is controlled by a variable resistor
(potentiometer) and some gears
11
Servo motor (another degree
range)(Motor-PWMSERVO in ISIS)
 Servo motor can be rotated from 0 to
180 degree, but it can go up to 210
degree, depending on the
manufacturing. This degree of rotation
can be controlled by applying
the Electrical Pulse of proper width,
to its Control pin. Servo checks the
pulse in every 20 milliseconds. Pulse
of 1 ms (1 millisecond) width can
rotate servo to 0 degree, 1.5ms can
rotate to 90 degree (neutral position)
and 2 ms pulse can rotate it to 180
degree.
12
Lab1/Test Servo Motor By Atmega 32
 With out any timer, run a servo Motor (Motor-PWMSERVO ) in ISIS
 Angle 0,90 and 180 as shown below
13
Lab1/Test Servo Motor By Atmega 32
 With out any timer, run a servo Motor (Motor-PWMSERVO ) in ISIS
 Angle 0,90 and 180 as shown below
14
Lab1/Test Servo Motor By Atmega 32
 With out any timer, run a servo Motor (Motor-PWMSERVO ) in ISIS
 Angle 0,90 and 180 as shown below
15
Lab1/Test Servo
Motor By
Atmega 32
Solution
16
DC Motor
 This DC or direct current motor works on the principal, when a current carrying
conductor is placed in a magnetic field, it experiences a torque and has a tendency
to move.
17
Lab2/ write embedded C Code without
timer to run two DC Motors
 First DC Motor Connect to PD0 (run Clockwise)
 Second DC Motor Connect to PD1 (run Anticlockwise)
 Sequence (Motor 1 run) > Motor1 stop & Motor 2 run
And so on
 Choose the time you prefer
18
Lab2/ sequence 19
LAB2/Solution 20
We can’t connect a DC Motor directly to a
microcontroller ?
 A microcontroller can’t supply the current required for the working of DC
Motor. ATmega32 Microcontroller can source or sink currents up to 40mA but a DC
Motor needs current very much more than that.
 The negative voltages created due to the back emf of the motor may affect the
proper functioning of the microcontroller.
 You may need to control the direction of rotation of the motor by changing the
polarity of the motor supply.
 The operating voltage of the DC Motor may be much higher than the operating
voltage of the microcontroller.
21
L293D
 To solve these problems you may use transistorized H Bridge in which freewheeling
diodes are used to avoid problems due to back emf. Thus it requires minimum four
transistors, diodes and resistors for each motor. It is better to use readymade ICs such
as L293D or L293instead of making your own H Bridge, which simplifies your project.
 L293D is a Quadruple Half H-Bridge driver commonly used for motor driving. We
needn’t connect any transistors, resistors or freewheeling diodes. All the four outputs of
this IC are TTL compatible and output clamp diodes are provided to drive inductive
loads. L293D can provide up to 600mA current, in the voltage raging from 4.5 to 36v.
L293 is a similar IC which can provide up to 1A in the same voltage range.
 L293 or L293D contains four Half H Bridge drivers and are enabled in pairs. Input
EN1 is used to enable pair 1 (IN1-OUT1, IN2-OUT2) and input EN2 is used to enable
pair 2 (IN3-OUT3, IN4-OUT4). We can drive two DC Motors with one L293D, but here
for demonstration we are using only one. You can connect second DC Motor to driver
pair 2 according to your needs.
22
Control Signals and Motor Status
PC0/IN1 PC1/IN2 Motor Status
LOW LOW Stops
LOW HIGH Clockwise
HIGH LOW Anti-Clockwise
HIGH HIGH Stops
23
If we can generate PWM by GPIO and Delay,
Why we need to use TIMER Module to generate PWM ?
24
Atmega 32 Timer 0 Modes
Normal Mode
Clear Timer on Compare Match (CTC) Mode
Fast PWM Mode Phase Correct PWM Mode
25
Hand Writing Notes: we took it on the previous Lecture
26
Request time equation 27
Normal Mode
 The simplest mode of operation is the Normal mode (WGM01:0 = 0). In this mode the counting
direction
is always up (incrementing), and no counter clear is performed. The counter simply overruns when
it
passes its maximum 8-bit value (TOP = 0xFF) and then restarts from the bottom (0x00). In normal
operation the Timer/Counter Overflow Flag (TOV0) will be set in the same timer clock cycle as
the TCNT0
becomes zero. The TOV0 Flag in this case behaves like a ninth bit, except that it is only set, not
cleared.
However, combined with the timer overflow interrupt that automatically clears the TOV0 Flag, the
timer
resolution can be increased by software. There are no special cases to consider in the Normal
mode, a
new counter value can be written anytime.
The Output Compare unit can be used to generate interrupts at some given time. Using the Output
Compare to generate waveforms in Normal mode is not recommended, since this will occupy too
much of
the CPU time.
28
Clear Timer on Compare Match (CTC)
Mode
 In Clear Timer on Compare or CTC mode (WGM01:0 = 2), the OCR0 Register is used to manipulate the
counter resolution. In CTC mode the counter is cleared to zero when the counter value (TCNT0) matches
the OCR0. The OCR0 defines the top value for the counter, hence also its resolution. This mode allows
greater control of the Compare Match output frequency. It also simplifies the operation of counting
external events.
The timing diagram for the CTC mode is shown in the figure below. The counter value (TCNT0) increases
until a Compare Match occurs between TCNT0 and OCR0, and then counter (TCNT0) is cleared.
29
Fast PWM Mode 30
Phase Correct PWM Mode, Timing
Diagram
31
Timer/Counter Timing Diagrams
No prescaling
With prescaling
32
Timer0_Register Description 33
34
35
36
37
38
39
40
41
Assignments
Repeat Lab1/2 by using Timer0
42
ADC “Analog Digital
Converter”
43
ADC introduction
 Signals in the real world are analog: light, sound, you name it.
So, real-world signals must be converted into digital, using a circuit called ADC
(Analog-to-Digital Converter)
44
ADC Application: Embedded systems receive
 Embedded systems receive their inputs from the
external world in the form of analog signals.
 An analog signal (amplitude varies continuously)
needs to be converted into a digital signal as
processor only takes digital signals ( a series of
ones and zeros represented by voltages).
 Thus conversions are performed by Analog-to-
Digital(ADC) and the reverse conversion of digital
to analog by Digital-to-Analog(DAC).
45
Concepts: Embedded Communication
“PCM”ss Modulation
Analog Modulation Digital Modulation
Continues Wave
Pulse Modulation
AM
FM
PM
PAM
PWM PPM
PCM
46
Sampling (Hand writing)
time domain
 Theoretical Sampling: x(t). ð(t-t.)
x(t) Ks(t)
P(t) periodic impulse train
47
Sampling (Hand writing) 48
Sampling (Hand writing)
Frequency Domain
49
quantizer
Vmax
Vmix
50
quantizer
Quantizer_max_error =
2
51
Quantizer Types
Quantizer
Uniform Quantizer
midrise quantizer midtead quantizer
Non-uniform quantizer
52
Simply we can consider ADC as
ADC major characteristics
Conversion Time
Resolution
Vref
Parallel vs. serial
Input channels
Sampler Quantizer Encoder
Analog
Signal
53
Resolution
 Resolution is The value of each sampled point will be stored
on a fixed-length variable. If this variable uses eight bits,
this means it can hold values from 0 to 255 (2^8 = 256). If
this variable uses 16 bits, this means it can hold values from
0 to 65,535 (2^16 = 65,536). And so on.
 The signal-to-noise ratio (SNR), which measures the noise
level, can be easily calculated through this formula, where n
is the number of bits used on the ADC:
SNR = 6.02 x n + 1.76 dB
 The higher the SNR, the better. An 8-bit ADC provides a
SNR of 49.9 dB, while a 16-bit SNR provides a SNR of 98
dB (which is, by the way, a virtually no-noise value).
54
ADC Types
 Parallel design (also known as Flash ADC);
 Digital-to-Analog Converter-based design
(e.g., ramp counter, successive approximation, tracking);
 Integrator-based design
(e.g., single-slope, dual-slope);
 Sigma-delta design
(also known as delta-sigma, 1-bit ADC or oversampling ADC).
55
Parallel Design
The Flash ADC, also called parallel ADC,
It works by comparing the input voltage – i.e., the analog signal – to a
reference voltage,
which would be the maximum value achieved by the analog signal.
For example, if the reference voltage is of 5 volts, this means that the
peak of the analog signal would be 5 volts.
On an 8-bit ADC when the input signal reached 5 volts we would find a
255 (11111111) value on the ADC output, i.e., the maximum value
possible.
Then the voltage reference is lowered through a resistor network and
other comparators added, so the input voltage (analog signal) can be
compared to other values.
56
Parallel Design Advantages/disadvantages
 Although Flash ADC uses a very simple design, it requires a lot of components. The
number of required comparers is 2^n-1, where n is the number of output bits. Thus for an eight-
bit Flash ADC 255 comparers would be necessary, and for a 16-bit Flash ADC, 65,535!
 On the other hand, Flash ADC is the fastest ADC type available. The digital equivalent of the
analog signal will be available right away at it output (it will only have the propagation delay
inserted by the logic gates) – hence the name “flash”.
 Another advantage of Flash ADC is that you can create an ADC with non-linear output.
Usually ADCs have a linear output, i.e., each digital number corresponds to a fixed voltage
increase on the analog input. For example, on the 3-bit ADC shown above with a Vref of 5 V,
each digital number would represent 625 mV (5 V / 2^3). So 0 V = 000, 0.625 V = 001,
1.250 V = 010 and so on up to 5 V = 111.
Since Flash ADC comparisons are set by a set of resistors, one could set different values for the
resistors in order to obtain a non-linear output, i.e., one value would represent a different
voltage step from the other values.
57
DAC-Based Designs
 There are a few ways to design an ADC using a DAC as part of its comparison
circuit
 Ramp Counter ADC
 Successive Approximation ADC
58
Ramp counter ADC
 Ramp counter ADC, also called digital ramp ADC.
Vin is the analog input and Dn through D0 are the digital outputs.
The control line found on the counter turns on the counter when it is
low and stops the counter when it is high.
 The basic idea is to increase the counter until the value found
on the counter matches the value of the analog signal. When
this condition is met, the value on the counter is the digital
equivalent of the analog signal.
 It requires a START pulse for each analog voltage you want to
convert into digital
 So the main problem with this circuit is that it is very slow, as it
would require up to 2^n-1 clock cycles to convert each sample.
For an eight-bit ADC, it would take up to 255 clock cycles to
convert a single sample. For a 16-bit ADC it would take up to
65,535 clock cycles to convert one sample.
59
Successive Approximation ADC
 the successive approximation ADC starts first setting the MSB
(most significant bit, on an eight-bit ADC it would be D7). In
order to facilitate the explanations below, consider an eight-
bit ADC.
 The comparison between Vin and the DAC output will tell the
control unit if this bit should remain set at 1 or should be set at
0, as the op amp will tell right away the control unit if the
sample value is greater or lower than 128 (2^7). Then D6 is
set to one, and from the comparison done by the op amp, the
control unit will know if this bit should remain set or not. And so
on.
 The good thing about the successive approximation ADC is its
speed. At the worst case it will find the correct digital value
for the sample at n clock cycles
60
Successive Approximation ADC 61
Sigma-delta design
 A delta sigma ADC or DAC always consists of a delta sigma modulator which
produces the bitstream and a low pass filter.
Block Diagram of a First Order Digital Delta Sigma
Modulator
62
Sigma-delta design
Signals within a First Order
Analog Modulator
63
ADC on ATMEGA32
64
Major Characteristic of ADC 65
ADC Features in Atmega32
 Atmega 16/32 have internal ADC
 8 analogue input channel
 7 differential input channel
 2 differential input channel with 10x or 200x gain
 3 source of Vref
 Internal 2.56V Vref generator
66
Interfacing Sensors
•8 channel implies that there are 8 ADC pins are
multiplexed together. You can easily see that these pins
are located across PORTA (PA0…PA7).
•10 bit resolution implies that there are 2^10 = 1024
•the type of ADC implemented inside the AVR MCU is of
Successive Approximation type.
67
ADC Prescaler
 There are some predefined division factors – 2, 4, 8, 16, 32, 64, and 128. For
example, a prescaler of 64 implies F_ADC = F_CPU/64. For F_CPU = 16MHz,
F_ADC = 16M/64 = 250kHz.
68
Analog to
Digital
Converter
Block
Schematic
Operation
69
ADC Registers
70
ADMUX – ADC Multiplexer Selection
Register
71
ADMUX – ADC Multiplexer Selection
Register
72
ADCH and ADCL Data registers
 ADCH:ADCL store the results
of conversion.
 The 10 bit result can be right
or left justified:
ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADC1 ADC0 - - - - - -ADC9 ADC8
ADCH ADCL
ADLAR = 0
ADLAR =1
ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADC1 ADC0- - - - - - ADC9 ADC8
ADCH ADCL
ADCSRA – ADC Control and Status
Register A
ADEN – ADC Enable – As the
name says, it enables the ADC
feature. Unless this is enabled,
ADC operations cannot take
place across PORTA i.e. PORTA
will behave as GPIO pins.
ADSC – ADC Start Conversion –
Write this to ‘1’ before starting any
conversion. This 1 is written as long
as the conversion is in progress,
after which it returns to zero.
Normally it takes 13 ADC clock
pulses for this operation. But when
you call it for the first time, it takes
25 as it performs the initialization
together with it.
ADATE – ADC Auto Trigger
Enable – Setting it to ‘1’ enables
auto-triggering of ADC. ADC is
triggered automatically at every
rising edge of clock pulse
ADIF – ADC Interrupt Flag –
Whenever a conversion is
finished and the registers are
updated, this bit is set to ‘1’
automatically
74
ADCSRA – ADC Control and Status
Register A
ADIE – ADC Interrupt Enable –
When this bit is set to ‘1’, the
ADC interrupt is enabled. This is
used in the case of interrupt-
driven ADC.
ADPS2:0 – ADC Prescaler
Select Bits – The prescaler
(division factor between XTAL
frequency and the ADC clock
frequency)
75
SFIOR – Special Function I/O Register
76
Programming ADC 77
Why 13 cycles max used for ADC
Conversion time ?
THINK IN-DEPTH 
78
Thermistor dependent resistor (DR)
 For example, the following thermistor circuit has a
resistance of 10KΩ at 25°C and a resistance
of 100Ω at 100°C. Calculate the output voltage
(Vout) for both temperatures
79
PIR SENSOR:
 The PIR sensor detect only bodies (hot materials and living
objects) in motions not the static ones. This sensor uses Infra red
beam to detect the motion and only covers a certain space
based on the sensor model, you should to go through the
manufacturer datasheet to know about the range. This sensor
module gives only two output states that is logic High 1 which
is equivalent to 3.3 V and logic low 0 equivalent to 0 V.
80
GATEWAY CAR Parking
81
GATEWAY CAR Parking
 WORKING:
 The PIR sensor is interfaced with Atmega32 AVR
microcontroller to detect the motion around the
environment. Atmega32 considers any voltage
between 2V to 5V as logic high. Hence PIR
sensor is directly interfaced to the input pin of
the controller.
 The circuit shown above will read the status of
the output of the PIR sensor and the ADC will
read the Value if the Value is less than 3 Volt
that mean that the PIR detected the CAR so the
gateway will opened and the 7-segement will
count each car entered on the PARKING and the
Buzzer will run, then the Gateway will closed
after the car moved a way from GATEWAY and
the Buzzer will be OFF.
82
References
 http://www.hardwaresecrets.com/how-analog-to-digital-converter-adc-works/3/
 http://www.beis.de/Elektronik/DeltaSigma/DeltaSigma.html
 AVR Microcontroller and Embedded Systems: Using Assembly and C (Pearson
Custom Electronics Technology) 1st Edition
https://www.amazon.com/AVR-Microcontroller-Embedded-Systems-
Electronics/dp/0138003319
83
84

More Related Content

What's hot

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
 
Uart VHDL RTL design tutorial
Uart VHDL RTL design tutorialUart VHDL RTL design tutorial
Uart VHDL RTL design tutorialNabil Chouba
 
Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsCorrado Santoro
 
伺服馬達控制
伺服馬達控制伺服馬達控制
伺服馬達控制艾鍗科技
 
Exercises with timers and UART
Exercises with timers and UARTExercises with timers and UART
Exercises with timers and UARTCorrado Santoro
 
Analog to Digital converter in ARM
Analog to Digital converter in ARMAnalog to Digital converter in ARM
Analog to Digital converter in ARMAarav Soni
 
Microcontroller Instruction Set atmel
Microcontroller Instruction Set atmelMicrocontroller Instruction Set atmel
Microcontroller Instruction Set atmelRuderocker Billy
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
Introduction to Vortex86EX Motion Control Modules
Introduction to Vortex86EX Motion Control ModulesIntroduction to Vortex86EX Motion Control Modules
Introduction to Vortex86EX Motion Control Modulesroboard
 
Interrupts at AVR
Interrupts at AVRInterrupts at AVR
Interrupts at AVRHamdy Fouad
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerCorrado Santoro
 
Atmel microcontrollers-a tmega328-p_datasheet
Atmel microcontrollers-a tmega328-p_datasheetAtmel microcontrollers-a tmega328-p_datasheet
Atmel microcontrollers-a tmega328-p_datasheetAlexTronciu
 
arm complete detail part 2
arm complete detail part 2arm complete detail part 2
arm complete detail part 2NOWAY
 
Overview of LPC214x MCUs
Overview of LPC214x MCUsOverview of LPC214x MCUs
Overview of LPC214x MCUsPremier Farnell
 

What's hot (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
 
Uart VHDL RTL design tutorial
Uart VHDL RTL design tutorialUart VHDL RTL design tutorial
Uart VHDL RTL design tutorial
 
Pt650 d英文说明书 (1)
Pt650 d英文说明书 (1)Pt650 d英文说明书 (1)
Pt650 d英文说明书 (1)
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
Using Timer1 and CCP
Using Timer1 and CCPUsing Timer1 and CCP
Using Timer1 and CCP
 
Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUs
 
伺服馬達控制
伺服馬達控制伺服馬達控制
伺服馬達控制
 
Exercises with timers and UART
Exercises with timers and UARTExercises with timers and UART
Exercises with timers and UART
 
Analog to Digital converter in ARM
Analog to Digital converter in ARMAnalog to Digital converter in ARM
Analog to Digital converter in ARM
 
Microcontroller Instruction Set atmel
Microcontroller Instruction Set atmelMicrocontroller Instruction Set atmel
Microcontroller Instruction Set atmel
 
STM32 Microcontroller Clocks and RCC block
STM32 Microcontroller Clocks and RCC blockSTM32 Microcontroller Clocks and RCC block
STM32 Microcontroller Clocks and RCC block
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Introduction to Vortex86EX Motion Control Modules
Introduction to Vortex86EX Motion Control ModulesIntroduction to Vortex86EX Motion Control Modules
Introduction to Vortex86EX Motion Control Modules
 
Interrupts at AVR
Interrupts at AVRInterrupts at AVR
Interrupts at AVR
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontroller
 
131080111003 mci
131080111003 mci131080111003 mci
131080111003 mci
 
Atmel microcontrollers-a tmega328-p_datasheet
Atmel microcontrollers-a tmega328-p_datasheetAtmel microcontrollers-a tmega328-p_datasheet
Atmel microcontrollers-a tmega328-p_datasheet
 
arm complete detail part 2
arm complete detail part 2arm complete detail part 2
arm complete detail part 2
 
Uart 16550
Uart 16550Uart 16550
Uart 16550
 
Overview of LPC214x MCUs
Overview of LPC214x MCUsOverview of LPC214x MCUs
Overview of LPC214x MCUs
 

Viewers also liked (20)

K vector embedded_linux_workshop
K vector embedded_linux_workshopK vector embedded_linux_workshop
K vector embedded_linux_workshop
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
C programming session3
C programming  session3C programming  session3
C programming session3
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
C programming part2
C programming part2C programming part2
C programming part2
 
Automative basics v3
Automative basics v3Automative basics v3
Automative basics v3
 
C programming part4
C programming part4C programming part4
C programming part4
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part4
C programming part4C programming part4
C programming part4
 
C programming session5
C programming  session5C programming  session5
C programming session5
 
Microcontroller part 7_v1
Microcontroller part 7_v1Microcontroller part 7_v1
Microcontroller part 7_v1
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
Microcontroller part 9_v1
Microcontroller part 9_v1Microcontroller part 9_v1
Microcontroller part 9_v1
 
Microcontroller part 6_v1
Microcontroller part 6_v1Microcontroller part 6_v1
Microcontroller part 6_v1
 

Similar to Microcontroller part 3

UNIT 4 & 5 - I nterfacing_Lecture7.pptx
UNIT 4 & 5 - I         nterfacing_Lecture7.pptxUNIT 4 & 5 - I         nterfacing_Lecture7.pptx
UNIT 4 & 5 - I nterfacing_Lecture7.pptxnaveen088888
 
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
 
Speed Control Of DC motor By Using PWM Technique
Speed Control Of DC motor By Using PWM TechniqueSpeed Control Of DC motor By Using PWM Technique
Speed Control Of DC motor By Using PWM TechniqueRITESH D. PATIL
 
What isn’t told about timers in stm32 application
What isn’t told about timers in stm32 applicationWhat isn’t told about timers in stm32 application
What isn’t told about timers in stm32 applicationOmar BOUZOURRAA
 
Gulotta_Wright_Parisi_FinalProjectOverview1
Gulotta_Wright_Parisi_FinalProjectOverview1Gulotta_Wright_Parisi_FinalProjectOverview1
Gulotta_Wright_Parisi_FinalProjectOverview1Nicholas Parisi
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
Pic ppt 13104022(4th_year)
Pic ppt 13104022(4th_year)Pic ppt 13104022(4th_year)
Pic ppt 13104022(4th_year)Daman Singh
 
Temperature Controller with Atmega16
Temperature Controller with Atmega16Temperature Controller with Atmega16
Temperature Controller with Atmega16Siddhant Jaiswal
 
ANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORAnil Yadav
 
EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfSPonmalar1
 
Black Box for a Car
Black Box for a CarBlack Box for a Car
Black Box for a Carsubrat manna
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programmingMohamed Ali
 
Microstepping of stepper Motor
Microstepping of stepper MotorMicrostepping of stepper Motor
Microstepping of stepper MotorANUP PALARAPWAR
 

Similar to Microcontroller part 3 (20)

Timers
TimersTimers
Timers
 
UNIT 4 & 5 - I nterfacing_Lecture7.pptx
UNIT 4 & 5 - I         nterfacing_Lecture7.pptxUNIT 4 & 5 - I         nterfacing_Lecture7.pptx
UNIT 4 & 5 - I nterfacing_Lecture7.pptx
 
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
 
Speed Control Of DC motor By Using PWM Technique
Speed Control Of DC motor By Using PWM TechniqueSpeed Control Of DC motor By Using PWM Technique
Speed Control Of DC motor By Using PWM Technique
 
What isn’t told about timers in stm32 application
What isn’t told about timers in stm32 applicationWhat isn’t told about timers in stm32 application
What isn’t told about timers in stm32 application
 
Timers in Arduino
Timers in ArduinoTimers in Arduino
Timers in Arduino
 
Gulotta_Wright_Parisi_FinalProjectOverview1
Gulotta_Wright_Parisi_FinalProjectOverview1Gulotta_Wright_Parisi_FinalProjectOverview1
Gulotta_Wright_Parisi_FinalProjectOverview1
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Pic ppt 13104022(4th_year)
Pic ppt 13104022(4th_year)Pic ppt 13104022(4th_year)
Pic ppt 13104022(4th_year)
 
Temperature Controller with Atmega16
Temperature Controller with Atmega16Temperature Controller with Atmega16
Temperature Controller with Atmega16
 
ANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTOR
 
Digital stop watch
Digital stop watchDigital stop watch
Digital stop watch
 
510 277-283
510 277-283510 277-283
510 277-283
 
Chapter5 dek3133
Chapter5 dek3133Chapter5 dek3133
Chapter5 dek3133
 
Ec8791 lpc2148 pwm
Ec8791 lpc2148 pwmEc8791 lpc2148 pwm
Ec8791 lpc2148 pwm
 
EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdf
 
Black Box for a Car
Black Box for a CarBlack Box for a Car
Black Box for a Car
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programming
 
Microstepping of stepper Motor
Microstepping of stepper MotorMicrostepping of stepper Motor
Microstepping of stepper Motor
 

More from Keroles karam khalil

Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Keroles karam khalil
 
Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Keroles karam khalil
 
Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Keroles karam khalil
 
Automotive embedded systems part6 v1
Automotive embedded systems part6 v1Automotive embedded systems part6 v1
Automotive embedded systems part6 v1Keroles karam khalil
 
Automotive embedded systems part5 v1
Automotive embedded systems part5 v1Automotive embedded systems part5 v1
Automotive embedded systems part5 v1Keroles karam khalil
 
Automotive embedded systems part4 v1
Automotive embedded systems part4 v1Automotive embedded systems part4 v1
Automotive embedded systems part4 v1Keroles karam khalil
 
Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Keroles karam khalil
 
Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Keroles karam khalil
 
Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Keroles karam khalil
 
Automotive embedded systems part8 v1
Automotive embedded systems part8 v1Automotive embedded systems part8 v1
Automotive embedded systems part8 v1Keroles karam khalil
 

More from Keroles karam khalil (20)

C basics quiz part 1_solution
C basics quiz part 1_solutionC basics quiz part 1_solution
C basics quiz part 1_solution
 
Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
 
Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Automotive embedded systems part6 v2
Automotive embedded systems part6 v2
 
Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2
 
EMBEDDED C
EMBEDDED CEMBEDDED C
EMBEDDED C
 
Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Automotive embedded systems part7 v1
Automotive embedded systems part7 v1
 
Automotive embedded systems part6 v1
Automotive embedded systems part6 v1Automotive embedded systems part6 v1
Automotive embedded systems part6 v1
 
Automotive embedded systems part5 v1
Automotive embedded systems part5 v1Automotive embedded systems part5 v1
Automotive embedded systems part5 v1
 
Automotive embedded systems part4 v1
Automotive embedded systems part4 v1Automotive embedded systems part4 v1
Automotive embedded systems part4 v1
 
Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Automotive embedded systems part3 v1
Automotive embedded systems part3 v1
 
Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Automotive embedded systems part2 v1
Automotive embedded systems part2 v1
 
Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Automotive embedded systems part1 v1
Automotive embedded systems part1 v1
 
Automotive embedded systems part8 v1
Automotive embedded systems part8 v1Automotive embedded systems part8 v1
Automotive embedded systems part8 v1
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
Quiz 10
Quiz 10Quiz 10
Quiz 10
 
Homework 6
Homework 6Homework 6
Homework 6
 
Homework 5 solution
Homework 5 solutionHomework 5 solution
Homework 5 solution
 
C programming session8
C programming  session8C programming  session8
C programming session8
 

Recently uploaded

Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdfKamal Acharya
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Krakówbim.edu.pl
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdfAhmedHussein950959
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdfKamal Acharya
 
Pharmacy management system project report..pdf
Pharmacy management system project report..pdfPharmacy management system project report..pdf
Pharmacy management system project report..pdfKamal Acharya
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfPipe Restoration Solutions
 
retail automation billing system ppt.pptx
retail automation billing system ppt.pptxretail automation billing system ppt.pptx
retail automation billing system ppt.pptxfaamieahmd
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfAbrahamGadissa
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...Amil baba
 
Scaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageScaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageRCC Institute of Information Technology
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopEmre Günaydın
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdfKamal Acharya
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxwendy cai
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturingssuser0811ec
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industriesMuhammadTufail242431
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationRobbie Edward Sayers
 
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringKIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringDr. Radhey Shyam
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-IVigneshvaranMech
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf884710SadaqatAli
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsAtif Razi
 

Recently uploaded (20)

Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
 
Pharmacy management system project report..pdf
Pharmacy management system project report..pdfPharmacy management system project report..pdf
Pharmacy management system project report..pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
retail automation billing system ppt.pptx
retail automation billing system ppt.pptxretail automation billing system ppt.pptx
retail automation billing system ppt.pptx
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
 
Scaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageScaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltage
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturing
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringKIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
 

Microcontroller part 3

  • 2. Index (1/4)  PWM (pulse width Modulation)  What is PWM  How Does A Servo Motor Work?  Lab1/Test Servo Motor By Atmega 32  DC Motor  L293D  Atmega 32 Timer 0 Modes  Request time equation  Fast PWM Mode  Phase Correct PWM Mode 2
  • 3. Index (2/4) 3  Timer0_Register Description  Assignments Repeat Lab1/2 by using Timer0  ADC “Analog Digital Converter”.  ADC introduction  ADC Application: Embedded systems receive  Concepts: Embedded Communication “PCM”ss  Sampling (Hand writing) time domain
  • 4. Index (3/4) 4  Sampling (Hand writing) Frequency Domain  Quantizer  Quantizer Types  Simply we can consider ADC as  Resolution  ADC Types
  • 5. Index (4/4) 5  ADC Parallel Design  DAC-Based Designs  Ramp counter ADC  Successive Approximation ADC  Sigma-delta design  ADC on ATMEGA32  ADC Features in Atmega32  Interfacing Sensors  ADC Registers  Project: GATEWAY CAR Parking
  • 7. What is PWM ?  A PWM Signal is a periodic rectangular pulse. Frequency = 1/T Duty Cycle = (T_ON/T)  Pulse width modulation (PWM) is a powerful technique for controlling analog circuits with a microprocessor's digital outputs. PWM is employed in a wide variety of applications, ranging from measurement and communications to power control and conversion. 7
  • 8. What is need of PWM?  PWM is mainly used for controlling the speed of DC motors . By pulse width modulation we can get a variable voltage digitally, that is we get voltages between 0 and VCC by switching the VCC on and off periodically . Other applications are fading Led , getting different tones in Buzzer,Contolling the degree of rotation of Servo motor . 8
  • 9. How Does A Servo Motor Work?  Usually a servomotor turns 90° in either direction, i.e. maximum movement can be 180°  Three wires are taken out of a servo: positive, ground and control wire.  A servo motor is controlled by sending a Pulse Width Modulated (PWM) signal through the control wire. A pulse is sent every 20 milliseconds.  Width of the pulses determine the position of the shaft. For example, a pulse of 1ms will move the shaft anticlockwise at -90°, a pulse of 1.5ms will move the shaft at the neutral position that 0° and a pulse of 2ms will move the shaft clockwise at +90 9
  • 10. How Does A Servo Motor Work?  Width of the pulses determine the position of the shaft. For example, a pulse of 1ms will move the shaft anticlockwise at -90°, a pulse of 1.5ms will move the shaft at the neutral position that 0° and a pulse of 2ms will move the shaft clockwise at +90 10
  • 11. Servo motor  Servo motor works on PWM (Pulse width modulation) principle, means its angle of rotation is controlled by the duration of applied pulse to its Control PIN. Basically servo motor is made up of DC motor which is controlled by a variable resistor (potentiometer) and some gears 11
  • 12. Servo motor (another degree range)(Motor-PWMSERVO in ISIS)  Servo motor can be rotated from 0 to 180 degree, but it can go up to 210 degree, depending on the manufacturing. This degree of rotation can be controlled by applying the Electrical Pulse of proper width, to its Control pin. Servo checks the pulse in every 20 milliseconds. Pulse of 1 ms (1 millisecond) width can rotate servo to 0 degree, 1.5ms can rotate to 90 degree (neutral position) and 2 ms pulse can rotate it to 180 degree. 12
  • 13. Lab1/Test Servo Motor By Atmega 32  With out any timer, run a servo Motor (Motor-PWMSERVO ) in ISIS  Angle 0,90 and 180 as shown below 13
  • 14. Lab1/Test Servo Motor By Atmega 32  With out any timer, run a servo Motor (Motor-PWMSERVO ) in ISIS  Angle 0,90 and 180 as shown below 14
  • 15. Lab1/Test Servo Motor By Atmega 32  With out any timer, run a servo Motor (Motor-PWMSERVO ) in ISIS  Angle 0,90 and 180 as shown below 15
  • 17. DC Motor  This DC or direct current motor works on the principal, when a current carrying conductor is placed in a magnetic field, it experiences a torque and has a tendency to move. 17
  • 18. Lab2/ write embedded C Code without timer to run two DC Motors  First DC Motor Connect to PD0 (run Clockwise)  Second DC Motor Connect to PD1 (run Anticlockwise)  Sequence (Motor 1 run) > Motor1 stop & Motor 2 run And so on  Choose the time you prefer 18
  • 21. We can’t connect a DC Motor directly to a microcontroller ?  A microcontroller can’t supply the current required for the working of DC Motor. ATmega32 Microcontroller can source or sink currents up to 40mA but a DC Motor needs current very much more than that.  The negative voltages created due to the back emf of the motor may affect the proper functioning of the microcontroller.  You may need to control the direction of rotation of the motor by changing the polarity of the motor supply.  The operating voltage of the DC Motor may be much higher than the operating voltage of the microcontroller. 21
  • 22. L293D  To solve these problems you may use transistorized H Bridge in which freewheeling diodes are used to avoid problems due to back emf. Thus it requires minimum four transistors, diodes and resistors for each motor. It is better to use readymade ICs such as L293D or L293instead of making your own H Bridge, which simplifies your project.  L293D is a Quadruple Half H-Bridge driver commonly used for motor driving. We needn’t connect any transistors, resistors or freewheeling diodes. All the four outputs of this IC are TTL compatible and output clamp diodes are provided to drive inductive loads. L293D can provide up to 600mA current, in the voltage raging from 4.5 to 36v. L293 is a similar IC which can provide up to 1A in the same voltage range.  L293 or L293D contains four Half H Bridge drivers and are enabled in pairs. Input EN1 is used to enable pair 1 (IN1-OUT1, IN2-OUT2) and input EN2 is used to enable pair 2 (IN3-OUT3, IN4-OUT4). We can drive two DC Motors with one L293D, but here for demonstration we are using only one. You can connect second DC Motor to driver pair 2 according to your needs. 22
  • 23. Control Signals and Motor Status PC0/IN1 PC1/IN2 Motor Status LOW LOW Stops LOW HIGH Clockwise HIGH LOW Anti-Clockwise HIGH HIGH Stops 23
  • 24. If we can generate PWM by GPIO and Delay, Why we need to use TIMER Module to generate PWM ? 24
  • 25. Atmega 32 Timer 0 Modes Normal Mode Clear Timer on Compare Match (CTC) Mode Fast PWM Mode Phase Correct PWM Mode 25
  • 26. Hand Writing Notes: we took it on the previous Lecture 26
  • 28. Normal Mode  The simplest mode of operation is the Normal mode (WGM01:0 = 0). In this mode the counting direction is always up (incrementing), and no counter clear is performed. The counter simply overruns when it passes its maximum 8-bit value (TOP = 0xFF) and then restarts from the bottom (0x00). In normal operation the Timer/Counter Overflow Flag (TOV0) will be set in the same timer clock cycle as the TCNT0 becomes zero. The TOV0 Flag in this case behaves like a ninth bit, except that it is only set, not cleared. However, combined with the timer overflow interrupt that automatically clears the TOV0 Flag, the timer resolution can be increased by software. There are no special cases to consider in the Normal mode, a new counter value can be written anytime. The Output Compare unit can be used to generate interrupts at some given time. Using the Output Compare to generate waveforms in Normal mode is not recommended, since this will occupy too much of the CPU time. 28
  • 29. Clear Timer on Compare Match (CTC) Mode  In Clear Timer on Compare or CTC mode (WGM01:0 = 2), the OCR0 Register is used to manipulate the counter resolution. In CTC mode the counter is cleared to zero when the counter value (TCNT0) matches the OCR0. The OCR0 defines the top value for the counter, hence also its resolution. This mode allows greater control of the Compare Match output frequency. It also simplifies the operation of counting external events. The timing diagram for the CTC mode is shown in the figure below. The counter value (TCNT0) increases until a Compare Match occurs between TCNT0 and OCR0, and then counter (TCNT0) is cleared. 29
  • 31. Phase Correct PWM Mode, Timing Diagram 31
  • 32. Timer/Counter Timing Diagrams No prescaling With prescaling 32
  • 34. 34
  • 35. 35
  • 36. 36
  • 37. 37
  • 38. 38
  • 39. 39
  • 40. 40
  • 41. 41
  • 42. Assignments Repeat Lab1/2 by using Timer0 42
  • 44. ADC introduction  Signals in the real world are analog: light, sound, you name it. So, real-world signals must be converted into digital, using a circuit called ADC (Analog-to-Digital Converter) 44
  • 45. ADC Application: Embedded systems receive  Embedded systems receive their inputs from the external world in the form of analog signals.  An analog signal (amplitude varies continuously) needs to be converted into a digital signal as processor only takes digital signals ( a series of ones and zeros represented by voltages).  Thus conversions are performed by Analog-to- Digital(ADC) and the reverse conversion of digital to analog by Digital-to-Analog(DAC). 45
  • 46. Concepts: Embedded Communication “PCM”ss Modulation Analog Modulation Digital Modulation Continues Wave Pulse Modulation AM FM PM PAM PWM PPM PCM 46
  • 47. Sampling (Hand writing) time domain  Theoretical Sampling: x(t). ð(t-t.) x(t) Ks(t) P(t) periodic impulse train 47
  • 52. Quantizer Types Quantizer Uniform Quantizer midrise quantizer midtead quantizer Non-uniform quantizer 52
  • 53. Simply we can consider ADC as ADC major characteristics Conversion Time Resolution Vref Parallel vs. serial Input channels Sampler Quantizer Encoder Analog Signal 53
  • 54. Resolution  Resolution is The value of each sampled point will be stored on a fixed-length variable. If this variable uses eight bits, this means it can hold values from 0 to 255 (2^8 = 256). If this variable uses 16 bits, this means it can hold values from 0 to 65,535 (2^16 = 65,536). And so on.  The signal-to-noise ratio (SNR), which measures the noise level, can be easily calculated through this formula, where n is the number of bits used on the ADC: SNR = 6.02 x n + 1.76 dB  The higher the SNR, the better. An 8-bit ADC provides a SNR of 49.9 dB, while a 16-bit SNR provides a SNR of 98 dB (which is, by the way, a virtually no-noise value). 54
  • 55. ADC Types  Parallel design (also known as Flash ADC);  Digital-to-Analog Converter-based design (e.g., ramp counter, successive approximation, tracking);  Integrator-based design (e.g., single-slope, dual-slope);  Sigma-delta design (also known as delta-sigma, 1-bit ADC or oversampling ADC). 55
  • 56. Parallel Design The Flash ADC, also called parallel ADC, It works by comparing the input voltage – i.e., the analog signal – to a reference voltage, which would be the maximum value achieved by the analog signal. For example, if the reference voltage is of 5 volts, this means that the peak of the analog signal would be 5 volts. On an 8-bit ADC when the input signal reached 5 volts we would find a 255 (11111111) value on the ADC output, i.e., the maximum value possible. Then the voltage reference is lowered through a resistor network and other comparators added, so the input voltage (analog signal) can be compared to other values. 56
  • 57. Parallel Design Advantages/disadvantages  Although Flash ADC uses a very simple design, it requires a lot of components. The number of required comparers is 2^n-1, where n is the number of output bits. Thus for an eight- bit Flash ADC 255 comparers would be necessary, and for a 16-bit Flash ADC, 65,535!  On the other hand, Flash ADC is the fastest ADC type available. The digital equivalent of the analog signal will be available right away at it output (it will only have the propagation delay inserted by the logic gates) – hence the name “flash”.  Another advantage of Flash ADC is that you can create an ADC with non-linear output. Usually ADCs have a linear output, i.e., each digital number corresponds to a fixed voltage increase on the analog input. For example, on the 3-bit ADC shown above with a Vref of 5 V, each digital number would represent 625 mV (5 V / 2^3). So 0 V = 000, 0.625 V = 001, 1.250 V = 010 and so on up to 5 V = 111. Since Flash ADC comparisons are set by a set of resistors, one could set different values for the resistors in order to obtain a non-linear output, i.e., one value would represent a different voltage step from the other values. 57
  • 58. DAC-Based Designs  There are a few ways to design an ADC using a DAC as part of its comparison circuit  Ramp Counter ADC  Successive Approximation ADC 58
  • 59. Ramp counter ADC  Ramp counter ADC, also called digital ramp ADC. Vin is the analog input and Dn through D0 are the digital outputs. The control line found on the counter turns on the counter when it is low and stops the counter when it is high.  The basic idea is to increase the counter until the value found on the counter matches the value of the analog signal. When this condition is met, the value on the counter is the digital equivalent of the analog signal.  It requires a START pulse for each analog voltage you want to convert into digital  So the main problem with this circuit is that it is very slow, as it would require up to 2^n-1 clock cycles to convert each sample. For an eight-bit ADC, it would take up to 255 clock cycles to convert a single sample. For a 16-bit ADC it would take up to 65,535 clock cycles to convert one sample. 59
  • 60. Successive Approximation ADC  the successive approximation ADC starts first setting the MSB (most significant bit, on an eight-bit ADC it would be D7). In order to facilitate the explanations below, consider an eight- bit ADC.  The comparison between Vin and the DAC output will tell the control unit if this bit should remain set at 1 or should be set at 0, as the op amp will tell right away the control unit if the sample value is greater or lower than 128 (2^7). Then D6 is set to one, and from the comparison done by the op amp, the control unit will know if this bit should remain set or not. And so on.  The good thing about the successive approximation ADC is its speed. At the worst case it will find the correct digital value for the sample at n clock cycles 60
  • 62. Sigma-delta design  A delta sigma ADC or DAC always consists of a delta sigma modulator which produces the bitstream and a low pass filter. Block Diagram of a First Order Digital Delta Sigma Modulator 62
  • 63. Sigma-delta design Signals within a First Order Analog Modulator 63
  • 66. ADC Features in Atmega32  Atmega 16/32 have internal ADC  8 analogue input channel  7 differential input channel  2 differential input channel with 10x or 200x gain  3 source of Vref  Internal 2.56V Vref generator 66
  • 67. Interfacing Sensors •8 channel implies that there are 8 ADC pins are multiplexed together. You can easily see that these pins are located across PORTA (PA0…PA7). •10 bit resolution implies that there are 2^10 = 1024 •the type of ADC implemented inside the AVR MCU is of Successive Approximation type. 67
  • 68. ADC Prescaler  There are some predefined division factors – 2, 4, 8, 16, 32, 64, and 128. For example, a prescaler of 64 implies F_ADC = F_CPU/64. For F_CPU = 16MHz, F_ADC = 16M/64 = 250kHz. 68
  • 71. ADMUX – ADC Multiplexer Selection Register 71
  • 72. ADMUX – ADC Multiplexer Selection Register 72
  • 73. ADCH and ADCL Data registers  ADCH:ADCL store the results of conversion.  The 10 bit result can be right or left justified: ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADC1 ADC0 - - - - - -ADC9 ADC8 ADCH ADCL ADLAR = 0 ADLAR =1 ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADC1 ADC0- - - - - - ADC9 ADC8 ADCH ADCL
  • 74. ADCSRA – ADC Control and Status Register A ADEN – ADC Enable – As the name says, it enables the ADC feature. Unless this is enabled, ADC operations cannot take place across PORTA i.e. PORTA will behave as GPIO pins. ADSC – ADC Start Conversion – Write this to ‘1’ before starting any conversion. This 1 is written as long as the conversion is in progress, after which it returns to zero. Normally it takes 13 ADC clock pulses for this operation. But when you call it for the first time, it takes 25 as it performs the initialization together with it. ADATE – ADC Auto Trigger Enable – Setting it to ‘1’ enables auto-triggering of ADC. ADC is triggered automatically at every rising edge of clock pulse ADIF – ADC Interrupt Flag – Whenever a conversion is finished and the registers are updated, this bit is set to ‘1’ automatically 74
  • 75. ADCSRA – ADC Control and Status Register A ADIE – ADC Interrupt Enable – When this bit is set to ‘1’, the ADC interrupt is enabled. This is used in the case of interrupt- driven ADC. ADPS2:0 – ADC Prescaler Select Bits – The prescaler (division factor between XTAL frequency and the ADC clock frequency) 75
  • 76. SFIOR – Special Function I/O Register 76
  • 78. Why 13 cycles max used for ADC Conversion time ? THINK IN-DEPTH  78
  • 79. Thermistor dependent resistor (DR)  For example, the following thermistor circuit has a resistance of 10KΩ at 25°C and a resistance of 100Ω at 100°C. Calculate the output voltage (Vout) for both temperatures 79
  • 80. PIR SENSOR:  The PIR sensor detect only bodies (hot materials and living objects) in motions not the static ones. This sensor uses Infra red beam to detect the motion and only covers a certain space based on the sensor model, you should to go through the manufacturer datasheet to know about the range. This sensor module gives only two output states that is logic High 1 which is equivalent to 3.3 V and logic low 0 equivalent to 0 V. 80
  • 82. GATEWAY CAR Parking  WORKING:  The PIR sensor is interfaced with Atmega32 AVR microcontroller to detect the motion around the environment. Atmega32 considers any voltage between 2V to 5V as logic high. Hence PIR sensor is directly interfaced to the input pin of the controller.  The circuit shown above will read the status of the output of the PIR sensor and the ADC will read the Value if the Value is less than 3 Volt that mean that the PIR detected the CAR so the gateway will opened and the 7-segement will count each car entered on the PARKING and the Buzzer will run, then the Gateway will closed after the car moved a way from GATEWAY and the Buzzer will be OFF. 82
  • 83. References  http://www.hardwaresecrets.com/how-analog-to-digital-converter-adc-works/3/  http://www.beis.de/Elektronik/DeltaSigma/DeltaSigma.html  AVR Microcontroller and Embedded Systems: Using Assembly and C (Pearson Custom Electronics Technology) 1st Edition https://www.amazon.com/AVR-Microcontroller-Embedded-Systems- Electronics/dp/0138003319 83
  • 84. 84