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.

CC2538: CC2538 PWM for ZLL

Part Number: CC2538
Other Parts Discussed in Thread: CC2530

Hello,

I need to use PWM for 3/4 Channels for controlling RGBW LED's and for this I have done the configuration specified by Yikai in the following link:

But here I need to understand the PWM as it is not working because the timer_init function has only following things in the default code.

void HalTimer1Init (halTimerCBack_t cBack)
{
  //not used for now
  (void) cBack;

  //
  // Enable GPT0
  //
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);

  //
  // Configure Timer0A for PWM use
  //
  TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
                 GPTIMER_CFG_A_PWM);

  //
  // Set Duty cycle and enable
  //
  TimerLoadSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
  TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
  TimerEnable(GPTIMER0_BASE, GPTIMER_A);

  //
  // Set duty cycle to 0
  //
  TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, 0);
}

Now here for CC2538 there no mutiple channels for single timer, there are only 4 Timers that can be used for PWM.

For this please let me know how do I do the configurations?

  • Couldn’t understand your question. Can you elaborate?
  • Dear Yikai,

    Sorry for the innconvienence.

    Actually I need to use PWM to control RGB LED's using Hue Sat. So initially I was using CC2530 for which there was ready code from ZLL that used to work directly.

    But now we to do the same thing using CC2538, so can you help me with PWM configuration here.

    I have done the configuration as said by you in the above thread that I have mentioned, but the configuration does not work.

  • The code are tested by myself and Daniel too. Do you check your HW first?
  • Dear Yikai,

    I have configured the PWM this way can you please verify this and the timer files are also attached here.

    In hal_board_cfg.h I have added following code:

    #if HAL_PWM

    #define WHITE_LED       HAL_T1_CH0
    #define RED_LED         HAL_T1_CH1
    #define BLUE_LED        HAL_T1_CH2
    #define GREEN_LED       HAL_T1_CH3

    #define PWM_LED_BASE                GPIO_A_BASE
    #define PWM_LED_1                   GPIO_PIN_0
    #define PWM_LED_2                   GPIO_PIN_1
    #define PWM_LED_3                   GPIO_PIN_2
    #define PWM_LED_4                   GPIO_PIN_3
    #define PWM_LED_ALL                 PWM_LED_1|PWM_LED_2|PWM_LED_3|PWM_LED_4

    //Enable LEDs: Enable PAD
    #define ENABLE_LAMP   IOCPadConfigSet(PWM_LED_BASE, PWM_LED_ALL, IOC_OVERRIDE_OE);
    //Disable LEDs: Disable PAD
    #define DISABLE_LAMP  IOCPadConfigSet(PWM_LED_BASE, PWM_LED_ALL, IOC_OVERRIDE_DIS);

    #define INIT_PWM_PINS()                                                     \
    {                                                                           \
        /* LEDs (off, output low) */                                            \
        GPIOPinTypeGPIOOutput(PWM_LED_BASE, PWM_LED_ALL);                       \
        GPIOPinWrite(PWM_LED_BASE, PWM_LED_ALL, 0);                             \
                                                                                \
        /* Configure LED pins to be controlled from PWM timer */                \
        GPIODirModeSet(PWM_LED_BASE, PWM_LED_ALL, GPIO_DIR_MODE_HW);            \
        IOCPadConfigSet(PWM_LED_BASE, PWM_LED_ALL, IOC_OVERRIDE_OE);            \
                                                                                \
        /* Hook up GPIO pins to internal timer signal Timer0A */                \
        IOCPinConfigPeriphOutput(PWM_LED_BASE, PWM_LED_ALL,                     \
                                 IOC_MUX_OUT_SEL_GPT0_ICP1);                    \
    }
    #else
    #define INIT_PWM_PINS()
    #endif

     

    And in zcl_app_init.c I have initialized it and I am checking for Timer output on Scope by setting breakpoints:


    HalTimer1Init(0);

      halTimer1SetChannelDuty( WHITE_LED, 0 );
      halTimer1SetChannelDuty( RED_LED, 0 );
      halTimer1SetChannelDuty( BLUE_LED, 0 );
      halTimer1SetChannelDuty( GREEN_LED, 0 );


      halTimer1SetChannelDuty( WHITE_LED, 100);
      halTimer1SetChannelDuty( RED_LED,
    100);
      halTimer1SetChannelDuty( BLUE_LED,
    100);
      halTimer1SetChannelDuty( GREEN_LED,
    100);

     

    7367.hal_timer.h

     

    /**************************************************************************************************
      Filename:       hal_timer.c
      Revised:        $Date: 2014-12-05 13:20:43 -0800 (Fri, 05 Dec 2014) $
      Revision:       $Revision: 41366 $
    
      Description:   This file contains the interface to the Timer Service.
    
    
      Copyright 2014 Texas Instruments Incorporated. All rights reserved.
    
      IMPORTANT: Your use of this Software is limited to those specific rights
      granted under the terms of a software license agreement between the user
      who downloaded the software, his/her employer (which must be your employer)
      and Texas Instruments Incorporated (the "License"). You may not use this
      Software unless you agree to abide by the terms of the License. The License
      limits your use, and you acknowledge, that the Software may not be modified,
      copied or distributed unless embedded on a Texas Instruments microcontroller
      or used solely and exclusively in conjunction with a Texas Instruments radio
      frequency transceiver, which is integrated into your product. Other than for
      the foregoing purpose, you may not use, reproduce, copy, prepare derivative
      works of, modify, distribute, perform, display or sell this Software and/or
      its documentation for any purpose.
    
      YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
      PROVIDED �AS IS� WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
      INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
      NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
      TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
      NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
      LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
      INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
      OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
      OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
      (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
    
      Should you have any questions regarding your right to use this Software,
      contact Texas Instruments Incorporated at www.TI.com.
    **************************************************************************************************/
    /*********************************************************************
     NOTE: The following mapping is done between the logical timer
           names defined in HAL_TIMER.H and the physical HW timer.
    
           HAL_TIMER_0 --> HW Timer 3  (8-bits)
           HAL_TIMER_2 --> HW Timer 4  (8-bits)
           HAL_TIMER_3 --> HW Timer 1  (16-bits)
    
     NOTE: The timer code assumes only one channel, CHANNEL 0, is used
           for each timer.  There is currently no support for other
           channels.
    
     NOTE: Only Output Compare Mode is supported.  There is no provision
           to support Input Capture Mode.
    
     NOTE: There is no support to map the output of the timers to a
           physical I/O pin
    
    *********************************************************************/
    /*********************************************************************
     * INCLUDES
     */
    #include  "hal_mcu.h"
    #include  "hal_defs.h"
    #include  "hal_types.h"
    #include  "hal_timer.h"
    
    #include "hw_ints.h"
    #include "hw_memmap.h"
    #include "gpio.h"
    #include "interrupt.h"
    #include "ioc.h"
    #include "hw_ioc.h"
    #include "sys_ctrl.h"
    #include "gptimer.h"
    
    /*********************************************************************
     * MACROS
     */
    
    /*********************************************************************
     * CONSTANTS
     */
    #define PWM_PERIOD 1000
    
    /*********************************************************************
     * FUNCTIONS - External
     */
    
    /*********************************************************************
     * FUNCTIONS - Local
     */
    uint8 halTimer1SetPeriod (uint32 timePerTick);
    void halTimer1SetChannelCount (uint8 channel, uint16 count);
    uint8 halTimerSetCount (uint8 hwtimerid, uint32 timePerTick);
    
    /*********************************************************************
     * FUNCTIONS - API
     */
    
    /*********************************************************************
     * @fn      HalTimer1Init
     *
     * @brief   Initialize Timer Service
     *
     * @param   None
     *
     * @return  None
     */
    void HalTimer1Init (halTimerCBack_t cBack)
    {
      //not used for now
      (void) cBack;
    
      //
      // Enable GPT0
      //
      SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);
    
      //
      // Configure Timer0A for PWM use
      //
      TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
                     GPTIMER_CFG_A_PWM);
    
      //
      // Set Duty cycle and enable
      //
      TimerLoadSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
      TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
      TimerEnable(GPTIMER0_BASE, GPTIMER_A);
    
      //
      // Set duty cycle to 0
      //
      TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, 0);
    }
    
    /***************************************************************************************************
     * @fn      halTimer1SetPeriod
     *
     * @brief   Set period for Timer1 PWM
     *
     * @param   timerPerTick - Number micro sec per ticks
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    uint8 halTimer1SetPeriod (uint32 timePerTick)
    {
      //Stub for now, only PWM implemented, with hard coded PWM period
      return 0;
    }
    
    /***************************************************************************************************
     * @fn      halTimer1SetChannelDuty
     *
     * @brief   Set duty for Timer1 PWM
     *
     * @param   channel - timer channel to control
     *          percent - dutycycle in promill
     *
     * @return  None
     ***************************************************************************************************/
    void halTimer1SetChannelDuty (uint8 channel, uint16 promill)
    {
      if(channel == 0)
      {
        uint32 timerAMatch = (PWM_PERIOD * (100-promill)) / 100;
    
        if(timerAMatch == PWM_PERIOD)
        {
          timerAMatch--;
        }
    
        //
        // The PWM counter counts down thus calculate actual match count based
        // on duty cycle as: period*(100-DucyCycle)/100
        //
        TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, timerAMatch);
      }
      else if(channel == 1)
      {
        uint32 timerAMatch = (PWM_PERIOD * (100-promill)) / 100;
    
        if(timerAMatch == PWM_PERIOD)
        {
          timerAMatch--;
        }
    
        //
        // The PWM counter counts down thus calculate actual match count based
        // on duty cycle as: period*(100-DucyCycle)/100
        //
        TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, timerAMatch);
      }
      else if(channel == 2)
      {
        uint32 timerAMatch = (PWM_PERIOD * (100-promill)) / 100;
    
        if(timerAMatch == PWM_PERIOD)
        {
          timerAMatch--;
        }
    
        //
        // The PWM counter counts down thus calculate actual match count based
        // on duty cycle as: period*(100-DucyCycle)/100
        //
        TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, timerAMatch);
      }
    
    }
    
    /***************************************************************************************************
     * @fn      halTimer1SetChannelCount
     *
     * @brief   Stop the Timer Service
     *
     * @param   hwtimerid - ID of the timer
     *          timerPerTick - Number micro sec per ticks
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    void halTimer1SetChannelCount (uint8 channel, uint16 count)
    {
      //Stub for now, only PWM implemented
    }
    
    /***************************************************************************************************
     * @fn      HalTimerInit
     *
     * @brief   Initialize Timer Service
     *
     * @param   None
     *
     * @return  None
     ***************************************************************************************************/
    void HalTimerInit (void)
    {
      //Stub for now, only PWM implemented
      return;
    }
    
    /***************************************************************************************************
     * @fn      HalTimerConfig
     *
     * @brief   Configure the Timer Serivce
     *
     * @param   timerId - Id of the timer
     *          opMode  - Operation mode
     *          channel - Channel where the counter operates on
     *          channelMode - Mode of that channel
     *          prescale - Prescale of the clock
     *          cBack - Pointer to the callback function
     *
     * @return  Status of the configuration
     ***************************************************************************************************/
    uint8 HalTimerConfig (uint8 timerId, uint8 opMode, uint8 channel, uint8 channelMode,
                          bool intEnable, halTimerCBack_t cBack)
    {
      //Stub for now, only PWM implemented
      return 0;
    }
    
    /***************************************************************************************************
     * @fn      HalTimerStart
     *
     * @brief   Start the Timer Service
     *
     * @param   timerId      - ID of the timer
     *          timerPerTick - number of micro sec per tick, (ticks x prescale) / clock = usec/tick
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    uint8 HalTimerStart (uint8 timerId, uint32 timePerTick)
    {
      //Stub for now, only PWM implemented
      return 0;
    }
    
    /***************************************************************************************************
     * @fn      HalTimerTick
     *
     * @brief   Check the counter for expired counter.
     *
     * @param   None
     *
     * @return  None
     ***************************************************************************************************/
    void HalTimerTick (void)
    {
      //Stub for now, only PWM implemented
    }
    
    /***************************************************************************************************
     * @fn      HalTimerStop
     *
     * @brief   Stop the Timer Service
     *
     * @param   timerId - ID of the timer
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    uint8 HalTimerStop (uint8 timerId)
    {
      //Stub for now, only PWM implemented
      return 0;
    }
    
    /***************************************************************************************************
     * @fn      halTimerSetCount
     *
     * @brief   Stop the Timer Service
     *
     * @param   hwtimerid - ID of the timer
     *          timerPerTick - Number micro sec per ticks
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    uint8 halTimerSetCount (uint8 hwtimerid, uint32 timePerTick)
    {
      //Stub for now, only PWM implemented
      return 0;
    }
    
    /***************************************************************************************************
     * @fn      HalTimerInterruptEnable
     *
     * @brief   Setup operate modes
     *
     * @param   hwtimerid - ID of the timer
     *          channelMode - channel mode
     *          enable - TRUE or FALSE
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    uint8 HalTimerInterruptEnable (uint8 hwtimerid, uint8 channelMode, bool enable)
    {
      //Stub for now, only PWM implemented
      return 0;
    }
    
    /***************************************************************************************************
    ***************************************************************************************************/
    

     


    Can you please let me know if this is right?

  • I test my codes on CC2538DK again and it works fine.
  • Dear Yikai,

    Thank you for the reply.

    I am also using CC2538DK, here the timer.c and timer.h is fine, right?

    Also which PINS have you configured? is there any specific pins that I should use for PWM timer? or any PIN's can configured for it?
  • I don't change anything on timer.c and timer.h. The followings are my pin defines which is the same in the link you point out.

    #define PWM_LED_1 GPIO_PIN_0
    #define PWM_LED_2 GPIO_PIN_1
    #define PWM_LED_3 GPIO_PIN_2
    #define PWM_LED_4 GPIO_PIN_3

    Do you define HAL_PWM in your project predefined symbols?
  • Dear Yikai,

    But your PWM_BASE is GPIO_B_BASE and I have configured its for A. Does this matter?

    Yes I have set HAL_PWM in predefined symbols.
  • My PWM_BASE is GPIO_C_BASE since CC2538DK use PC0,PC1, PC2, and PC3 as LED1, LED2, LED3, and , LED4. It should be fine to change to use GPIO_A_BASE. However, PA0, PA1,PA2, and PA3 are used as UART RX, UART TX, LV_SPI_SCK, and LC_BTN_SELECT. So, do you disable those peripherals and IOs when you test it with GPIO_A_BASE?
  • Dear Yikai,

    Yes I have disable it.

    Also in timer.c we have one timer set in init and set_timer functions, as shown below:

    void HalTimer1Init (halTimerCBack_t cBack)
    {
    //not used for now
    (void) cBack;

    //
    // Enable GPT0
    //
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);

    //
    // Configure Timer0A for PWM use
    //
    TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
    GPTIMER_CFG_A_PWM);

    //
    // Set Duty cycle and enable
    //
    TimerLoadSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
    TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
    TimerEnable(GPTIMER0_BASE, GPTIMER_A);

    //
    // Set duty cycle to 0
    //
    TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, 0);
    }

    void halTimer1SetChannelDuty (uint8 channel, uint16 promill)
    {
    if(channel == 0)
    {
    uint32 timerAMatch = (PWM_PERIOD * (100-promill)) / 100;

    if(timerAMatch == PWM_PERIOD)
    {
    timerAMatch--;
    }

    //
    // The PWM counter counts down thus calculate actual match count based
    // on duty cycle as: period*(100-DucyCycle)/100
    //
    TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, timerAMatch);
    }
    }
  • I test GPIO_A_BASE and PA6/PA7 as PWM output. It works fine.
  • Dear Yikai,

    OK Thanks. I will check that.

    But I have one more confusion that how do I assign different PWM Value to different channels because there ia only one channel in halTimer1SetChannelDuty function in timer.c

    Will I have to configure different timers for different PWM?
  • API halTimer1SetChannelDuty can set different duty to different channel.
  • Dear Yikai,

    Ya, that's write but currently the function support only one channel as far as I can see.

    void halTimer1SetChannelDuty (uint8 channel, uint16 promill)
    {
    if(channel == HAL_T1_CH0)
    {
    uint32 timerAMatch = (PWM_PERIOD * (100-promill)) / 100;

    if(timerAMatch == PWM_PERIOD)
    {
    timerAMatch--;
    }

    //
    // The PWM counter counts down thus calculate actual match count based
    // on duty cycle as: period*(100-DucyCycle)/100
    //
    TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, timerAMatch);
    }
    }

    We will have to enable other channels in init and add further code here, right?
  • In my example code, I set them as different channels. Please refer to the following settings in hal_board_cfg.h

    #define WHITE_LED HAL_T1_CH0
    #define RED_LED HAL_T1_CH1
    #define BLUE_LED HAL_T1_CH2
    #define GREEN_LED HAL_T1_CH3
  • Dear Yikai,

    That is right but the function halTimer1SetChannelDuty does not have support for it.

    Can you please send me your hal_timer.c file for verifications
  • /**************************************************************************************************
      Filename:       hal_timer.c
      Revised:        $Date: 2014-12-05 13:20:43 -0800 (Fri, 05 Dec 2014) $
      Revision:       $Revision: 41366 $
    
      Description:   This file contains the interface to the Timer Service.
    
    
      Copyright 2014 Texas Instruments Incorporated. All rights reserved.
    
      IMPORTANT: Your use of this Software is limited to those specific rights
      granted under the terms of a software license agreement between the user
      who downloaded the software, his/her employer (which must be your employer)
      and Texas Instruments Incorporated (the "License"). You may not use this
      Software unless you agree to abide by the terms of the License. The License
      limits your use, and you acknowledge, that the Software may not be modified,
      copied or distributed unless embedded on a Texas Instruments microcontroller
      or used solely and exclusively in conjunction with a Texas Instruments radio
      frequency transceiver, which is integrated into your product. Other than for
      the foregoing purpose, you may not use, reproduce, copy, prepare derivative
      works of, modify, distribute, perform, display or sell this Software and/or
      its documentation for any purpose.
    
      YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
      PROVIDED �AS IS� WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
      INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
      NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
      TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
      NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
      LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
      INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
      OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
      OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
      (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
    
      Should you have any questions regarding your right to use this Software,
      contact Texas Instruments Incorporated at www.TI.com.
    **************************************************************************************************/
    /*********************************************************************
     NOTE: The following mapping is done between the logical timer
           names defined in HAL_TIMER.H and the physical HW timer.
    
           HAL_TIMER_0 --> HW Timer 3  (8-bits)
           HAL_TIMER_2 --> HW Timer 4  (8-bits)
           HAL_TIMER_3 --> HW Timer 1  (16-bits)
    
     NOTE: The timer code assumes only one channel, CHANNEL 0, is used
           for each timer.  There is currently no support for other
           channels.
    
     NOTE: Only Output Compare Mode is supported.  There is no provision
           to support Input Capture Mode.
    
     NOTE: There is no support to map the output of the timers to a
           physical I/O pin
    
    *********************************************************************/
    /*********************************************************************
     * INCLUDES
     */
    #include  "hal_mcu.h"
    #include  "hal_defs.h"
    #include  "hal_types.h"
    #include  "hal_timer.h"
    
    #include "hw_ints.h"
    #include "hw_memmap.h"
    #include "gpio.h"
    #include "interrupt.h"
    #include "ioc.h"
    #include "hw_ioc.h"
    #include "sys_ctrl.h"
    #include "gptimer.h"
    
    /*********************************************************************
     * MACROS
     */
    
    /*********************************************************************
     * CONSTANTS
     */
    #define PWM_PERIOD 1000
    
    /*********************************************************************
     * FUNCTIONS - External
     */
    
    /*********************************************************************
     * FUNCTIONS - Local
     */
    uint8 halTimer1SetPeriod (uint32 timePerTick);
    void halTimer1SetChannelCount (uint8 channel, uint16 count);
    uint8 halTimerSetCount (uint8 hwtimerid, uint32 timePerTick);
    
    /*********************************************************************
     * FUNCTIONS - API
     */
    
    /*********************************************************************
     * @fn      HalTimer1Init
     *
     * @brief   Initialize Timer Service
     *
     * @param   None
     *
     * @return  None
     */
    void HalTimer1Init (halTimerCBack_t cBack)
    {
      //not used for now
      (void) cBack;
    
      //
      // Enable GPT0
      //  
      SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);
        
      //
      // Configure Timer0A for PWM use
      //
      TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
                     GPTIMER_CFG_A_PWM);
    
      //
      // Set Duty cycle and enable
      //
      TimerLoadSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
      TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
      TimerEnable(GPTIMER0_BASE, GPTIMER_A);
    
      //
      // Set duty cycle to 0
      //
      TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, 0); 
    }
    
    /***************************************************************************************************
     * @fn      halTimer1SetPeriod
     *
     * @brief   Set period for Timer1 PWM
     *
     * @param   timerPerTick - Number micro sec per ticks
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    uint8 halTimer1SetPeriod (uint32 timePerTick)
    {
      //Stub for now, only PWM implemented, with hard coded PWM period
      return 0;
    }
    
    /***************************************************************************************************
     * @fn      halTimer1SetChannelDuty
     *
     * @brief   Set duty for Timer1 PWM
     *
     * @param   channel - timer channel to control
     *          percent - dutycycle in promill
     *
     * @return  None
     ***************************************************************************************************/
    void halTimer1SetChannelDuty (uint8 channel, uint16 promill)
    {
      if(channel == 0)
      {
        uint32 timerAMatch = (PWM_PERIOD * (100-promill)) / 100;
        
        if(timerAMatch == PWM_PERIOD)
        {
          timerAMatch--;
        }
        
        //
        // The PWM counter counts down thus calculate actual match count based
        // on duty cycle as: period*(100-DucyCycle)/100
        //
        TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, timerAMatch); 
      }
    }
    
    /***************************************************************************************************
     * @fn      halTimer1SetChannelCount
     *
     * @brief   Stop the Timer Service
     *
     * @param   hwtimerid - ID of the timer
     *          timerPerTick - Number micro sec per ticks
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    void halTimer1SetChannelCount (uint8 channel, uint16 count)
    {
      //Stub for now, only PWM implemented
    }
    
    /***************************************************************************************************
     * @fn      HalTimerInit
     *
     * @brief   Initialize Timer Service
     *
     * @param   None
     *
     * @return  None
     ***************************************************************************************************/
    void HalTimerInit (void)
    {
      //Stub for now, only PWM implemented
      return;
    }
    
    /***************************************************************************************************
     * @fn      HalTimerConfig
     *
     * @brief   Configure the Timer Serivce
     *
     * @param   timerId - Id of the timer
     *          opMode  - Operation mode
     *          channel - Channel where the counter operates on
     *          channelMode - Mode of that channel
     *          prescale - Prescale of the clock
     *          cBack - Pointer to the callback function
     *
     * @return  Status of the configuration
     ***************************************************************************************************/
    uint8 HalTimerConfig (uint8 timerId, uint8 opMode, uint8 channel, uint8 channelMode,
                          bool intEnable, halTimerCBack_t cBack)
    {
      //Stub for now, only PWM implemented
      return 0;
    }
    
    /***************************************************************************************************
     * @fn      HalTimerStart
     *
     * @brief   Start the Timer Service
     *
     * @param   timerId      - ID of the timer
     *          timerPerTick - number of micro sec per tick, (ticks x prescale) / clock = usec/tick
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    uint8 HalTimerStart (uint8 timerId, uint32 timePerTick)
    {
      //Stub for now, only PWM implemented
      return 0;
    }
    
    /***************************************************************************************************
     * @fn      HalTimerTick
     *
     * @brief   Check the counter for expired counter.
     *
     * @param   None
     *
     * @return  None
     ***************************************************************************************************/
    void HalTimerTick (void)
    {
      //Stub for now, only PWM implemented
    }
    
    /***************************************************************************************************
     * @fn      HalTimerStop
     *
     * @brief   Stop the Timer Service
     *
     * @param   timerId - ID of the timer
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    uint8 HalTimerStop (uint8 timerId)
    {
      //Stub for now, only PWM implemented
      return 0;
    }
    
    /***************************************************************************************************
     * @fn      halTimerSetCount
     *
     * @brief   Stop the Timer Service
     *
     * @param   hwtimerid - ID of the timer
     *          timerPerTick - Number micro sec per ticks
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    uint8 halTimerSetCount (uint8 hwtimerid, uint32 timePerTick)
    {
      //Stub for now, only PWM implemented
      return 0;
    }
    
    /***************************************************************************************************
     * @fn      HalTimerInterruptEnable
     *
     * @brief   Setup operate modes
     *
     * @param   hwtimerid - ID of the timer
     *          channelMode - channel mode
     *          enable - TRUE or FALSE
     *
     * @return  Status - OK or Not OK
     ***************************************************************************************************/
    uint8 HalTimerInterruptEnable (uint8 hwtimerid, uint8 channelMode, bool enable)
    {
      //Stub for now, only PWM implemented
      return 0;
    }
    
    /***************************************************************************************************
    ***************************************************************************************************/
    

  • Dear Yikai,

    As per the timer file you have sent me, there is configuration done only for channel and rest channel wont work as there is no code for it.

    Can you please verify this?
  • OK, I suppose you can clone code section of channel==0 to 1, 2, and 3, and let them mapping to GPTIMER1_BASE, GPTIMER2_BASE, and GPTIMER3_BASE using TimerMatchSet.
  • Dear Yikai,

    Thank You. I will look into it and get back to you if there is any problem.