• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Low Power RF & Wireless Connectivity » Low Power RF ZigBee® Software & IEEE 802.15.4 Forum » How to set timer 3 cc2530 TIMAC
Share
Low Power RF & Wireless Connectivity
  • Forums
  • Announcements
  • Files
  • E2E Wiki
Options
  • Subscribe via RSS

How to set timer 3 cc2530 TIMAC

How to set timer 3 cc2530 TIMAC

This question is not answered
edgar rodriguez
Posted by edgar rodriguez
on Aug 14 2012 17:55 PM
Prodigy50 points

Hi, 

     I have tried to set the timer 3, and I don't know what i am missing. I need to do an interrupt every 5 ms. If anyone can help me would appreciate it. My code is the following:

      PERCFG  = 0xC0;

      P2SEL |= 0x20;

      P1SEL = 0x18;

      P1DIR |= 0x18;

      T3CTL = 0x1A;

      T3CCTLO = 0x64;

      T3CC0 = 0x0A;

I focused first on the configuration of timer 3 is something that so far I have not set. Thanks for your help.

2.4GHz
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • greenja
    Posted by greenja
    on Aug 15 2012 18:45 PM
    Guru12100 points

    Here is the configuration of Timer 3 without interrupt on P1_7, taken from the Buzzer.c example.

    For interrupt, toggle the interrupt bit.

    void PWM_Init(void)
    {
        // PWM connected at P1_7
        // We will use Timer 3 Channel 1 at alternate location 2
        // Channel 1 will toggle on compare with 1 and counter will
        // count in up/down mode to T3CC1.

        PERCFG |= 0x20;             // Timer 3 Alternate location 2
        P1DIR |= 0x80;              // P1_7 = output
        P1SEL |= 0x80;              // Peripheral function on P1_7

        T3CTL &= ~0x10;             // Stop timer 3 (if it was running)
        T3CTL |= 0x04;              // Clear timer 3
        T3CTL &= ~0x08;             // Disable Timer 3 overflow interrupts
        T3CTL |= 0x03;              // Timer 3 mode = 3 - Up/Down

        T3CCTL1 &= ~0x40;           // Disable channel 0 interrupts
        T3CCTL1 |= 0x04;            // Ch0 mode = compare
        T3CCTL1 |= 0x10;            // Ch0 output compare mode = toggle on compare

    }

    The next part sets the frequency.

    /** \brief    Starts PWM
    *
    * Starts the PWM with given frequency
    *
    * \param[in]       frequency
    *     The frequency in Hertz to output
    * @return  1 successful - 0 if frequency invalid
    */
    uint8 PWM_Frequency(uint16 frequency)
    {
       uint8 prescaler = 0;

        // Get current Timer tick divisor setting
        uint8 tickSpdDiv = (CLKCONSTA & 0x38)>>3;

        // Check if frequency too low
    //    if (frequency < (244 >> tickSpdDiv)){   // 244 Hz = 32MHz / 256 (8bit counter) / 4 (up/down counter and toggle on compare) / 128 (max timer prescaler)
    //        return 0;
    //    }

        // Calculate nr of ticks required to achieve target frequency
        uint32 ticks = (8000000/frequency) >> tickSpdDiv;      // 8000000 = 32M / 4;

        // Fit this into an 8bit counter using the timer prescaler
        while ((ticks & 0xFFFFFF00) != 0)
        {
            ticks >>= 1;
            prescaler += 32;
        }

        // Update registers
        T3CTL &= ~0xE0;
        T3CTL |= prescaler;
        T3CC0 = (uint8)ticks;

        // Start timer
        T3CTL |= 0x10;
    //#endif

        return 1;
    }

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • liangliang lou
    Posted by liangliang lou
    on Aug 17 2012 03:48 AM
    Expert1870 points

    hi

       i use your code to verify on CC2530,but no signal output on P1.7 port,how is this going?my code is as follows

    void PWM_Init(void)
    {
    // PWM connected at P1_7
    // We will use Timer 3 Channel 1 at alternate location 2
    // Channel 1 will toggle on compare with 1 and counter will
    // count in up/down mode to T3CC1.

    PERCFG |= 0x20; // Timer 3 Alternate location 2
    P1DIR |= 0x80; // P1_7 = output
    P1SEL |= 0x80; // Peripheral function on P1_7

    T3CTL &= ~0x10; // Stop timer 3 (if it was running)
    T3CTL |= 0x04; // Clear timer 3
    T3CTL &= ~0x08; // Disable Timer 3 overflow interrupts
    T3CTL |= 0x03; // Timer 3 mode = 3 - Up/Down

    T3CCTL1 &= ~0x40; // Disable channel 0 interrupts
    T3CCTL1 |= 0x04; // Ch0 mode = compare
    T3CCTL1 |= 0x10; // Ch0 output compare mode = toggle on compare

    }

    //The next part sets the frequency.

    /** \brief Starts PWM
    *
    * Starts the PWM with given frequency
    *
    * \param[in] frequency
    * The frequency in Hertz to output
    * @return 1 successful - 0 if frequency invalid
    */
    uint8 PWM_Frequency(uint16 frequency)
    {
    uint8 prescaler = 0;

    // Get current Timer tick divisor setting
    uint8 tickSpdDiv = (CLKCONSTA & 0x38)>>3;

    // Check if frequency too low
    // if (frequency < (244 >> tickSpdDiv)){ // 244 Hz = 32MHz / 256 (8bit counter) / 4 (up/down counter and toggle on compare) / 128 (max timer prescaler)
    // return 0;
    // }

    // Calculate nr of ticks required to achieve target frequency
    uint32 ticks = (8000000/frequency) >> tickSpdDiv; // 8000000 = 32M / 4;

    // Fit this into an 8bit counter using the timer prescaler
    while ((ticks & 0xFFFFFF00) != 0)
    {
    ticks >>= 1;
    prescaler += 32;
    }

    // Update registers
    T3CTL &= ~0xE0;
    T3CTL |= prescaler;
    T3CC0 = (uint8)ticks;

    // Start timer
    T3CTL |= 0x10;
    //#endif

    return 1;
    }


    void main(void)
    {
    int16 i;

    SLEEPCMD &= ~OSC_PD;
    while (!(SLEEPSTA & XOSC_STB));
    asm("NOP");
    for (i=0; i<504; i++) asm("NOP");
    CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ);
    while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ));
    SLEEPCMD |= OSC_PD;

    PWM_Init();
    PWM_Frequency(2000);

    while(1);
    }

    where can i get the file of Buzzer.c? thank you for your help

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • greenja
    Posted by greenja
    on Aug 17 2012 05:55 AM
    Guru12100 points

    Hello,

    I may have made a mistake.  The buzzer.c is for the CC2540.  The way the chips implement the timers should be identical though, especially if you are not using ZStack.

    I have attached the original files from the CC2540 BLE Stack that uses P1_6. Just remove the #ifdefine and #endif.

    If this doesn't work then there are differences in the CC2540 and CC2530 Timers that I am unaware of.

    2438.Buzzer.zip

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • edgar rodriguez
    Posted by edgar rodriguez
    on Aug 17 2012 08:28 AM
    Prodigy50 points

    Hi greenja, first of all thanks for your answer. I used your code and it did not work. But I know that there must be the answer so thanks.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • greenja
    Posted by greenja
    on Aug 17 2012 14:57 PM
    Guru12100 points

    Well that is very strange?!

    Did you use the files from the attached zip file for Buzzer.c and that didn't give you a PWM on the P1_6?  Are you looking at it with an oscilloscope or with your Multimeter set to Hz?

    Try different values for frequency.  Are you sure you are testing the right pin (lol)?  Check all the pins to see.  If you are have an LED connected to it, the frequency has to be below lower than 20 Hz to really see it flicker.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • edgar rodriguez
    Posted by edgar rodriguez
    on Aug 17 2012 15:58 PM
    Prodigy50 points

    Hi,

        I'm using an oscilloscope and I have tried with diferent pin. The P1_6 on SMARTRF05EB is the 18 port in pin 18. and I don't get a positive result. I'll try to change the frecuency.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • kidd dexter
    Posted by kidd dexter
    on Sep 05 2012 09:57 AM
    Prodigy215 points

    Hi greenja

    I used your code

    And I want to change the duty cycle

    so I changed Timer 3 to free run mode

    void buzzerInit(void)
    {

    PERCFG |= 0x20; // Timer 3 Alternate location 2
    P1DIR |= 0x40; // P1_6 = output
    P1SEL |= 0x40; // Peripheral function on P1_6

    T3CTL &= ~0x10; // Stop timer 3 (if it was running)
    T3CTL |= 0x04; // Clear timer 3
    T3CTL &= ~0x08; // Disable Timer 3 overflow interrupts
    T3CTL |= 0x00; // Timer 3 mode = 3 - Free mode

    T3CCTL0 &= ~0x40; // Disable channel 0 interrupts
    T3CCTL0 |= 0x04; // Ch0 mode = compare
    T3CCTL0 |= 0x20; // Ch0 output compare mode
    // T3CCTL0 |= 0x24;


    //#endif
    }

    And Now I do can change the duty cycle by set T3CC0 in  buzzerStart

    // Update registers
    T3CTL &= ~0xE0;
    T3CTL |= 224;

    T3CC0 = 10;

    But  in this time

    I can not control the frequency

    I set frequency to 400

    but my oscilloscope shows 977 hz

    I do everything to change the frequency,but it did not work

    Is this because of the free-running mode?

    in the mean time

    I could not find a way to change duty cycle in up/down mode

    Could you give me a little hit about my problem?

    I want fixed frequency and free-change duty cycle, is this possible?

    Thanks

    timer cc2530 frequency
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

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 Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve 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.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use