Other Parts Discussed in Thread: TM4C1294NCPDT,
I am working my way through the Tiva C Series Connected LaunchPad Workshop as my first introduction to microcontroller programming (although I have knowledge of C and higher-level languages).
For the most part, the tutorial has been excellent in showing me what I need to know when I need to know it. However, I find the suggested "Homework Idea[s]" (eg. at the end of Lab03 and Lab05) impossible. For the purpose of this question, I will focus on the Lab05 "Interrupts and the Timer" homework idea.
For convenience, I have reproduced the description here:
Homework Idea: Investigate the Pulse-Width Modulation capabilities of the general purpose timer. Program the timer to blink the LED aster than your eye can see, usually above 30Hz and use the pulse width to vary the apparent intensity. Write a loop to make the intensity vary periodically.
Also, for convenience, I have included the "main.c" from Lab05 at the end of this post.
My question is the following: Am I being asked to investigate the PWM capabilities via configurations such as TIMER_CFG_A_PWM, or simply by adding a second PERIODIC timer to count out the duty cycle and activate an interrupt? The latter was (almost) trivial for me to implement, but the wording of the question makes me think they intend the former. If it is the former, I would love some help in figuring this out, as all my efforts to understand the documentation so far have been fruitless. (Actually, if it's the latter, I would also love some feedback about my implementation, which I can share.)
Thank you!
- A Newbie
Lab05's "main.c"
#include <stdint.h> #include <stdbool.h> #include "inc/tm4c1294ncpdt.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" #include "driverlib/gpio.h" #include "driverlib/timer.h" int main(void) { uint32_t ui32Period; uint32_t ui32SysClkFreq; ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0|GPIO_PIN_1); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ui32Period = ui32SysClkFreq/2; TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1); IntEnable(INT_TIMER0A); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); IntMasterEnable(); TimerEnable(TIMER0_BASE, TIMER_A); while(1) { } } void Timer0IntHandler(void) { // Clear the timer interrupt TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Read the current state of the GPIO pin and // write back the opposite state if(GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_1)) { GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0); } else { GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 2); } }
(Note that "tm4c1294ncpdt_startup_ccs.c" is also edited to include "Timer0IntHandler", this is just not shown here.)