Docsity
Docsity

Prepara tus exámenes
Prepara tus exámenes

Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity


Consigue puntos base para descargar
Consigue puntos base para descargar

Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium


Orientación Universidad
Orientación Universidad


Microprocesadores Timers, Diapositivas de Microprocesadores

Presentación de Clase sobre Timers del curso de microprocesadores

Tipo: Diapositivas

2020/2021

Subido el 13/04/2021

jorge-enrique-perez-escobar
jorge-enrique-perez-escobar 🇬🇹

5 documentos

1 / 20

Toggle sidebar

Esta página no es visible en la vista previa

¡No te pierdas las partes importantes!

bg1
1
Timer Peripherals
Julio Enrique Fajardo
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Vista previa parcial del texto

¡Descarga Microprocesadores Timers y más Diapositivas en PDF de Microprocesadores solo en Docsity!

Timer Peripherals

Julio Enrique Fajardo

Types of Timer Peripherals

▪ Interrupt Timer ▪ Can generate periodically generate interrupts or trigger DMA (direct memory access) transfers ▪ PWM Module ▪ Connected to I/O pins, has input capture and output compare support ▪ Can generate PWM signals ▪ Can generate interrupt requests ▪ Low-Power Timer ▪ Can operate as timer or counter in all power modes ▪ Can wake up system with interrupt ▪ Can trigger hardware ▪ Real-Time Clock ▪ Powered by external 32.768 kHz crystal ▪ Tracks elapsed time (seconds) in register ▪ Can set alarm ▪ Can generate 1Hz output signal and/or interrupt ▪ Can wake up system with interrupt ▪ SYSTICK ▪ Part of CPU core’s peripherals ▪ Can generate periodic interrupt

INTERRUPT TIMER

Interrupt Timer

▪ Load start value from register

▪ Counter counts down with each clock pulse

▪ When timer value reaches zero

▪ Generates interrupt ▪ Reloads timer with start value Write 1000 to timer max Enabling timer loads counter with 1000, starts counting Timer counts down to 0 Interrupt generated, counter reloads with 1000, starts counting Write 700 to timer max Interrupt generated, counter reloads with 700, starts counting Interrupt generated, counter reloads with 700, starts counting Interrupt generated, counter reloads with 700, starts counting Interrupt Clock Read current timer value Presettable Binary Counter Interrupt Reload Start Value Read / write timer start value

Configuring the Interrupt Timer

▪ Setup timer, set to tick at 10 Hz

▪ timer_init(CLK_FREQ / 10);

▪ Set interrupt

▪ timer_set_callback(timer_isr);

▪ Enable module

▪ timer_enable();

▪ Disable module

▪ timer_disable();

Example: Stopwatch

▪ Measure time with 100 us resolution

▪ Display elapsed time, updating screen every 10 ms

▪ Controls

▪ S1: toggle start/stop

▪ Use interrupt timer

▪ Counter increment every 100 us ◦ Set to timer to expire every 100 us ◦ Calculate max value, e.g. at 24 MHz = round (100 us * 24 MHz - 1) = 2399 ▪ LCD Update every 10 ms ◦ Update LCD every nth ISR ◦ n = 10 ms/100us = 100 ◦ Don’t update LCD in ISR! Too slow. ◦ Instead set flag in ISR, poll it in main loop

Timer

▪ Core Counter

▪ Clock options - external or internal ▪ Prescaler to divide clock ▪ Can reload with set value, or overflow and wrap around

▪ N channels

▪ 3 modes ◦ Capture Mode: Capture timer’s value when input signal changes ◦ Output Compare: Change an output signal when timer reaches certain value ◦ PWM: Generate pulse-width-modulated signal. Width of pulse is proportional to specified value. ▪ Possible triggering of interrupt, hardware trigger on overflow ▪ One I/O pin per channel

Major Channel Modes

▪ Input Capture Mode

▪ Capture timer’s value when input signal changes ◦ Rising edge, falling edge, both ▪ How long after I started the timer did the input change? ◦ Measure time delay

▪ Output Compare Mode

▪ Modify output signal when timer reaches specified value ◦ Set, clear, pulse, toggle (invert) ▪ Make a pulse of specified width ▪ Make a pulse after specified delay

▪ Pulse Width Modulation

▪ Make a series of pulses of specified width and frequency

Wind Speed Indicator (Anemometer)

▪ Rotational speed (and pulse frequency) is

proportional to wind velocity

▪ Two measurement options:

▪ Frequency (best for high speeds) ▪ Width (best for low speeds)

▪ Can solve for wind velocity v

▪ How can we use the timer for this?

▪ Use Input Capture Mode to measure period of input signal 𝑣𝑤𝑖𝑛𝑑 = 𝐾 ∗ 𝑓𝑐𝑙𝑘 𝑇𝑎𝑛𝑒𝑚𝑜𝑚𝑒𝑡𝑒𝑟

TPM Capture Mode for Anemometer

▪ Configuration

▪ Set up module to count at given speed from internal clock ▪ Set up channel for input capture on rising edge

▪ Operation: Repeat

▪ First interrupt - on rising edge ◦ Reconfigure channel for input capture on falling edge ◦ Clear counter, start it counting ▪ Second interrupt - on falling edge ◦ Read capture value, save for later use in wind speed calculation ◦ Reconfigure channel for input capture on rising edge ◦ Clear counter, start it counting

Pulse-Width Modulation

▪ Uses of PWM ▪ Digital power amplifiers are more efficient and less expensive than analog power amplifiers ◦ Applications: motor speed control, light dimmer, switch-mode power conversion ◦ Load (motor, light, etc.) responds slowly, averages PWM signal ▪ Digital communication is less sensitive to noise than analog methods ◦ PWM provides a digital encoding of an analog value ◦ Much less vulnerable to noise ▪ PWM signal characteristics ▪ Modulation frequency – how many pulses occur per second (fixed) ▪ Period – 1/(modulation frequency) ▪ On-time – amount of time that each pulse is on (asserted) ▪ Duty-cycle – on-time/period ▪ Adjust on-time (hence duty cycle) to represent the analog value

PWM Mode

▪ PWM duty cycle proportional to compare value

▪ Period = max timer value ▪ Pulse width = compare value

Enable timer (^) Overflow Overflow Timer Value Output Pin Compare Value

LOW POWER TIMER

Low Power Timer Overview

▪ Features

▪ Count time or external pulses ▪ Generate interrupt when counter matches compare value ▪ Interrupt wakes MCU from any low power mode

▪ Current draw can be reduced to microamps or even nanoamps!

▪ Use the WFI instruction (Wait For Instruction)

▪ Puts CPU in low power mode until interrupt request Current Time Interrupt routine Sleeping mode Average Current Processor Always On With Low Power Timer