Manual ARM Microcontroller Course E.T.S.V. Scintilla

Add to my manuals
36 Pages

advertisement

Manual ARM Microcontroller Course E.T.S.V. Scintilla | Manualzz

9 Timers

A peripheral found in all microcontrollers is the timer. Timers is a counter fed by a clock. It can be considered to be a register which increments or decrements

(depending on the timer settings) by one on every tick of a clock connected to it.

The microcontroller on the Nucleo has seven general purpose timers: TIM2

-TIM5 and TIM9 - TIM11 of which the latter only count upwards. The timers can be fed with different clock sources, internally or externally.

This clock source is fed through a programmable 16-bit clock divider called "prescaler" to generate a clock signal for the timer. If the counter TIMx_CNT reaches a so called auto-reload value TIMx_ARR it resets the counter to zero and throws a event.

The counter is connected to four input capture/ output compare channels

TIMx_OC. These channels can be connected to a output pin and can work in different modes ranging from measuring the pulse length on a input to toggle a output. In figure

1

a simplified sketch is made to give insight in the purpose of the auto-reload and the output compare registers. Of course is this only one of the possible modes of operation. Look in the reference manual in chapter 13 or

14 for more in depth information about which registers to use.

There are also timers with more specific task: The main purpose of a watchdog is to check whether or not the code not hangs, it does this by being set periodically to an initial value, if for some reason this does not happen, then the device gets reset or an event is thrown.

Another timer is the Systick timer. This timer runs on the background and is used to generate so called ticks which are used by a realtime operating system to schedule slots for the different task.

Exercise 5

Use a Timer 2 to make an LED blink. To do this follow the following steps

1. Set up the the LED as output.

2. Enable the clock to timer 2.

3. Initialize the timer using a TIM_HandleTypeDef from the HAL.

4. Set up the timer interrupt NVIC priority and enable this interrupt using the HAL.

5. Start the timer using the HAL.

6. Make an interrupt routine for TIM2_IRQHandler to call to HAL_TIM_IRQHandler

7. Make the LED blink on the "period elapsed" routine (HAL_TIM_PeriodElapsedCallback).

27

Table 11 List of possible GPIO settings in ARM microcontrollers

Register

TIMx_CR1

TIMx_CR2

CH.

Full name

13.4.1 Control register one

13.4.2 Control register two

Function

Main control register, used for enabling the counter and setting the counter mode

Second control register, used for setting DMA and other triggering

Settings used for using the timer in slave mode TIMx_SMCR

TIMx_DIER

TIMx_SR

TIMx_EGR

TIMx_PSC

TIMx_ARR

TIMx_CCR1

13.4.3 Slave mode control register

13.4.4 DMA / interupt enable register

TIMx_CCMR1 13.4.7 Capture/ Compare mode register 1

TIMx_CCER

TIMx_CNT

TIMx_DCR

TIMx_DMAR

TIM2_OR

13.4.5 Status register

13.4.6 Event generation register

13.4.9 Capture/ Compare enable register

13.4.10 Counter register

Used for enabling the different interupt/ dma events

Houses all the interrupt flags

Settings for generating DMA events

Mode selection of the different channels

Setting for the polarity of the channels and enabling them

The register containing the counter value

13.4.11 Prescaler register

13.4.12 Auto-reload register

Prescaler used for dividing the clock

The register containing the auto-reload value

13.4.13 Capture/ Compare register channel 1

The register containing the capture/ compare value of channel one

13.4.17 DMA control register Settings for the DMA

13.4.18 DMA adress register for full transfer

The register containing the adress for burst

DMA

13.4.19 TIM2 option register Extra options

28

Figure 1: Simplified timing diagram

29

advertisement

Was this manual useful for you? Yes No
Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Related manuals