• 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 » Microcontrollers » MSP430™ Microcontrollers » MSP430 Ultra-Low Power 16-bit Microcontroller Forum » use Touch and PWM together
Share
MSP430™ Microcontrollers
  • Forum
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
MSP430 Resources
  • MSP430 Product Folder
  • MSP-EXP430G2 - MSP430 LaunchPad Value Line Development kit
  • MSP430 Getting Started Guide
  • MSP430 Microcontroller Projects
  • More Resources >
  • Forums

    use Touch and PWM together

    This question has suggested answer(s)
    Frank Boehme
    Posted by Frank Boehme
    on Apr 30 2012 05:22 AM
    Prodigy40 points

    Hello,

    I'm new on the MSP430 family and started to play around with the Launchpad and the Cap.-Touch Boosterback. I quickly changed to my own touch board since I need a functionality which I cannot get with the Boosterpack. And here is my problem:

    Configuration:

    MSP430G2553

    P2.0 Sensor left

    P2.2 to P2.5 Sensor down, right, up, middle

    Feedback LEDs on P1.0, P1.3, P1.4, P1.5, P1.6

    PWM out on P2.1 for TIMER_A1

    Touch alone: works fine

    PWM alone: works fine

    Touch and PWM together: sucks, the PWM LED flickers

    My idea was to use the TIMER_A1 for PWM because the TIMER_A0 is used for TouchSense. But it seems that there is a problem which causes the TIMER_A1 to stutter.

    Any ideas (I did'nt find anything using search)? I can provide the code if necessary.

    Frank

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Apr 30 2012 12:05 PM
      Guru141810 points

      Frank Boehme
      But it seems that there is a problem which causes the TIMER_A1 to stutter.

      Apparently. And since the two work independently, the mos tlikely cause is the way you implemented your ISRs or the control of the PWM.

      You should post your code, as there is no known 'TimerA1 PWM fails if TimerA0 is used for TouchSense" hardware bug.

      However, I have a guess. Maybe you confused the two timers with the two vectors for each timer.

      TIMER0_A0_VECTOR and TIMER0_A1_VECTOR (or their aliases TIMER_Ax_VECTOR) belong both to Timer0.
      Timer1 has the vectors TIMER1_A0_VECTOR and TIMER1_A1_VECTOR.

      You really should post your code.

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Frank Boehme
      Posted by Frank Boehme
      on May 01 2012 14:05 PM
      Prodigy40 points

      Hello,

      This is the Code. I stripped it down to the essentials. It is a standard CCS 5 project for the MSP430G2553. All of "my" Code is in main.c. I use the standard files

      CTS_HAL.c
      CTS_HAL.h
      CTS_Layer.c
      CTS_Layer.h

      from slac489.zip and the mode "RO_PINOSC_TA0_WDTp" with the files structure.c and structure.h from "RO_PINOSC_TA0_WDTp_One_Button" example without modifications.

      Comment the line: FeedbackLED(one_button, BIT0, 0); to run only the PWM and it works fine

      Comment the line: Timer1_A3_init(); to run only the touch and it works fine

      Use both lines and the PWM LED stutters

      //******************************************************************************
      //          Schematic Description: 
      // 
      //                         MSP430G2452
      //                      +---------------+
      //                      |
      //           OUT--------|P1.0 (Feedback LED)
      //         PWM----------|P2.1 (LED)
      //               C------|P2.5 (Touch)
      // 
      //******************************************************************************
      #include "CTS_Layer.h"
      
      // Uncomment to have this compiler directive run characterization functions only
      // Comment to have this compiler directive run example application
      //#define ELEMENT_CHARACTERIZATION_MODE
      
      #ifdef ELEMENT_CHARACTERIZATION_MODE
      // Delta Counts returned from the API function for the sensor during characterization
      unsigned int dCnt;
      #endif
      
      int up = 1;
      int disable = 0;
      
      /*
       *  ======== Timer1_A3_init ========
       *  Initialize MSP430 Timer1_A3 timer
       *  Conf. made with GRACE, Comments removed
       */
      void Timer1_A3_init(void)
      {
          TA1CCTL0 = CM_0 + CCIS_0 + OUTMOD_0; // + CCIE;
          TA1CCTL1 = CM_0 + CCIS_0 + OUTMOD_7;// + CCIE;
          TA1CCR0 = 9999;
          TA1CCR1 = 500;
          TA1CTL = TASSEL_2 + ID_0 + MC_1;
      }
      
      //Feedback LED anschalten
      void FeedbackLED(const struct Sensor Sens, int Pin, int disable)
      {
      	if(disable == 0)
      	{
      		if(TI_CAPT_Button(&Sens))
      			P1OUT |= Pin;                            // Turn on  LED
      		else
      			P1OUT &= ~Pin;
      	}
      	else
      		P1OUT &= ~Pin;
      }
      
      // Main Function
      void main(void)
      { 
      
        // Initialize System Clocks
        WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
        BCSCTL1 = CALBC1_1MHZ;                // Set DCO to 1, 8, 12 or 16MHz
        DCOCTL = CALDCO_1MHZ;
        BCSCTL3 |= LFXT1S_2;                  // LFXT1 = VLO
        
        P1OUT = 0x00;							// Clear Port 1 bits
        P1SEL = BIT6;
        P1DIR |= BIT0 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;						// Set output pins
      
        P2SEL &= ~(BIT6 + BIT7);				// Configure XIN (P2.6) and XOUT (P2.7) to GPIO
        P2SEL |= BIT1;						// P2.1 to PWM
        P2OUT = 0x00;							// Drive all Port 2 pins low
        P2DIR = 0xFF;							// Configure all Port 2 pins outputs
      
        Timer1_A3_init();
      
        // Initialize Baseline measurement
        TI_CAPT_Init_Baseline(&one_button);
        
        // Update baseline measurement (Average 5 measurements)
        TI_CAPT_Update_Baseline(&one_button,5);
        
        // Main loop starts here
        while (1)
        {
      		#ifdef ELEMENT_CHARACTERIZATION_MODE
      	  // Get the raw delta counts for element characterization
      	  TI_CAPT_Custom(&middle_button,&dCnt);
      	  __no_operation(); 					// Set breakpoint here
      		#endif
      
      	#ifndef ELEMENT_CHARACTERIZATION_MODE
      
      	  FeedbackLED(one_button, BIT0, 0);
      
      	#endif
        }
      } // End Main
      

      You may also have a look on the complete project if you wish 6136.oneButtonPWMTest.zip

      Frank

      BTW: When I change the ".measGateSource" in structure.c to SMCLK, it looks much better, but the sensitivity decreases dramatically and I am not really happy with that workaround.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Frank Boehme
      Posted by Frank Boehme
      on May 02 2012 11:21 AM
      Prodigy40 points

      I think I have it!

      In the original CTS_HAL.c is the code

              if(group->measGateSource == GATE_WDT_ACLK)
              {
                  __bis_SR_register(LPM3_bits+GIE);   // Wait for WDT interrupt
              }
              else
              {
      	    __bis_SR_register(LPM0_bits+GIE);   // Wait for WDT interrupt
              }
       
      
      
      
      
      

      which causes the MCU going in Low Power Mode 3 when using the ACLK which disables the SMCLK and therefore the TIMER_A1 in my code. 

      I changed LPM3 to LPM0 and it works.

      Can anyone confirm this?

      Frank

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on May 02 2012 13:51 PM
      Guru141810 points

      It's well possible that the funciton TI_CAPT_Custom and TI_CAPT_Button or something they do (especially the 'Custom' looks suspicious) causes a compatibility problem.

      Your TIemr setup doesn't use itnerrupts and runs in plain hardware. But it is possible that the CAPT code somehow requires the timer by itself.

      IIRC, the touch pins are oscillating and the oscillations are counted by Timer0. However, to make any sense, you'll need to know how many oscillations per time period happen. And since TimerA0 is used for counting pulses, only TimerA1 is available for measuring the period. So both tiemrs are implicitely used for CapSense and your use of TimerA1 conflicts with this.

      I don't know the actual TI library code, but I bet it is a good guess.

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Frank Boehme
      Posted by Frank Boehme
      on May 03 2012 03:48 AM
      Suggested Answer
      Prodigy40 points

      Thank you for the response.

      The TI_CAPT_Custom and TI_CAPT_Button functions are TI code, I just used them, hoping that they know what they do.

      I think they use the TimerA0 for counting and the WDT for the time period, which leaves the TimerA1 free. The problem was that the MCU was sent to LPM3 at each touch cycle which disabled my PWM.

      I now happy with that.

      Thanks again

      Frank


      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on May 03 2012 06:48 AM
      Guru141810 points

      Frank Boehme
      The problem was that the MCU was sent to LPM3 at each touch cycle which disabled my PWM.

      Well, as long as Timer1 is using SMCLK, LPM3 shouldn't disable it. But this is on 5x family. I'm not sure for 2x family, I never used LPMs there.

      Frank Boehme
      TI code, I just used them, hoping that they know what they do

      The problem with TI code is not that they don't know what they do, but that you don't know what they do. Lack of detailed documentation. So I always suspect 'foreign' code in a project.
      This is not a TI specific problem, I also had it with 3rd party libraries on Flex (Flash), Dojo (JavScript) and elsewhere. But indeed, in some cases it turned out that they didn't know what they were doing too, while after debugging I did know. :)

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      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