infineon4engineers Facebook

infineon@google+ Google+

infineon@linkedin linkedin

infineon4engi@twitter twitter

infineon@youtube youtube

+ Reply to Thread
Results 1 to 8 of 8

Thread: PWM duty cycle and frequency measurement using TIM PWM measurement mode. TricoreTC277

  1. #1
    New Member New Member Aparajith is on a distinguished road
    Join Date
    Feb 2018
    Posts
    3
    Points
    45

    PWM duty cycle and frequency measurement using TIM PWM measurement mode. TricoreTC277

    Hi all,

    I am new to Tricore architecture and my goal is to measure PWM signal(s) using the GTM - TIM module's PWM measurement mode.

    Could anyone help me with a sample source code or the steps involved to configure the registers to do a measurement of dutycycle and frequency?

    I tried referring to Infineons datasheet with very little success.

    Thanks in advance.

    Best regards,
    Aparajith

  2. #2
    Beginner Beginner vinicius.oliveira is on a distinguished road
    Join Date
    Jun 2018
    Posts
    9
    Points
    105
    Hi Aparajith,

    Did you accomplish this? Because I'm trying the same, but I couldn't find any example on this topic.

    Best.

  3. #3
    New Member New Member tomazpercic is on a distinguished road
    Join Date
    Mar 2018
    Posts
    10
    Points
    235
    I have accomplished this on the TC277 with ILLD 1.0.1.0.0.

    I've used TIM1 module with source clock CMU_CLK0. Let me know if you need a sample of code.

    Regards,
    Tomaz

  4. #4
    Beginner Beginner vinicius.oliveira is on a distinguished road
    Join Date
    Jun 2018
    Posts
    9
    Points
    105
    Hi Tomaz,

    Thank you for your reply. It would be great to take look in your sample code. Could you please share with me?

    Best,
    Vinicius.

  5. #5
    New Member New Member tomazpercic is on a distinguished road
    Join Date
    Mar 2018
    Posts
    10
    Points
    235
    See below. I have skipped parts of code which aren't necessary and most of the comments. You should check what each function does and add comments accordingly.

    INIT:
    Code:
    IfxGtm_Tom_Pwm_Driver _timDriver; // should be global
    
    Ifx_GTM *gtm = &MODULE_GTM;
    
    IfxGtm_enable(gtm);
    
    IfxGtm_Cmu_setGclkFrequency(gtm, (float)GTM_CFG_GCLK_FREQUENCY);
    
    IfxGtm_Cmu_setClkFrequency(gtm, IfxGtm_Cmu_Clk_0, 10000000);
    
    IfxGtm_Cmu_enableClocks(gtm, GTM_CFG_CLK_SRC_TIM_EN);
    
    IfxGtm_Tim_In_Config TimConfig;
    
    IfxGtm_Tim_In_initConfig(&TimConfig, gtm);
    
    TimConfig.capture.clock = IfxGtm_Cmu_Clk_0;
    TimConfig.filter.inputPin 	  = &IfxGtm_TIM0_0_TIN87_P14_7_IN; // select channel
    TimConfig.filter.inputPinMode = IfxPort_Mode_inputNoPullDevice; // select mode
    
    IfxGtm_Tim_In_init(&_timDriver, &TimConfig);

    Measure frequency:
    Code:
    Ifx_GTM_TIM_CH_GPR0 GPR0;
    Ifx_GTM_TIM_CH_GPR1 GPR1;
    uint32 period_ticks = 0;
    
    // check if new event
    if (IfxGtm_Tim_Ch_isNewValueEvent(_timDriver.channel))
    {
    	IfxGtm_Tim_Ch_clearNewValueEvent(_timDriver.channel);
    
    	// get values from registers
    	GPR1.U       = _timDriver.channel->GPR1.U;
    	GPR0.U       = _timDriver.channel->GPR0.U;
    	period_ticks = GPR1.B.GPR1;
    
    	// calculate frequency
    	_frequency = 10000000 / (float) period_ticks;
    }
    else
    {
    	_frequency = 0;
    }
    The duty cycle will be stored in GPR0.B.GPR0 register (in ticks of TIM counter frequency).

    Regards,
    Tomaz

  6. #6
    Beginner Beginner vinicius.oliveira is on a distinguished road
    Join Date
    Jun 2018
    Posts
    9
    Points
    105
    Hi Tomaz,

    I have tryed your code with iLLD 1.0.5.0.0, unfortunately with no luck. Especially because of "IfxGtm_Tom_Pwm_Driver _time Driver;" struct:

    Code:
    typedef struct
    {
        Ifx_GTM         *gtm;              /**< \brief Pointer to GTM module */
        IfxGtm_Tom       tomIndex;         /**< \brief Index of the TOM object used */
        IfxGtm_Tom_Ch    tomChannel;       /**< \brief TOM channel used for the timer */
        Ifx_GTM_TOM     *tom;              /**< \brief Pointer to the TOM object */
        Ifx_GTM_TOM_TGC *tgc[2];           /**< \brief Pointer to the TGC object */
    } IfxGtm_Tom_Pwm_Driver;
    Which does not contain "_timDriver.channel" for example. Then I have tryed with "IfxGtm_Tim_In":

    Code:
    typedef struct
    {
        Ifx_GTM_TIM_CH *channel;                     /**< \brief TIM channel used */
        uint32          periodTick;                  /**< \brief Period value in clock ticks */
        uint32          pulseLengthTick;             /**< \brief Duty value in clock ticks */
        boolean         dataCoherent;                /**< \brief TRUE, if the duty and period values are measured from the same period */
        boolean         overflowCnt;                 /**< \brief TRUE if the last measurement show an overflow in CNT */
        boolean         newData;                     /**< \brief TRUE when values are updated, and  if none of the counter CNT, CNTS have overflowed */
        boolean         dataLost;                    /**< \brief TRUE if data are lost */
        uint32          edgeCounterUpper;            /**< \brief upper part of the edge counter */
        boolean         glitch;                      /**< \brief TRUE if glitch is detected */
        float32         captureClockFrequency;       /**< \brief Capture clock frequency in Hz */
        IfxGtm_Tim      timIndex;                    /**< \brief Index of the TIM module being used. */
        IfxGtm_Tim_Ch   channelIndex;                /**< \brief Index of the TIM channel being used. */
        uint16          edgeCount;                   /**< \brief number of edges counted. */
    } IfxGtm_Tim_In;
    INIT:
    Code:
    /* initialize TIM */
    IfxGtm_Tim_In_Config configTim;
    IfxGtm_Tim_In _timDriver;
    
    IfxGtm_enable(&MODULE_GTM);
    // we set the global clock to 100MHz
    IfxGtm_Cmu_setGclkFrequency(&MODULE_GTM, 100000000.0f);
    // set CMU0 frequency
    IfxGtm_Cmu_setClkFrequency(&MODULE_GTM, IfxGtm_Cmu_Clk_0, 100000000.0f);
    // enable CMU0 clock
    IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_CLK0);
    // enable FX clock
    IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_FXCLK);
    
    IfxGtm_Tim_In_initConfig(&configTim, &MODULE_GTM);
    configTim.capture.clock 	  = IfxGtm_Cmu_Clk_0;
    configTim.filter.inputPin 	  = &IfxGtm_TIM0_1_TIN1_P02_1_IN;   // select channel
    configTim.filter.inputPinMode = IfxPort_Mode_inputNoPullDevice; // select mode
    IfxGtm_Tim_In_init(&_timDriver, &configTim);
    READ:
    Code:
    	// check if new event
    	if (IfxGtm_Tim_Ch_isNewValueEvent(_timDriver.channel))
    	{
    		IfxGtm_Tim_Ch_clearNewValueEvent(_timDriver.channel);
    		// get values from registers
    		GPR1.U       = _timDriver.channel->GPR1.U;
    		GPR0.U       = _timDriver.channel->GPR0.U;
    		period_ticks = GPR1.B.GPR1;
    	}
    Well I will keep debbuging, thank you for your help.

    Best,
    Vinicius.

  7. #7
    Beginner Beginner vinicius.oliveira is on a distinguished road
    Join Date
    Jun 2018
    Posts
    9
    Points
    105
    It seens to be working now.

    Thank you Tomaz.
    Last edited by vinicius.oliveira; Sep 14th, 2018 at 07:35 AM.

  8. #8
    New Member New Member tomazpercic is on a distinguished road
    Join Date
    Mar 2018
    Posts
    10
    Points
    235
    The struct IfxGtm_Tom_Pwm_Driver is completely my mistake, sorry. I've had TIM and TOM init in the same file and copied the wrong one. You've used the correct one (we're using TIM, not TOM of course).

    You don't need to enable the FXCLK, that one is used only for the TOM. The TIM uses the CMU_CLKx (x = 0 to 7).

    Do you know in what way it stops working?
    Are there no new events or does the app hang?
    How often are you calling the read code?
    What input frequency are you measuring?
    How many times does it work?

    EDIT: No problem.
    Last edited by tomazpercic; Sep 14th, 2018 at 08:09 AM.

+ Reply to Thread

Tags for this Thread

Disclaimer

All content and materials on this site are provided “as is“. Infineon makes no warranties or representations with regard to this content and these materials of any kind, whether express or implied, including without limitation, warranties or representations of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. No license, whether express or implied, is granted by Infineon. Use of the information on this site may require a license from a third party, or a license from Infineon.


Infineon accepts no liability for the content and materials on this site being accurate, complete or up- to-date or for the contents of external links. Infineon distances itself expressly from the contents of the linked pages, over the structure of which Infineon has no control.


Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Usage Terms of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Usage Terms of this site. Infineon reserves the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.