• 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 » adc to pwm on msp430g2231
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

    adc to pwm on msp430g2231

    This question is answered
    mehmet celik
    Posted by mehmet celik
    on May 04 2012 12:01 PM
    Prodigy20 points

    Hi everyone.

    Can i controll the brightness of four different LED by using PWM according to changing values read from four different variable POT with the help of ADC?

    I think it is impossible to do it with four different channel, at least how can i do it only one channel namely let the brightness of LED changes according to a variable POT.

    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 May 04 2012 17:47 PM
      Verified Answer
      Verified by mehmet celik
      Guru141810 points

      mehmet celik
      Can i controll the brightness of four different LED by using PWM according to changing values read from four different variable POT with the help of ADC?


      Of the G series, the 2x53 devices are the only ones with two Timers and three CCR units each. Since one of the CCR units of each tiemr is required to set the PWM frequencies, you can do four PWM outputs with the 2x53 devices, but only one with all other G-series MSPs, as these only have one timer with two CCR units.

      However, you can do sort of a PWM in plain software for any number of signals you have free GPIO pins available. It will require tight coding and use a significant amount of CPU time, but it is possible.

      For a single PWM output, things are relatively simple. Use the ADC to obtain an input voltage, e.g. with a pot between VCC and GND. So you'll get a value of 0..1023 for 0..100%.

      Now write 1022 (!) to TACCR0 and let the timer run in up mode. Then program TACCTL1 to RESET/SET mode and configure the port pin of TA0.1 for module output.

      TACCR1 gets the value from the ADC.For any ADC value x from 1 to 1023 this will result in a duty cycle of x/1023. The only exception is x=0. In this case you'll have to switch the port pin off manually.

      But keep in mind that the human perception of brightness is not linear. So the optical impression of the resulting LED brightness won't be what you'd expect from the POT position.
      So for a better result, vreate a translation table that converts all possible 1024 ADC results into a value from 0 to 100. Write 99 to TACCR0 instead of 1022. And the 1..100 result (for 0, again you'll have to switch the port pin off manually) to TACCR1. THis allows for a fine control of the brightness according the human perception courve.

      _____________________________________
      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.
    • mehmet celik
      Posted by mehmet celik
      on May 15 2012 14:34 PM
      Prodigy20 points

      Thanks for your answer Michael.

      Now I'm a little confused. Because there should a timer both of operation of ADC and PWM. How can I settle the timer.

      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 16 2012 10:25 AM
      Guru141810 points

      mehmet celik
      Because there should a timer both of operation of ADC and PWM. How can I settle the timer.

      It depends on your exact requirements.

      A timer has a cycle time which you can control eithe rby limiting the number of ticks per cycle (using CCR0 and tierm up mode) or by changing the speed of the timer ticks (the source clock speed).
      However, all periodical events always happen once per cycle. If you want a timer to trigger your ADC conversions as well as producing a PWM output, you need to find a common base. The timer conversion frequency then needs to be the PWM cycle frequency. Also, the trigger signal for the timer is produced by a CCR unit, which also produces the PWM output. So you need to use a constant trigger point, e.g. the raising edge of the PWM signal at begin of the cycle. However, a PWM DC of 0 would actually stop the ADC triggering then.

      Arternatively you can trigger an interrupt at tiemr overrun and manually start the conversions inside the ISR. THis will introduce some jitter ot the start of each conversion, but the average sampling frequency will still be correct.

      You need to determine your exact parameters. Required PWM frequency, required sampling frequency etc. However, it is possible that you won't find a combination that fits all of your requirements. Then you have the wrong processor and need one with more timers (or with timers with more CCR units)

      _____________________________________
      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