Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

. For pulse width measurement the timers in the TM4C123 have a very nice feature

ID: 2266734 • Letter: #

Question

. For pulse width measurement the timers in the TM4C123 have a very nice feature split into two 16 bit timers TIMEROA and TIMEROB. These A 32 bit timer can be imers count in lock step. They are started together and always have the same count. TIMEROB will measure the rising edge and TIMEROA will measure the falling edge. Both timers are set up in the input compare mode and count down MI ROB is setup to capture the rising edge and TIMEROA is setup to capture the lalling edge and generate an interrupt. In the interrupt service routine for TIMEROA the pulse width is calculated. Write the ISR code for measuring the pulse width. Assurme the counter does not roll over for this problem. The following functions are available to you. (20 points) TI TimerValueGet(TIMERO BASE, TIMER A); TimerValueGet(TIMERO BASE, TIMER B) TimerintClear(TIMERO BASE, TIMER CAPA EVENT TIMERO CCPO1 uint32 t pulse Width; void TimerOA Handler(void)

Explanation / Answer

Programming code :

#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"

void init_timer(void);
void duty_cycle(void);
void init_UART(void);
uint32_t sys_clock;
uint32_t start = 0, end = 0, length = 0;

int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
sys_clock = SysCtlClockGet();
IntMasterEnable();

init_UART();
init_timer();

TimerEnable(TIMER0_BASE, TIMER_BOTH);

while(1);
}

void init_timer(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

TimerConfigure(TIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP | TIMER_CFG_B_CAP_TIME_UP));
TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_NEG_EDGE);
TimerLoadSet(TIMER0_BASE, TIMER_BOTH, 0x9C3F);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB6_T0CCP0);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
IntRegister(INT_TIMER0A, duty_cycle);
TimerIntClear(TIMER0_BASE, TIMER_CAPA_EVENT);
TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT);
IntEnable(INT_TIMER0A);
}
void duty_cycle(void)
{
TimerIntClear(TIMER0_BASE, TIMER_CAPA_EVENT);
start = TimerValueGet(TIMER0_BASE, TIMER_A);
end = TimerValueGet(TIMER0_BASE, TIMER_B);
length = end - start;

UARTprintf(" LENGTH = %d ", length);
}

void init_UART(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, (GPIO_PIN_0 | GPIO_PIN_1));
UARTStdioConfig(0, UART1_BAUDRATE, sys_clock);
}