












Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Prepara tus exámenes
Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Prepara tus exámenes con los documentos que comparten otros estudiantes como tú en Docsity
Encuentra los documentos específicos para los exámenes de tu universidad
Estudia con lecciones y exámenes resueltos basados en los programas académicos de las mejores universidades
Responde a preguntas de exámenes reales y pon a prueba tu preparación
Consigue puntos base para descargar
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Comunidad
Pide ayuda a la comunidad y resuelve tus dudas de estudio
Ebooks gratuitos
Descarga nuestras guías gratuitas sobre técnicas de estudio, métodos para controlar la ansiedad y consejos para la tesis preparadas por los tutores de Docsity
Presentación de Clase sobre Timers del curso de microprocesadores
Tipo: Diapositivas
1 / 20
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!













▪ 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
▪ 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
▪ timer_init(CLK_FREQ / 10);
▪ timer_set_callback(timer_isr);
▪ timer_enable();
▪ timer_disable();
▪ S1: toggle start/stop
▪ 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
▪ Clock options - external or internal ▪ Prescaler to divide clock ▪ Can reload with set value, or overflow and wrap around
▪ 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
▪ 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
▪ 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
▪ Make a series of pulses of specified width and frequency
▪ Frequency (best for high speeds) ▪ Width (best for low speeds)
▪ Use Input Capture Mode to measure period of input signal 𝑣𝑤𝑖𝑛𝑑 = 𝐾 ∗ 𝑓𝑐𝑙𝑘 𝑇𝑎𝑛𝑒𝑚𝑜𝑚𝑒𝑡𝑒𝑟
▪ Set up module to count at given speed from internal clock ▪ Set up channel for input capture on rising edge
▪ 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
▪ 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
▪ Period = max timer value ▪ Pulse width = compare value
Enable timer (^) Overflow Overflow Timer Value Output Pin Compare Value
LOW POWER TIMER
▪ Count time or external pulses ▪ Generate interrupt when counter matches compare value ▪ Interrupt wakes MCU from any low power mode
▪ Puts CPU in low power mode until interrupt request Current Time Interrupt routine Sleeping mode Average Current Processor Always On With Low Power Timer