0% found this document useful (0 votes)
6 views70 pages

Day 3

The document provides an overview of ARM main peripherals, focusing on GPIO, ADC, and timers. It explains bit masking, logical operators, ADC digitalization processes, and various HAL functions for GPIO and ADC. Additionally, it covers timer functionality, including counting, prescaling, and PWM mode.

Uploaded by

mohamed.ismail05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views70 pages

Day 3

The document provides an overview of ARM main peripherals, focusing on GPIO, ADC, and timers. It explains bit masking, logical operators, ADC digitalization processes, and various HAL functions for GPIO and ADC. Additionally, it covers timer functionality, including counting, prescaling, and PWM mode.

Uploaded by

mohamed.ismail05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

ARM Main

Peripherals
GPIO, ADC and Timers
01
GPIO
3.3v

1
3.3v
0v

0
0v

0
PORT

0 0 0 0 0 0
Register
Bit Musking:
• Logical Operators:
01100
1. AND Operator
&
11001
Bit Musking:
• Logical Operators:
01100
1. AND Operator
&
11001
01000
01100
Bit Musking: &
• Logical Operators: 11001
1. AND Operator
01000
X X X
0
0 1 No
Change
Bit Musking:
• Logical Operators:
01100
2. OR Operator
|
11001
Bit Musking:
• Logical Operators:
01100
2. OR Operator
|
11001
11101
01100
Bit Musking: |
• Logical Operators: 11001
2. OR Operator
11101
X X X
1
1 0 No
Change
Bit Musking:
• Logical Operators:
01100
3. XOR Operator
^
11001
Bit Musking:
• Logical Operators:
01100
3. XOR Operator
^
11001
10101
01100
Bit Musking: ^
• Logical Operators: 11001
3. XOR Operator
10101
X X X

1 0 No
Change
Bit Musking:
• Logical Operators:
~01100
4. NOT Operator
Bit Musking:
• Logical Operators:
~01100
4. NOT Operator
10011
X X̄
Bit Musking:
• Logical Operators:
5. Shift Left and Right

0010 <<2
Bit Musking:
• Logical Operators:
5. Shift Left and Right

0010 <<2
Bit Musking:
• Logical Operators:
5. Shift Left and Right

10
Bit Musking:
• Logical Operators:
5. Shift Left and Right

1000 0100 >>2


Bit Musking:
• Logical Operators:
5. Shift Left and Right

1000 0100 >>2


Bit Musking:
• Logical Operators:
5. Shift Left and Right

1000 01
Bit Musking:
• Logical Operators:
5. Shift Left and Right

1000 0001
5 4 3 2 1 0
Bit Musking: RegX 0 1 0 1 1 0
• Clear Bit:
&
0 0 0 0 0 1<<4 1 0 1 11 1
010000~ 101111 5 4 3 2 1 0

RegX=RegX &(~(1<<n))
RegX 0 0 0 1 1 0
5 4 3 2 1 0
Bit Musking: RegX 0 0 0 1 1 0
• Set Bit:
|
0 0 0 0 0 1<<4 0 1 0 000
010000 5 4 3 2 1 0

RegX=RegX | (1<<n) RegX 0 1 0 1 1 0


5 4 3 2 1 0
Bit Musking: RegX 0 0 0 1 1 0
• Toggle Bit:
^
0 0 0 0 0 1<<4 0 1 0 000
010000 5 4 3 2 1 0

RegX=RegX ^ (1<<n) RegX 0 1 0 1 1 0


5 4 3 2 1 0

RegX 0 1 0 1 1 0
Bit Musking:
• Get Bit:
&
0 1 0 000
x=RegX & (1<<n) 0 1 0 0 0 0 >>4
0 0 0 001
GPIO HAL Functions:

1. Define Pin
MODE
GPIO HAL Functions:

2. Configure
GPIO PIN
GPIO HAL Functions:
HAL_GPIO_WritePin(GPIOx, GPIO_Pin, PinState);

GPIOA GPIO_PIN_1 GPIO_PIN_SET : 1


GPIOB GPIO_PIN_2 GPIO_PIN_RESET : 0
…… ……
GPIO HAL Functions:
HAL_GPIO_TogglePin(GPIOx, GPIO_Pin);

GPIOA GPIO_PIN_1
GPIOB GPIO_PIN_2
…… ……
GPIO HAL Functions:
HAL_GPIO_ReadPin(GPIOx, GPIO_Pin);

GPIOA GPIO_PIN_1
GPIOB GPIO_PIN_2
…… ……
LED Toggle Example:
LED Toggle Example:
02
ADC
Introduction

• The ADC does the counter operation that of a


DAC
Digitalization Process

1) Sampling
Convert continuous analog signal to a discrete digital
signal
3.1v
2v 1.6v
Digitalization Process
2) Quantization 5 4 3 2 1 0

• Resolution 0 0 0 1 1 0
6-bit resolution
3
• Maximum 5 4 2 1 0

(reference) 1 1 1 1 1 1
Voltage
?? v
Digitalization Process
2) Quantization
Assume: 2-bit resolution , 0 0 0 : 0v
Ref. volt. 4v

• Step Size
0 1
?? v
𝑹𝒆𝒇 𝑽𝒐𝒍𝒕
𝑺𝒕𝒆𝒑 = 1 0
𝟐𝒓𝒆𝒔
𝟒 4 : 4v
= 𝟐 = 𝟏𝑽 1 1
𝟐
Digitalization Process
2) Quantization
0v : 0.99v 0 0
1v : 1.99v 0 1
Input signal
2v : 2.99v 1 0
3v : 3.99v 1 1
Digitalization Process
2) Quantization
Analog Val =
2 2.8V Digital Val * Step

Max Analog Val =


𝟐𝒓𝒆𝒔 = 𝟒 2 * 1V = 2V
Volt
‫حس‬
?? 2 2.8V 2V
Quantization Error
Digitalization Process
2) Quantization

Quantization Error
Step Sensitivity Accuracy
Size
𝑹𝒆𝒇 𝑽𝒐𝒍𝒕
𝑺𝒕𝒆𝒑 =
𝟐𝒓𝒆𝒔
Digitalization Process
2) Quantization
Assume: 2-bit 0v : 0.499v 0 0
resolution ,
Ref. volt. 2v 0.5v :0.99v 0 1
𝟐
𝑺𝒕𝒆𝒑 = 𝟐 = 𝟎. 𝟓𝑽
𝟐 1v : 1.499v 1 0
Input signal 1.5v : 1.99v 1 1
Digitalization Process
2) Quantization

3 1.8V

Analog Val = 3 * 0.5V = 1.5V


‫حس‬
1.8V 1.5V
Quantization Error
Digitalization Process
2) Quantization
replaces each approximation real number from a finite set
of discrete values.
Types of ADC
Single Mode

• the ADC does one conversion.


• Once the conversion of the selected channel is
complete.
• The converted data is stored in the 16-bit
ADC_DR register.
Continuous Mode

• The conversions happen repeatedly and


automatically at some defined rate.

• Does not need to re-enable the ADC after each


conversion.
ADC HAL Functions:
1. Selecting Channel
ADC HAL Functions:

2. ADC
Configuration
ADC HAL Functions:
Steps to use ADC
//Start ADC &hadc1
HAL_ADC_Start(address_hadc);
//Check For Convergence complete
HAL_ADC_PollForCovers(address_hadc,Timout);
//Read Data
X = HAL_ADC_GetValue(address_hadc);
03
Timers
Introduction

• It is a digital logic circuit that


counts up every clock cycle.
• It can count up or down.
• It can also have circuitry for
input capture, PWM signal
generation.
• Every clock cycle, the value of
the timer is incremented by 1.
Counter
Register
0 0 0 0
TICK!
0 0 0 1
Counter
Register
0 0 0 0
TICK!
𝑨𝒇𝒕𝒆𝒓 𝟐 𝟒 0 0 0 1
TICK!
𝑻𝒊𝒄𝒌𝒔 0 0.1 0
.
Overflow
1 1 1 1 TICK!
0 0 0 0
Timer Calculation & Equation Formula
Prescaler value
How fast do timers run?
If we wish to measure longer events, we need to use a
prescaler, which is a piece of hardware that divides the
clock source.
Counter
Pre-scaler Register

16 MHz
÷
64 250 kHz
0 0 0 0 .
1. F_CPU = 16 MHz 2. Presc= 64
3. TMR_Freq= F_CPU/Presc = 16M/64 = 250kHz

4. Tick_Time= 1/ F_CPU = 1/250k = 4 Micro sec

5. #OVF_Ticks= 2^res = 2^8= 256 ticks

6. Ovf_Time= #OVF_Ticks * Tick_Time


= 2^res * Presc/ F_CPU = 1.024 msec
Timer Interrupts
• Timers can be used to trigger a variety of
interrupts.
we will use a very basic
MAX Value
interrupt: when the
timer reaches its
maximum value, it will
rollover back to 0 and
trigger an interrupt.
Counter
Register
0 0 0 0
Comparator

0 1 1 0
Output Compare
Register
Counter
Register
0 0 0 1
Comparator

0 1 1 0
Output Compare
Register
Counter
Register
0 0 1 0
. .
Comparator

0 1 1 0
Output Compare
Register
Counter
Register
. . . .
. .
Comparator

0 1 1 0
Output Compare
Register
Counter
Register
0 1 1 0
. . .
Comparator

Compare matched 0 1 1 0
Output Compare
Register
Timer Interrupts

OCR Value

Compare match time


#Ticks * Tick_Time = (OCR+1) * (Presc+1)/F_CPU
Timer Calculation & Equation Formula

The output time interval is determined by the


Prescaler value, the clock frequency, and the
timer auto-reload register’s value.
Timer Calculation & Equation Formula
Example:
we’ll set our desired output time interval to be 100ms. we
can set the FCLK to be 72MHz. And let the Prescaler be 999.
the only unknown is the auto-reload (ARR) value. By
solving for it, we’ll get 7199.
PWM Mode
• The timer module is clocked from an internal
clock source and produces a digital waveform
on the output channel pin called the PWM
signal.

𝑽𝒆𝒇𝒇 = 𝑨𝑴𝑷 ∗ 𝑫𝒖𝒕𝒚


Input Capture Unit(ICU)
• Input capture is a method to measure the most
important main parameters of any Pulse-Width
Modulation that are:
1) Duty Cycle.
2) Frequency.
• Those parameters directly depend on the time
when pulse was being high, and the full time of
period or cycle.
THANK YOU !!

You might also like