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.

TM4C1230H6PM: Using a TivaWare Library Timer to generate a software based PWM - help with interrupts

Part Number: TM4C1230H6PM

Hi guys,

I am working on a product for which the hardware layout and pin-out does not allow me to use my PWM assigned ports. For this reason I am trying to generate one via SW using a Digital Output port.

This is working fine, but I would like to have the Timer do the work for me since I see in the manual that I can generate a Timer for a PWM signal by setting a period and a match value. However, when I do this, my routine is not called by any interrupt source. The code is spread apart, but the config is the following:

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM);
TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_BOTH_EDGES);
TimerLoadSet(TIMER0_BASE, TIMER_B, 50000);
TimerMatchSet(TIMER0_BASE, TIMER_B, 40000); IntEnable(INT_TIMER0B);
TimerEnable(TIMER0_BASE, TIMER_B);
TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT | TIMER_CAPB_MATCH);

I know, that TIMER_CAPB_MATCH might not be the right source, but... the question is... can I really do this? What should be the interrupts to expect and look for? Or is the PWM Timer only useful for a real PWM output?

Thanks in advance for any help!

  • Hello Joao,

    Have you looked at the example we provide in TivaWare?

    It is located at [Install Path]\TivaWare_C_Series-2.1.4.178\examples\peripherals\timer

    Look for the pwm.c file.

    I don't think you need interrupts at all to do what you want. The Timer module if configured right will output your PWM without interrupts needed. I don't see any value in even trying to do an interrupt based on your description which is that you want to general a Timer-based PWM signal with a period & match value.

    Check the example we provided and see how it is done, you basically have all of it but added unneeded complexity with the interrupt piece.

  • May our small yet "semi-skilled" outsider group - essentially agree w/Vendor's Ralph?

    Once the Timer has been properly Set-Up & Configured - it will (happily) continue to provide the PWM Frequency & Duty Cycle which you've specified & enabled.    Now should you seek to "Update" (usually the Duty Cycle) that can be accomplished with a "Periodic, Polled Read of a dedicated GPIO pin."   (i.e. when that "Duty Cycle Update pin is active" - your code implements the Duty Cycle Update/Change/ON or OFF code routine.)

    Undescribed  is the role of the PWM Output.   Should it drive a "serious" (perhaps a power application) then the use of (only) the MCU's Timer to yield the PWM - is likely to prove a liability!    (i.e. the PWM Generators offer serious (and eased) "Protective Modes" (over-current shut-down, as just one example.)    While you may be able to add such capability to your "Timer-Generated PWM" - added time, effort & cost result.

    Design capability & flexibility also "enters the picture."    Each PWM Generator provides 2 highly controllable PWM Outputs.   Such proves ideal when driving a "Half H-Bridge" (or similar) especially as "dead-band" is included along w/the ability to "Sync" different PWM Generator Outputs.   Also easily obtained is the "automatic disabling" of "select or ALL" PWM Outputs - based upon the application of signal to (just one) of the MCU's PWM Fault Pins!   Thus - much is "discarded" by that (likely) early-on MCU design implementation.   Seriously - was that wise?

    It is always "unfortunate" when "Early-On Design Implementations" - cause such an impact upon the project's "Lasting Capabilities!"    

  • Hi Ralph,

    Thanks for the quick reply.

    I understand this and I have checked the example you gave me. However, the issue is that the hardware is fixed and the pin in question is PE1 which cannot be set a CCP/Timer only UART Tx. So I consider then a software solution using the interrupts, therefore I was wondering if its possible to find triggers for MATCH and TIMEOUT or OVERFLOW for the Timer PWM signal because I cannot find this info on the Datasheet.

    Thanks again!

  • Hello Joao,

    There aren't interrupts for Timer PWM signals like that and even if there were I don't think you would gain much compared to standard timer operation. You can run the timer in standard mode and have Match / Timeout interrupts. That's the closest you will get. There are definitely limitations to what you can do with just a GPIO when trying to emulate a precise PWM signal... unfortunately as robust as the MCU is, there isn't a great solution for this scenario beyond a standard Timer running and then toggling the I/O based on Match/Timeout interrupts.

  • Hello Ralph,

    Again thanks for the super quick reply.

    I understand that, it our design fault here, but we currently have a solution which is competly by software only unsing a TIMEOUT interrupt. I just want to try to improve that a little. For instance by adding the MATCH interrupt, however... I do not know how to activate this. Which flag should i add? TIMER_CAPB_MATCH?

  • Hi Ralph,

    Have you, staff, I, others - all just witnessed the (exact) reverse of, "Feature Creep?"   

    "Feature-Lite" products - caused by "less than inspired" Early-On Design choices ... Caveat Venditor!   (Let the Seller beware!)    Such products are not likely to, "Fly from the shelves!"

  • Hello Joao,

    It would be TIMER_TIMB_MATCH. The CAPB_MATCH flag is for Capture/Compare events. That would be why your above code block isn't working.

  • Oh, indeed. I have been so focused on this that I have missed this flag completly in the header and documentation. (sorry to have asked about it)!

    Thanks, for all the info!