• 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 » loop ADC work just one time
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

    loop ADC work just one time

    This question is not answered
    felipe paulo
    Posted by felipe paulo
    on May 19 2012 12:37 PM
    Intellectual400 points

    Hi, i am trying do work one ADC, but he work one time, when he will convert again he dont work, he stop in this line

     while (ADC10CTL1 & BUSY);  

    look my code

    ----------------------------------------

    main code

          InitLCD();      
            initadc();
            while(1){
           adc();
           letensao();
           lecorrente();
            }

    --------------------------------------

    initadc()

    -----------------------------------

        void initadc(){

          ADC10CTL1 = INCH_1 + CONSEQ_1;            // /A2/A1, sequência simples
          ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
          ADC10DTC1 = 0x02;                         // 2 conversões
          ADC10AE0 |= 0x03;                         // P1.1, 1.0 entradas ADC10

        }

    -------------------------------

    adc()

    ------------------------------
            float volt;
            float current;
            ADC10CTL0 &= ~ENC;
            while (ADC10CTL1 & BUSY);               // Aguarda até o ADC10 estar ativo
            ADC10SA = (unsigned int)&conv_ADC10;    // Inicializa o buffer de dados
            ADC10CTL0 |= ENC + ADC10SC;             // Inicia a amostragem/conversão

            volt = ((2.5*conv_ADC10[0])/1023);
            current = ((2.5*conv_ADC10[1])/1023);
            __delay_cycles(200);
            grava_valor(volt,endetensao,86);
            __delay_cycles(200);
            grava_valor(current,endecorrente,65);            // leitura da corrente

    --------------------------------------

    grava_valor is one function that records the value in the flash memory

    letensao() and lecorrente() are functions that show the values recorded in the memory flash in the LCD

    ------------------------

    the trouble is that this function convert ADC just one time, when he will convert again, he stop. What the happen? why he stop?

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • felipe paulo
      Posted by felipe paulo
      on May 20 2012 13:28 PM
      Intellectual400 points

      anyone?

      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 22 2012 07:39 AM
      Guru140650 points

      felipe paulo
      anyone?

      Not on sunday/weekend. :)

      felipe paulo
              ADC10CTL0 |= ENC + ADC10SC;             // Inicia a amostragem/conversão

              volt = ((2.5*conv_ADC10[0])/1023);


      Here you start the conversion (setting ADC10SC) and then work with the result. Well, with a result that hasn't appeared yet. An ADC conversion requires some time. Two conversions require twice as much time. You give it no time to do the job.

      You'll have to check (worst but simplest case with a busy-waiting while loop) whether the ADC has done its job.

      felipe paulo
            ADC10CTL1 = INCH_1 + CONSEQ_1;            // /A2/A1, sequência simples
            ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;

      I'm not sure whether the ADC likes it when you configure channel and sequence (first line) before you actually switch it on (second line).

      felipe paulo
              volt = ((2.5*conv_ADC10[0])/1023);

      Using float results in big and slow code. Why not using integer math?
      unsigned long int volt = (2500*conv_ADC10[0])>>10;
      It gives the voltage in mV, is by magnitudes faster and smaller and,well, the difference between /1023 and /1024 (>>10) is negligible.

      felipe paulo
            ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;

      After switching on the reference, some settling tiem is required. You don't give it the time to settls but almos timmediately start converting,. This results in some (first few) readings being much too high.

      _____________________________________
      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.
    • felipe paulo
      Posted by felipe paulo
      on May 22 2012 11:33 AM
      Intellectual400 points

      Jens-Michael Gross, this some time i can do with __delay_cycles()? Or i have to do with timer?

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • felipe paulo
      Posted by felipe paulo
      on May 22 2012 14:26 PM
      Intellectual400 points

      worked, i change ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V; TO ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + MSC + REF2_5V; ..... I do this to measure the power consumer. But to do this i have to multiplicate all points of measure to find the wave of power and after calculate the average power. Do you have some idea how i do this?

      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 23 2012 13:44 PM
      Guru140650 points

      felipe paulo
      this some time i can do with __delay_cycles()? Or i have to do with timer?

      That's your choice. Timers have the advantage that the CPU can do other things while the delay runs. So for more complex projects timer delays are a good thing to have. However, for a first test, delay_cycles is fine. Keep in mind that a timer delay is independent of the CPU execution speed (once the timer is set up once) whiel delay_cycles depends on current CPU cpeed and you'll need to change the parameters everywhere in your code when you change the CPU clock later. Bad thing for code you want to use in different projects.

      felipe paulo
      I do this to measure the power consumer. But to do this i have to multiplicate all points of measure to find the wave of power and after calculate the average power.

      Indeed. Power metering is a lot of math :)
      There are different approaches. You can multiply U and I, square it and accumulate it, and after a certain period (e.g. when the voltage crosses zero next time) you divide through the number of measurements and calculate the square root. Then you have the RMS power of this wave. It doesn't take much computing power (except for the square root) and also not much space.
      As usual, I suggest fixed point arithmetics rather than using floats. The ADC results are really easy to use as fixed point. Just keep the reference voltage as a scale factor for the final result rather than working with voltage values (your voltage dividers and shunt factors can also applied to the final value rather than to every sample).You can then go with long int calculations all the way until the final square root.

      _____________________________________
      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.
    • felipe paulo
      Posted by felipe paulo
      on May 23 2012 13:53 PM
      Intellectual400 points

      Yes, but how do I get the point of conversion? because the program gives me the result only when the conversion ends. If a can get the points, i can multiply the wave of de voltage and current, find the wave of power and after calculate the average. I don´t know how i do this in the MSP430

      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 24 2012 07:01 AM
      Guru140650 points

      I don't really understand what you mean. Sure you can only get the conversion result once it is ready.  One conversion, one 'point'. Available when taken.
      It's your programs job to request values when you need them, or take continuously incoming conversions results into a context. Your code just requests one pair of values, then does the calculation and then returns. If this is not what you want, then you need to change the concept of your code.

      The DTC can trigger an interrupt whenever a pair of conversions is done, so in an ISR for this interrupt, you can take the two and do whatever you want (multiply, tag them with a timestamp derived from a timer, check for zero-crossing etc.) while the ADC continues making the next sequence of conversions.

      _____________________________________
      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