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.

RTOS: CC2630 PWM Sample for Zigbee

Other Parts Discussed in Thread: CC2630, Z-STACK, CC2530, CC2652R, SYSBIOS

Tool/software: TI-RTOS

I use Zigbee HA sample code, now i want to create pulse for buzzer, i search across the forum, found sample using PWM driver for CC26xx, but it all for Bluetooth stack not for zigbee.

I try to adapt it but is all wrong path for header file like GPTimerCC26XX.h. Anyone can provide me an sample?

  • You can refer to svendbt’s example code in e2e.ti.com/.../1435673
  • Thank you.
    It can work now, but i don't know those use hardware or software to generate the pulse? Because it cost 2.2ma with 5khz pulse with no output
  • It’s HW.
  • But do you know why it use so much power?

    I use 4 button, 2 led and 4 i/o for relay, with RF at 0dbm ti only 1.8 ma, but with only pwm it is more than. Is there any document about pwm power usage and optimize?

  • What’s your PWM output connected to?
  • I am only test frequency by connect to an Multi Meter (True RMS), if i disconnect to it, power usage still the same.
  • I suppose that’s the normal power consumption when output PWM signal.
  • 1.8ma with Zigbee(0 dbm) and all output, add 1 pwm it is 5ma, so only 1 channel pwm it is 2.2ma. It is still normal?
  • I am confused by your descriptions. Do you use scope or power Analyzer to measure power consumption in details?
  • This is not the expected results with a GPIO timer PWM output not connected to a load, it would appear that your PWM initialization is preventing the MCU from entering standby mode. You could confirm this by further debugging your code inside IAR.

    Regards,
    Ryan
  • /******************************************************************************
    
     @file  board_buzzer.c
    
     @brief PWM-based buzzer interface.
    
     Group: WCS, BTS
     Target Device: CC2650, CC2640, CC1350
    
     ******************************************************************************
     
     Copyright (c) 2016, Texas Instruments Incorporated
     All rights reserved.
    
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions
     are met:
    
     *  Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
    
     *  Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
    
     *  Neither the name of Texas Instruments Incorporated nor the names of
        its contributors may be used to endorse or promote products derived
        from this software without specific prior written permission.
    
     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
     ******************************************************************************
     Release Name: ble_sdk_2_02_01_18
     Release Date: 2016-10-26 15:20:04
    
     TI CC2640R2F Sensortag using TI CC2640R2F Launchpad + Educational BoosterPack MKII
    
     Maker/Author - Markel T. Robregado
    
     Modification Details : CC2640R2F Launchpad with SensorTag and Key Fob codes
                            ported from BLE Stack 2.2.1.
    
     Device Setup: TI CC2640R2F Launchpad + Educational BoosterPack MKII
     *****************************************************************************/
    
    #ifndef EXCLUDE_IO
    
    /* -----------------------------------------------------------------------------
    *  Includes
    * ------------------------------------------------------------------------------
    */
    
    // TI RTOS drivers
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/family/arm/cc26xx/Power.h>
    #include <ti/sysbios/family/arm/cc26xx/PowerCC2650.h>
    
    #include <ti/drivers/PIN/PINCC26XX.h>
    #include <driverLib/timer.h>
    
    
    #include "board_buzzer.h"
    
    /* -----------------------------------------------------------------------------
    *  Local variables
    * ------------------------------------------------------------------------------
    */
    static PIN_Handle hPin = NULL;
    /* BUZZER pin state */
    static PIN_State buzzerPinState;
    
    PIN_Config buzzerPinTable[] = { Board_BUZZER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MIN, //PIN_INV_INOUT, 
                                 PIN_TERMINATE };
    
    /* -----------------------------------------------------------------------------
    *  Public Functions
    * ------------------------------------------------------------------------------
    */
    
    /*******************************************************************************
     * @fn          SensorTagBuzzer_initialize
     *
     * @brief       Initialize the Buzzer
     *
     * @descr       Initializes pin
     *
     * @return      -
     */
    
    void SensorTagBuzzer_initialize(void){
      //RTOS: Open and assign pins through PIN driver
      hPin = PIN_open(&buzzerPinState, buzzerPinTable);
    }
    
    /*******************************************************************************
     * @fn          SensorTagBuzzer_open
     *
     * @brief       Initialize the Buzzer
     *
     * @descr       Initializes pin and PWM
     *
     * @return      -
     */
    void SensorTagBuzzer_open(void)
    {
        //hPin = hGpioPin;
    
        // Turn on PERIPH power domain and clock for GPT0 and GPIO
        Power_setDependency(PERIPH_GPT0);
        Power_setConstraint(Power_SB_DISALLOW);
    
        // Assign GPT0
        TimerConfigure(GPT0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
    
        // Configure pin for PWM output
    #ifdef Board_BUZZER
        PINCC26XX_setMux(hPin, Board_BUZZER, IOC_PORT_MCU_PORT_EVENT0);
    #endif
    }
    
    
    /*******************************************************************************
     * @fn          SensorTagBuzzer_setFrequency
     *
     * @brief       Set the frequency (3Hz - 8 KHz)
     *
     * @return      return true if the frequency is within range
     */
    bool SensorTagBuzzer_setFrequency(uint16_t freq)
    {
        uint32_t ticks;
        uint32_t loadLow;
        uint32_t loadHigh;
        uint32_t matchLow;
        uint32_t matchHigh;
    
        if (hPin == NULL)
        {
            // Make sure the pin is not used when not open
            return false;
        }
    
        if (freq < BUZZER_FREQ_MIN && freq > BUZZER_FREQ_MAX)
        {
            return false;
        }
    
        // Stop timer during reconfiguration
        TimerDisable(GPT0_BASE, TIMER_A);
    
        // Calculate timer load and match values
        ticks = 48000000 / freq;
        loadLow = ticks & 0x0000FFFF;
        loadHigh = (ticks & 0x00FF0000) >> 16;
        matchLow = (ticks / 2) & 0x0000FFFF;
        matchHigh = ((ticks / 2) & 0x00FF0000) >> 16;
    
        // Set timer load
        TimerLoadSet(GPT0_BASE, TIMER_A, loadLow);
        TimerPrescaleSet(GPT0_BASE, TIMER_A, loadHigh);
    
        // Set timer match
        TimerMatchSet(GPT0_BASE, TIMER_BOTH, matchLow);
        TimerPrescaleMatchSet(GPT0_BASE, TIMER_A, matchHigh);
    
        // Start timer
        TimerEnable(GPT0_BASE, TIMER_A);
    
        return true;
    }
    
    /*******************************************************************************
     * @fn          SensorTagBuzzer_close
     *
     * @brief       Closes the buzzer interface
     *
     * @return      -
     */
    void SensorTagBuzzer_close(void)
    {
        if (hPin != NULL)
        {
            // Configure pin as GPIO
    #ifdef Board_BUZZER
            PINCC26XX_setMux(hPin, Board_BUZZER, IOC_PORT_GPIO);
    #endif
            // Turn off PERIPH power domain and clock for GPT0
            Power_releaseDependency(PERIPH_GPT0);
            Power_releaseConstraint(Power_SB_DISALLOW);
    
            hPin = NULL;
        }
    }
    
    #endif // EXCLUDE_IO
    

    Yes, I do, I will post the code for you check. In the main program, sample switch switch.c i use those code to activate pwm:

        SensorTagBuzzer_initialize();
        SensorTagBuzzer_open();
        SensorTagBuzzer_setFrequency(5000);

  • The issue, as pointed out by svendbt in his example post, is that the lower layer drivers do not include any power management meaning that the devices must be active in order for the PWM timer to work. You need the GPTimer driver but this is not compiled with the released Z-Stack 1.2.2a which has TI-RTOS v2.11 for the CC2630. You can read this other post by svendbt to learn more: e2e.ti.com/.../474000

    There are no plans to update the Z-Stack release for CC2630 devices so you might consider migrating to a different part, either the CC2530 for Z-Stack HA1.2.2a/3.0.1 or CC2652R for Z-Stack 3.1.0.

    Regards,
    Ryan
  • I check svendbt lib here e2e.ti.com/.../474000 i try it but not work, the pwm not produce. I have bought many cc2630 chip for the product, i could not change to cc2530 (hungry power) or cc2652R2 (not release) for now, may be with next revision of the hardware, I must make it work with some way.

  • I already stated that svendbt's library will not work as it is only compatible with TI-RTOS v2.13 or later. Power mode 2 (standby) is the exact same for both the CC2530/CC2630, which is the state your sleepy ZED should be in most of the time.  However, I do not know enough about your application to further comment on the matter.  You would have to upgrade the TI-RTOS version of the Z-Stack 1.2.2a release, we can discuss your options outside of the public forum.

    Regards,
    Ryan

  • Thank you, but how i can discuss with you about the update TI-RTOS? I want to user GPTimer driver too.
  • Thank you, it all up and running now.
  • Tool/software: TI-RTOS

    I have problem with Zigbee HA 1.2 and cc2630, with all the support and solution provide by Ryan Brown1 I could use GPTimer driver from newer version TO RTOS, but it not stable.

    I take 2 days but not solve the problem.

    So i will back to original TI RTOS, now my main purpose is accurate microseconds timer (10us) like in  GPTimer but for TI RTOS 2.11.

    I have try Task_sleep() but it not accurate and make zigbee connection drop.

  • We've been over this externally. You have the OSAL_Timers from Z-StackCore/OSAL and basic Clock libraries from the SYS/BIOS kernel (ti/sysbios/knl). Please look through the TI-RTOS APIs or reference the existing Zigbee examples like sensortag.

    Regards,
    Ryan