• 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 » Stellaris® ARM® Microcontrollers » Stellaris® ARM® LM3S Microcontrollers Forum » How do I setup setup PWM 0 at 1000Hz and 50% duty cycle
Share
Stellaris® ARM® Microcontrollers
  • Forum
Options
  • Subscribe via RSS
Helpful Stellaris® LM4F Series Links
  • LM4F Series
  • Stellaris PinMux Utility
  • Stellaris® LM4F120 LaunchPad
  • LM4F MCU Applications
  • LM4F MCU Video
  • ARM Cortex-M4F Whitepaper
  • Stellaris MCU Brochure
  • LM4F232 Eval Kit
  • Forums

    How do I setup setup PWM 0 at 1000Hz and 50% duty cycle

    This question is answered
    Stephen Griffiths
    Posted by Stephen Griffiths
    on May 03 2012 17:21 PM
    Intellectual345 points

    ////Init (PF0)
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);

    //Set clock directly from crystal
    SysCtlPWMClockSet(SYSCTL_PWMDIV_16);

    // Set GPIO F0 as PWM pin.
    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);

    // Compute the PWM period based on the system clock.
    ulPWMPeriod = SysCtlClockGet() / 1000;

    //Configure PWM
    PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, ulPWMPeriod );

    //Set Pulse Width
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, (unsigned long)(ulPWMPeriod * 50));

    //Enable Output signal
    PWMOutputState(PWM_BASE, PWM_OUT_0_BIT, true);

    // Enable the PWM generator.
    PWMGenEnable(PWM_BASE, PWM_GEN_0);

    What is missing? I'm not seeing any activity on the PF0 PWM signal at all?

    PWM duty cycle setup Help argggh lm3s9d96
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • cb1_mobile
      Posted by cb1_mobile
      on May 03 2012 17:34 PM
      Guru21640 points

      PF0 defaults into "special function" mode on certain Stellaris MCUs - this may be the cause of your issue.  Earlier (your I2C post) Stellaris Mitch requested that you identify your chosen MCU - without that knowledge we are forced to "guess."

      Assuming that your MCU is among those which specially treats - or locks PF0 - you must first unlock PF0 and then place it into PWM mode.  (assuming that is an allowed use of PF0)

      There is a sticky, guideline post atop this forum which outlines forum procedures which will benefit your future posts.  (and those who choose to respond...)

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Stephen Griffiths
      Posted by Stephen Griffiths
      on May 03 2012 21:54 PM
      Intellectual345 points

      Thanks for any help you can offer.  The processor is the lm3s9d96.  Would I be better off using a different pin?

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • cb1_mobile
      Posted by cb1_mobile
      on May 04 2012 08:09 AM
      Verified Answer
      Verified by Stephen Griffiths
      Guru21640 points

      Stephen Griffiths
       Would I be better off using a different pin?

      Absolutement - mon ami!  KISS always best - you have much to read/learn/master - suggest that you initially study your design goals - then focus on individual goal achievement.  (dealing with "special pins" - at this time - is unnecessary/unwanted distraction - your idea of choosing a, "less restricted/suspect pin" makes perfect sense...) 

      Be sure to read/review

      a) MCU datasheet

      b) numerous Stellaris code examples which relate to your project's needs

      c) StellarisWare Driver Library "User Guide" details PWM functions and provides brief, code examples.  (beware - peeve of mine/others - while SW-DRL User Guide's code examples are tested - they most always "avoid" the very necessary, "Pre-set-ups/configs" - without which the example code may, "fail to perform!"   Frustration could be reduced/perhaps prevented by "boiler-plate reminder," "Note: Insure that any/all pins/ports referenced by this code example have been properly/fully configured."  (and especially have their clocks, "SysCtlEnabled()"...)

      Confess to very quick scan of your code - basically looks good.  Change to different pin - continue w/modified code Configs/Set-Ups (due to new pin - possibly new port) and try/report.   You're almost there...

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Stephen Griffiths
      Posted by Stephen Griffiths
      on May 04 2012 09:31 AM
      Intellectual345 points

      SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
      SysCtlDelay(1000);
      GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_3, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
      GPIODirModeSet(GPIO_PORTJ_BASE, GPIO_PIN_3, GPIO_DIR_MODE_OUT);
      GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_3, m_PowerState);

      ////Init MLP PWM Brightness Control (PF0)
      SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
      SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
      SysCtlDelay(1000);

      Got it.  This is the initialization that finally worked.  Thanks for everyone who helped out on this.

      GPIOPinConfigure(GPIO_PF0_PWM0);
      GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
      PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
      SysCtlDelay(10);

      // Compute the PWM period based on the system clock.
      m_PWMPeriod = SysCtlClockGet() / m_PWMFrequency;
      unsigned long width = (unsigned long)(m_PWMPeriod * 50* 0.01);

      printf("MLP PWM: period=%d, freq=%d, dutycycle=%d width=%d\n", m_PWMPeriod, m_PWMFrequency, m_DutyCyclePercent, width);

      PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, m_PWMPeriod);
      SysCtlDelay(10);

      PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, width);
      SysCtlDelay(10);

      PWMGenEnable(PWM0_BASE, PWM_GEN_0);
      SysCtlDelay(10);

      PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
      SysCtlDelay(10);

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • cb1_mobile
      Posted by cb1_mobile
      on May 04 2012 10:02 AM
      Verified Answer
      Verified by Stephen Griffiths
      Guru21640 points

      Stephen Griffiths
      initialization that worked.  Thanks for everyone (1) 

      Ahh...  Success has many fathers...  failure few.  (where is that pistol?  one way to escape dreary basement...)

      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