This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EK-TM4C1294XL: Connected LaunchPad Workshop -- Lab05: Interrupts and the Timer

Part Number: EK-TM4C1294XL
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.)

  • I agree that the "Homework Idea" is ambiguous. I suspect that the homework idea suggestion was a straight copy from the TM4C123G LaunchPad Workshop. On that device the pin used as a GPIO to control an LED can also be configured as a general purpose timer PWM output. This is not the case on the EK-TM4C1294XL launchpad. Because of that this homework suggestion should not have been included in the TM4C1294XL LaunchPad workshop. I apologize for the confusion.

    If you are still up for a challenge, LED D4, attached to PF0, can be configured as a PWM module output pin. (The PWM modules are different than the general purpose timers.) A similar experiment can be done with that LED.
  • If I can "escape" having my head handed me (again) for, "Complementing a poster" (vendor or outsider) is poster N.K.'s effort here not, "Absolutely terrific?"

    And its his/her very first post - which we'd never know - as he/she: correctly formatted code, provided a well described narrative, and made use of "bold" to properly emphasize & focus.     Absent the post was any mention of the dreaded, "Expected or Urgent" - both noted as manipulative & commanding - neither motivating...

    If and when "N.K." plans to, "Issue Stock" - cb1 firm pleasantly notes (some) excess capital - enjoys (guiding/assisting) the launch of, "shooting stars!"

  • Oh stop, you're making me blush! But really, this feedback is highly appreciated! I did spend about 45 minutes writing my question, so it is good to know that my effort was appreciated! I learned a lot of my post-writing etiquette from the stack exchange network, so I'm glad that paid off as well. Lastly, male pronouns are fine, thank you! :)
  • I cannot tell you how glad I am to hear that! Thank you for your clarification, I really appreciate it! (Now I just wish I had asked this question about two days ago ;)

    I'll gladly take you up on your challenge! Hopefully I won't end up back here asking silly questions.


    As a side note, is there a place (like the workshop wiki, perhaps) where errata and small changes like this can be user-documented? I'm trying to follow the guide pretty closely, and I have noticed the odd change here or there that can be made. I know the documentation is 3+ years old by now, but maybe it could help out someone in the future!


    Thanks again,
    NK

    (Reposted, as original was erroneously marked (by me) as solving the problem.)

  • Do realize - as small, (somewhat successful) Tech Biz Owner - it IS my job to recognize, attract, capture & groom talent.      It is a pity that "not more here" make the time/effort to "mark & reward" excellence...    And grievously noted by the recent "expulsion" of  "LIKE" from the forum-post's, "click-options!"

    For a "first ever" post here - even w/your "stack exchange" background - especially w/your "stack exchange" background - you got, "So many things right" that such, "Had to be noted!"      And "Had to be applauded" - that rises beyond "sentiment" - is a simple, "statement of fact."

    If you can sustain such care, focused effort, & interest - even when "Going gets rough" - your tech future is assured.     (having past co-founded, taken Tech firm Public - I, "just may be qualified"  to, "make such pronouncements...")          (maybe)