SlideShare a Scribd company logo
1 of 16
What isn’t told about Timers in
STM32 application notes!
« Signal Processing as an example »
By Omar Bouzourraa
August 2017
The main goal ??
In this brief presentation, I’m going to show you something
amazing about STM32 microcontrollers!
My objective is implementing an ideal filter using only stm32
microcontroller and with a full hardware solution. In other
words, my goal is :
- Not to use external hardware components
- not to use STM32 Microcontroller CPU
- obtain an ideal output from the filter
What’s amazing in all of that?
STM32 Timers are always used for timing puposes, which include signal
measurement and generation.
In this presentation, you will discover that STM32 Timers can be used as
blocs of digital comparators.
 Timers with 4 channels can be used as 4 digital comparators. Signals
that describe comparaison result, are obtained on Timer output
channels.
 The capture compare registers are used to preload constant reference
datas which are useful for comparaison.
 The data to be compared with the capture compare registers, is
stocked in the Counter Register and can change (without CPU
intervention) while program is running.
The hardware architecture equivalence between
STM32 Timer and the classic digital comparator
Let’s explain it more!
• CCR or capture compare register, is a timer related register. It’s used for
stocking data useful for setting the pwm duty-cycle when timer mode is
PWM Output. For further information about this mode and other modes,
please check STM32 reference manual.
• CNT or Counter is also a timer related register. It usually contains the
digital counter value. Please don’t confuse between the counter and the
register that contains the counter value. In our case, counter should be
disabled and CNT is referred to as the register and not the counter!
• ARR or Auto Reload Register, is a timer related register. It contains a
constant value which is known as the signal period (when typically
working in PWM output mode). When the counter value reaches the ARR
value, it is then reinitialized (the counter value CNT is reinitialized to zero
when up-counting mode is enabled). In this presentation, we will use the
up-counting mode. There is also down-counting and up-down counting
modes.
The PWM signal generation mechanism
Now, I will explain how typically a timer works when PWM output mode is
enabled. I suppose that we have enabled the up-counting mode and the PWM
output mode PWM Mode1 (please refer to the reference manual for further
information about PWM mode1 and PWM mode2) and the output polarity is
not inverted.
If the counter is enabled in the bit 0 of CR1 rgister :
 the Timer output is active high (at the beginning).
 the counter is incremented every sensitive edge detected on the timer
source clock.
 ARR and CCRx (x can be a value from 1 to 4) are constant while they are not
modified by the CPU.
 Always, CNT and CCRx are compared due to a digital comparator embedded
with each channel.
 When CNT > CCRx, an event is generated and the Timer output state is low.
 When CNT = ARR, a second event is generated and the counter value is
reinitialized to zero and so on …
The PWM signal generation mechanism
The STM32 Timer as a digital comparator
Now the process is very simple! Just we need to configure our
timer exactly the same way when we want to generate a
PWM signal. But we must enable output without enabling the
counter. The counter must be disabled in order to disable its
automatic evolution.
Let’s forget the counter and focus only on the CNT register. In
fact, we don’t really need the counter but we need its value!
Good news! The counter value is modifiable on the fy.Just
write a value in the CCRx register (it is the reference value for
comparaison).
How can you modify the CNT value
without using the CPU ?
Now, it’s the time to talk about the magic of the DMA controller!
DMAC : Direct Memory Access Controller. For more information, please
check the reference manual!
I will show you how you can measure a PWM signal frequency using a
classic configuration of an STM32 Timer in PWM Input mode. This
measure is transferred to the CNT of another Timer (in the same
microcontroller !) using the DMAC .Finally, data is transferred to the
CNT without a CPU intervetion.
As a conclusion: comparing the period of a signal with a reference
period value and generating the comparaison result without being
obliged to use the CPU has huge advantages : We can avoid software
latency and deal with signals with high frequencies , efficiently and use
CPU for further applications at the same time!
How can this be useful in signal
processing ?
As I said at the beginning of this presentation, my goal is to
build an ideal filter using only STM32 microcontroller.
Let’s talk a bit about low-pass filter!
Low-pass filter is typically used for elimination of frequencies
higher than a reference frequency which is known as cut-off
frequency. But the problem is that obtaining a precise
response demands a complex hardware architecture and
always, an ideal response is so far to get!
Low-pass filter is just an example! You can design all the other
filters you know, using the exact same logic.
Low-pass filter implementation with stm32
timers
I suppose we want to build a low-pass filter with a cut-off frequency
F0 = 20Khz. The Timer source clock for signal measurement is
F_Source = 168 MHz. For a measurement precision, the prescaler must be kept in at
zero value. The ARR must be initialized to its maximum value.
Using the famous formula given in the reference manual, we realize the value which be
latched on the CCR1 register of the timer used for measurement, is CCR1 = 8400 =
0x20D0.
As we are working on low-pass filter, the filter output must be zero as soon as the
measured frequency is higher than 20KHz else the output is an « identical » copy of the
measured signal.
Now, we choose a secod timer to work as a digital comparator. Using the DMAC, the
CCR1 register value of the measurement timer is copied in the second Timer CNT
register. In CCR1 register of the secod timer, you preload the value « 0x20D0 ».
Let’s look at the schematic of the method
Further Applications
• You can do the same thing as decribed in the low-pass filter, in order to design your
high-pass filter.
• For band-pass filter, there is something new, to highlight. The question in this case
is: How should we do, to combine 2 comparaisons (the measured frequency is
compared with two reference frequencies defined in CCR1 and CCR2 registers of
the timer configured as digital comparator (TIM3)) and generate only one signal to
control the transistor of the GPIO port ?
• We can simply use a logic AND between the two comparaisons to obtain the
desired control signal.
• And if we don’t want to add an external logic gate, we have a solution offered by
STM32 timers. We can use the Combined Mode.
• The combined mode is a specific feature (not available in all STM32 products)
available on STM32 Timers. It makes it possible to generate two PWM signals on
TIM_CHn and TIM_CHn+1 and make the logic « AND » or « OR » with the two
signals. Combined signal is then obtained on TIM_CHn. Please check the reference
manual to get more informations!
And What should I do if the signal is analog ?
• When we are dealing with analog signals, we can simply use
comparators and DACs available in STM32 products.
• Comparator is used to compare the analog signal with a
reference voltage, in order to generate internally a PWM
signal. This signal is connected internally to a Timer to
measure its frequency (You can use exactly the same
architecture described in the last slides to design your filter).
• DAC (Digital to Analog Comparator) is used to generate the
reference voltage.
• Don’t forget that all of this, is done in the same STM32
microcontroller!
And we can go further!
• I suppose that after obtaining the filtered
signal, I want to connect the output signal to
another hardware bloc. In this case, I can
disturb the source signal, so a follower
OPAMP is necessary.
• You are not obliged to use an external
OPAMP, because STM32 microcontrollers
offer a lot of them in only one chip. Check
your reference manual for more details.
Thank you

More Related Content

What's hot

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
 
Digital Electronics – Unit V.pdf
Digital Electronics – Unit V.pdfDigital Electronics – Unit V.pdf
Digital Electronics – Unit V.pdfKannan Kanagaraj
 
Digital Counter Design
 Digital Counter Design Digital Counter Design
Digital Counter DesignGargiKhanna1
 
L15 timers-counters-in-atmega328 p
L15 timers-counters-in-atmega328 pL15 timers-counters-in-atmega328 p
L15 timers-counters-in-atmega328 prsamurti
 
8254 timer - Microprocessor and interfacing
8254 timer - Microprocessor and interfacing8254 timer - Microprocessor and interfacing
8254 timer - Microprocessor and interfacingAmitabh Shukla
 
Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 40-42)
Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 40-42)Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 40-42)
Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 40-42)Adnan Zafar
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / CountersPatricio Lima
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontrollerAnkit Bhatnagar
 
The evolution of TMS, family of DSP\'s
The evolution of TMS, family of DSP\'sThe evolution of TMS, family of DSP\'s
The evolution of TMS, family of DSP\'sRitul Sonania
 
ARM Exception and interrupts
ARM Exception and interrupts ARM Exception and interrupts
ARM Exception and interrupts NishmaNJ
 
Timing synchronization F Ling_v1.2
Timing synchronization F Ling_v1.2Timing synchronization F Ling_v1.2
Timing synchronization F Ling_v1.2Fuyun Ling
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
Phase-Locked Loop (PLL) and Carrier Synchronization Fuyun Ling_v1.3
Phase-Locked Loop (PLL) and Carrier Synchronization Fuyun Ling_v1.3Phase-Locked Loop (PLL) and Carrier Synchronization Fuyun Ling_v1.3
Phase-Locked Loop (PLL) and Carrier Synchronization Fuyun Ling_v1.3Fuyun Ling
 

What's hot (20)

Group 11 introduction to registers and counters
Group 11 introduction to registers and countersGroup 11 introduction to registers and counters
Group 11 introduction to registers and counters
 
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
 
Counters
CountersCounters
Counters
 
Digital Electronics – Unit V.pdf
Digital Electronics – Unit V.pdfDigital Electronics – Unit V.pdf
Digital Electronics – Unit V.pdf
 
Basics Counters
Basics Counters Basics Counters
Basics Counters
 
Circuitos secuenciales
Circuitos secuencialesCircuitos secuenciales
Circuitos secuenciales
 
Digital Counter Design
 Digital Counter Design Digital Counter Design
Digital Counter Design
 
L15 timers-counters-in-atmega328 p
L15 timers-counters-in-atmega328 pL15 timers-counters-in-atmega328 p
L15 timers-counters-in-atmega328 p
 
8254 timer - Microprocessor and interfacing
8254 timer - Microprocessor and interfacing8254 timer - Microprocessor and interfacing
8254 timer - Microprocessor and interfacing
 
Line coding
Line codingLine coding
Line coding
 
Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 40-42)
Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 40-42)Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 40-42)
Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 40-42)
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / Counters
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
The evolution of TMS, family of DSP\'s
The evolution of TMS, family of DSP\'sThe evolution of TMS, family of DSP\'s
The evolution of TMS, family of DSP\'s
 
ARM Exception and interrupts
ARM Exception and interrupts ARM Exception and interrupts
ARM Exception and interrupts
 
Timing synchronization F Ling_v1.2
Timing synchronization F Ling_v1.2Timing synchronization F Ling_v1.2
Timing synchronization F Ling_v1.2
 
Counters
Counters Counters
Counters
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
Phase-Locked Loop (PLL) and Carrier Synchronization Fuyun Ling_v1.3
Phase-Locked Loop (PLL) and Carrier Synchronization Fuyun Ling_v1.3Phase-Locked Loop (PLL) and Carrier Synchronization Fuyun Ling_v1.3
Phase-Locked Loop (PLL) and Carrier Synchronization Fuyun Ling_v1.3
 
Avr timers
Avr timersAvr timers
Avr timers
 

Similar to What isn’t told about timers in stm32 application

timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptxSujalKumar73
 
8051 training an interactive tutorial
8051 training an interactive tutorial8051 training an interactive tutorial
8051 training an interactive tutorialFutura infotech
 
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
 
Training Report on embedded Systems and Robotics
Training Report on embedded  Systems and RoboticsTraining Report on embedded  Systems and Robotics
Training Report on embedded Systems and RoboticsNIT Raipur
 
Industrial training report of embedded system and robotics
Industrial training report of embedded system and roboticsIndustrial training report of embedded system and robotics
Industrial training report of embedded system and roboticsPallavi Bharti
 
project report on embedded system
project report on embedded systemproject report on embedded system
project report on embedded systemram avtar
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Aarav Soni
 
Best-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiBest-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiUnmesh Baile
 
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
 
Quickly design infrared body temperature detector
Quickly design infrared body temperature detectorQuickly design infrared body temperature detector
Quickly design infrared body temperature detectorVinsion Chan
 
unit 2 lect 6 AND 7 8254.pptx
unit 2 lect 6 AND 7 8254.pptxunit 2 lect 6 AND 7 8254.pptx
unit 2 lect 6 AND 7 8254.pptxDrVikasMahor
 
Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Ramadan Ramadan
 

Similar to What isn’t told about timers in stm32 application (20)

timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
Timers and pwm
Timers and pwmTimers and pwm
Timers and pwm
 
8051 training an interactive tutorial
8051 training an interactive tutorial8051 training an interactive tutorial
8051 training an interactive tutorial
 
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
 
Timers
TimersTimers
Timers
 
Lpc 1768 timers
Lpc 1768 timersLpc 1768 timers
Lpc 1768 timers
 
Training Report on embedded Systems and Robotics
Training Report on embedded  Systems and RoboticsTraining Report on embedded  Systems and Robotics
Training Report on embedded Systems and Robotics
 
Industrial training report of embedded system and robotics
Industrial training report of embedded system and roboticsIndustrial training report of embedded system and robotics
Industrial training report of embedded system and robotics
 
project report on embedded system
project report on embedded systemproject report on embedded system
project report on embedded system
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
Arduino 101
Arduino 101Arduino 101
Arduino 101
 
Best-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiBest-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbai
 
Timers in Arduino
Timers in ArduinoTimers in Arduino
Timers in Arduino
 
JamesEndl
JamesEndlJamesEndl
JamesEndl
 
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
 
Quickly design infrared body temperature detector
Quickly design infrared body temperature detectorQuickly design infrared body temperature detector
Quickly design infrared body temperature detector
 
Timers and Endge-aligned PWM
Timers and Endge-aligned PWMTimers and Endge-aligned PWM
Timers and Endge-aligned PWM
 
unit 2 lect 6 AND 7 8254.pptx
unit 2 lect 6 AND 7 8254.pptxunit 2 lect 6 AND 7 8254.pptx
unit 2 lect 6 AND 7 8254.pptx
 
Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Timer & Interrupt Atmega16
Timer & Interrupt Atmega16
 

Recently uploaded

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 

What isn’t told about timers in stm32 application

  • 1. What isn’t told about Timers in STM32 application notes! « Signal Processing as an example » By Omar Bouzourraa August 2017
  • 2. The main goal ?? In this brief presentation, I’m going to show you something amazing about STM32 microcontrollers! My objective is implementing an ideal filter using only stm32 microcontroller and with a full hardware solution. In other words, my goal is : - Not to use external hardware components - not to use STM32 Microcontroller CPU - obtain an ideal output from the filter
  • 3. What’s amazing in all of that? STM32 Timers are always used for timing puposes, which include signal measurement and generation. In this presentation, you will discover that STM32 Timers can be used as blocs of digital comparators.  Timers with 4 channels can be used as 4 digital comparators. Signals that describe comparaison result, are obtained on Timer output channels.  The capture compare registers are used to preload constant reference datas which are useful for comparaison.  The data to be compared with the capture compare registers, is stocked in the Counter Register and can change (without CPU intervention) while program is running.
  • 4. The hardware architecture equivalence between STM32 Timer and the classic digital comparator
  • 5. Let’s explain it more! • CCR or capture compare register, is a timer related register. It’s used for stocking data useful for setting the pwm duty-cycle when timer mode is PWM Output. For further information about this mode and other modes, please check STM32 reference manual. • CNT or Counter is also a timer related register. It usually contains the digital counter value. Please don’t confuse between the counter and the register that contains the counter value. In our case, counter should be disabled and CNT is referred to as the register and not the counter! • ARR or Auto Reload Register, is a timer related register. It contains a constant value which is known as the signal period (when typically working in PWM output mode). When the counter value reaches the ARR value, it is then reinitialized (the counter value CNT is reinitialized to zero when up-counting mode is enabled). In this presentation, we will use the up-counting mode. There is also down-counting and up-down counting modes.
  • 6. The PWM signal generation mechanism Now, I will explain how typically a timer works when PWM output mode is enabled. I suppose that we have enabled the up-counting mode and the PWM output mode PWM Mode1 (please refer to the reference manual for further information about PWM mode1 and PWM mode2) and the output polarity is not inverted. If the counter is enabled in the bit 0 of CR1 rgister :  the Timer output is active high (at the beginning).  the counter is incremented every sensitive edge detected on the timer source clock.  ARR and CCRx (x can be a value from 1 to 4) are constant while they are not modified by the CPU.  Always, CNT and CCRx are compared due to a digital comparator embedded with each channel.  When CNT > CCRx, an event is generated and the Timer output state is low.  When CNT = ARR, a second event is generated and the counter value is reinitialized to zero and so on …
  • 7. The PWM signal generation mechanism
  • 8. The STM32 Timer as a digital comparator Now the process is very simple! Just we need to configure our timer exactly the same way when we want to generate a PWM signal. But we must enable output without enabling the counter. The counter must be disabled in order to disable its automatic evolution. Let’s forget the counter and focus only on the CNT register. In fact, we don’t really need the counter but we need its value! Good news! The counter value is modifiable on the fy.Just write a value in the CCRx register (it is the reference value for comparaison).
  • 9. How can you modify the CNT value without using the CPU ? Now, it’s the time to talk about the magic of the DMA controller! DMAC : Direct Memory Access Controller. For more information, please check the reference manual! I will show you how you can measure a PWM signal frequency using a classic configuration of an STM32 Timer in PWM Input mode. This measure is transferred to the CNT of another Timer (in the same microcontroller !) using the DMAC .Finally, data is transferred to the CNT without a CPU intervetion. As a conclusion: comparing the period of a signal with a reference period value and generating the comparaison result without being obliged to use the CPU has huge advantages : We can avoid software latency and deal with signals with high frequencies , efficiently and use CPU for further applications at the same time!
  • 10. How can this be useful in signal processing ? As I said at the beginning of this presentation, my goal is to build an ideal filter using only STM32 microcontroller. Let’s talk a bit about low-pass filter! Low-pass filter is typically used for elimination of frequencies higher than a reference frequency which is known as cut-off frequency. But the problem is that obtaining a precise response demands a complex hardware architecture and always, an ideal response is so far to get! Low-pass filter is just an example! You can design all the other filters you know, using the exact same logic.
  • 11. Low-pass filter implementation with stm32 timers I suppose we want to build a low-pass filter with a cut-off frequency F0 = 20Khz. The Timer source clock for signal measurement is F_Source = 168 MHz. For a measurement precision, the prescaler must be kept in at zero value. The ARR must be initialized to its maximum value. Using the famous formula given in the reference manual, we realize the value which be latched on the CCR1 register of the timer used for measurement, is CCR1 = 8400 = 0x20D0. As we are working on low-pass filter, the filter output must be zero as soon as the measured frequency is higher than 20KHz else the output is an « identical » copy of the measured signal. Now, we choose a secod timer to work as a digital comparator. Using the DMAC, the CCR1 register value of the measurement timer is copied in the second Timer CNT register. In CCR1 register of the secod timer, you preload the value « 0x20D0 ».
  • 12. Let’s look at the schematic of the method
  • 13. Further Applications • You can do the same thing as decribed in the low-pass filter, in order to design your high-pass filter. • For band-pass filter, there is something new, to highlight. The question in this case is: How should we do, to combine 2 comparaisons (the measured frequency is compared with two reference frequencies defined in CCR1 and CCR2 registers of the timer configured as digital comparator (TIM3)) and generate only one signal to control the transistor of the GPIO port ? • We can simply use a logic AND between the two comparaisons to obtain the desired control signal. • And if we don’t want to add an external logic gate, we have a solution offered by STM32 timers. We can use the Combined Mode. • The combined mode is a specific feature (not available in all STM32 products) available on STM32 Timers. It makes it possible to generate two PWM signals on TIM_CHn and TIM_CHn+1 and make the logic « AND » or « OR » with the two signals. Combined signal is then obtained on TIM_CHn. Please check the reference manual to get more informations!
  • 14. And What should I do if the signal is analog ? • When we are dealing with analog signals, we can simply use comparators and DACs available in STM32 products. • Comparator is used to compare the analog signal with a reference voltage, in order to generate internally a PWM signal. This signal is connected internally to a Timer to measure its frequency (You can use exactly the same architecture described in the last slides to design your filter). • DAC (Digital to Analog Comparator) is used to generate the reference voltage. • Don’t forget that all of this, is done in the same STM32 microcontroller!
  • 15. And we can go further! • I suppose that after obtaining the filtered signal, I want to connect the output signal to another hardware bloc. In this case, I can disturb the source signal, so a follower OPAMP is necessary. • You are not obliged to use an external OPAMP, because STM32 microcontrollers offer a lot of them in only one chip. Check your reference manual for more details.