• 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 » Pulse Counting and Function Generator
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 >
  • Pulse Counting and Function Generator

    Pulse Counting and Function Generator

    This question is not answered
    Akshay Raghu
    Posted by Akshay Raghu
    on Jun 05 2012 08:28 AM
    Prodigy210 points

    I am very new to using MSP430s and am trying to work on two separate projects using it:

    1) To take in an input signal from a function generator and calculate the duty cycle, frequency, etc from the signal. I know that to do this I'll have to use a timer and some type of capture, but I'm having a lot of difficulty getting started on it.

    2) To use the MSP430 as a function generator itself, to create square waves with a defined duty cycle and frequency. I'm having similar trouble getting started with this one, because I know I'll have to use a timer again, but I'm not sure how to define it to output the signal properly.

    I have an MSP430-F2013 and an MSP430-RF2500 that I can work with to program each of these.

    Any assistance you can give would be greatly appreciated. Thanks!

    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 Jun 07 2012 20:27 PM
      Guru140435 points

      Akshay Raghu
      I'm having a lot of difficulty getting started on it.

      What's your problem then? THe basic concept of timers? How to use them for couting external events?

      Basically, the timer is a counter. It counts clock pulses. When its coutner registe roverflows, it will trigger an interrupt. That's all.
      Now there are the Capture-Compare units. They can trigger an interrupt and/or change an output pin when the timer count reaches a certain value, or they can copy the current timer count when an external event occurs.

      So get the frequency, you configure a CCR unit for capture mode. So it captures the current tiemr count when a positive (or negative, or both) edge is detected and triggers an interrupt. The difference in teh captured count for two risign edges gives you the interval T (and 1/T is the frequency).
      For the duty cycle, you'll have to capture both edges, and teh DC is the relation of thr time between rising and falling edge and falling and next rising edge.

      Akshay Raghu
      I'm not sure how to define it to output the signal properly.

      That's rather a PWM signal output than a function generator.
      Here the CCR units are configured to change an output pin when the timrr counts to a certain value and change it again when the timer overflows. The relation of the first interval and the second gives the duty cycle.
      To allow finer control over the PWM frequency, one of the CCR units, CCR0, can make the timer overflow at a certain value rather than at 65535. The timer runs in up mode then, from 0 to CCR0, then overflows to 0 again.

      In any case, you'll have to configure the I/O pins for timer use. See the digital I/O chapter of the users guide. And look up which port pins are available for which CCR unit input/output in your MSPs device datasheet.

      _____________________________________
      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.
    • Akshay Raghu
      Posted by Akshay Raghu
      on Jun 10 2012 09:16 AM
      Prodigy210 points

      Hi Jens-Michael, 

      Thanks very much for your help. I used one of the example codes about setting up a PWM output for MSP430 RF2500(F2274), and edited it slightly to generate a PWM with a period of 50ms and a 40% duty cycle. Would you be willing to take a look and recommend any changes?

      In addition, using the RF transceivers in the pair of RF2500s, I would like to be able to transmit the PWM signal from one to the other. I've gone through the example code given in the SimpliciTI installation, but I still don't understand the syntax or setup for that to work very well, and I wasn't able to find any other threads in this forum that go into what code should be added to the current code to transmit from one and receive at the other. Can you point me to a tutorial or another thread in this forum that you know of that would get me started on adding code to the pair of transceivers to transmit/receive the signal?

      Thanks again for your help!

      #include <msp430.h>
      int main (void)
      {
      	WDTCTL = WDTPW + WDTHOLD; 	// Disable Watchdog Timer
      
      	P1DIR |= 0x04;			// Defines P1.1 and P1.2 as outputs
      	P1SEL |= 0x04;			
      
      	CCR0 = 50000 - 1;	// (CCR0+1)/1MHz * 1000 = 50 ms
      	CCTL1 = OUTMOD_7;
      	CCR1 = 20000;
      
      	BCSCTL1 = CALBC1_1MHZ;	// Configures DCO clock at 1 MHz.
      	DCOCTL = CALDCO_1MHZ;	// Configures DCO clock at 1 MHz.
      
      	TACTL = TASSEL_2 + ID_0 + MC_1 + TACLR;
      		// Chooses SMCLK as source, no divider, Up-mode, clears counter
      	
      	__BIS_SR(LPM0_bits);
      }

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Roberto Romano
      Posted by Roberto Romano
      on Jun 10 2012 09:23 AM
      Mastermind6840 points

       hi,IMHO you are in a too early stage to perform wireless communication, so try study and fully grasp every example come from TI then try some more deep task and if you have a solid programmer experience you can afford analysis of simpliciTI code. Otherwise is the same as pretending to run when you born few days ago.

       

       Regards

       Roberto


       Please login & click    Verify Answer    if this post answered your question.

      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 Jun 10 2012 17:37 PM
      Guru140435 points

      Akshay Raghu
      edited it slightly to generate a PWM with a period of 50ms and a 40% duty cycle. Would you be willing to take a look and recommend any changes?

      It looks like it shoudl work as expected. Except one thing: P1.1 will only output a 1µs pulse every 50ms - if you set OUTMOD_7 for CCTL0 too. Currently, it will remain low

      And, well, the 1MHz calibrated frequency isn't exactly stable 1MHz. It is only as close as the DCO in this MSP can get to 1MHz at 25°C and Vcc=3V. And only as an average over (at least) 32 clock cycles (usually, 5ms averaging time are given for the precision in the datasheet).
      So expect some drift with temperature change, some frequency error and also a little jitter if the PWM frequency isn't a multiple of 32 timer ticks.

      For the RF2500, I don't have any experience. However, there are several threads in this forum. (I usually skip them :) )

      _____________________________________
      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.
    • Akshay Raghu
      Posted by Akshay Raghu
      on Jun 10 2012 17:58 PM
      Prodigy210 points

      Jens-Michael Gross
       It looks like it shoudl work as expected. Except one thing: P1.1 will only output a 1µs pulse every 50ms - if you set OUTMOD_7 for CCTL0 too. Currently, it will remain low

      I think the forum stole the end of what you were trying to say there :). Were you trying to say that the code as I had it will output a 1µs pulse every 50ms instead of a 20ms pulse every 50ms? If so, could you explain why setting OUTMOD_7 for CCTL0 also is necessary to get the desired output?

      And thanks for letting me know that the 1MHz frequency is not exact; I am aware that for a truly accurate output I would need to add a crystal between XIN and XOUT, but for the time being the 1MHz calibrated frequency should suffice.

      Thanks again!

      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 Jun 11 2012 10:35 AM
      Guru140435 points

      Akshay Raghu
      I think the forum stole the end of what you were trying to say there :)

      No, I was just not writing it out in detail.
      You configured P1.1 for module output, but you didn't configure CCTL0 to output something on this pin. So it remains in OUTMOD_0 which is the content of the OUT bit, which in turn ins zero by default. If you change CCTL0 to OUTMOD_7, you'll see a short (1 timer tick) pulse at the beginning (or end) of each cycle.

      P1.2 is controlled by CCTL1 and should give you the desired 50ms 40% DC signal.

      _____________________________________
      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