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.

MSPM0G3507: Best way to capture the time of a PWM's rising edge and falling edge

Part Number: MSPM0G3507
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hi,

I need to capture a PWM's rising edge and falling edge and do something during that period time.

Right now, I use the PWM's interrupt which is triggered by both rising edge and falling edge. Because there is no way to know it is a falling edge or rising edge in the ISR, I have to maintain a variable to store the last state and toggle the state in ISR. The method might easily cause errors.

These are the other ways I can think of:

1. If there is a bit from PWM's registers can represent the PWM output (high or low), I can directly use the value of this bit;

2. If there are two interrupts from the same PWM, one of which is from PWM's falling edge and another from rising edge.

If these two methods are available, it will make things easier. 

So far, I didn't find such a bit from a Timer's registers. Also didn't find there are two interrupts that can be assigned to a timer for PWM.

I am wondering if I just didn't find either one. Or these two options are not available for this MCU at all. 

Can you help confirm this? Or there are other ways for this MCU to achieve this goal?

Thanks!

Crane

  • The trick is to set both timer channels to monitor the same pin, using the IFCTL:ISEL setting (either =1 or =2). Then set one channel for rising edge, and the other for falling edge, so you can distinguish the edge by which channel triggers.

    This method is used in Use Case "Combined Pulse Width and Period Time" [Ref TRM (SLAU846A) Sec 25.2.3.1.2.4]. You can't use that method exactly due to Erratum TIMER_ERR_01, but your case will look very similar.

  • Thanks Bruce for your input.

    It looks like it is not available to configure IFCTL in syscofig tool, right? Is there any example available for this use case?

    In addition, in the ISR, how to determine which channel triggers the interrupt?

    Thanks!

    Crane

  • It looks like the example timx_timer_mode_capture_duty_and_period implements the use case I mentioned:

    https://dev.ti.com/tirex/explore/node?node=A__ACdsrKl.4hX4Pw9rSp1lsA__MSPM0-SDK__a3PaaoK__LATEST

    Looking at the syscfg, they did it somewhat differently from the way I expected. DriverLib evidently defines a "Single/Combined" mode which does the ISEL matching for you, but also sets up some other conditions. Further down, "Interrupts configuration" allows you to enable Compare [sic] interrupts for both channels.

    Alternatively, it looks as though you can use "Multi" mode then set "Input Channels"->"Select All". That enables individual configuration for each channel. I haven't tried this, but it may be useful to know if you find the Combined mode has too many hidden assumptions.

    When I did this I didn't use sysconfig/DriverLib. If a Wizard tells you something different, believe that.

    [Edit: Sorry, I forgot your second question. In the ISR you would add a second case looking something like:

    > case DL_TIMERG_IIDX_CC0_DN: 

    for the other channel. You may or may not be interested in the ZERO case.]