This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Tiva C Series TM4C123G LaunchPad Evaluation Board PWM DEMO

Hi,

 i'm trying to use the PWM to change the LEDs (PF1 PF2 PF3) brightness can you help me out?

   SYSCTL->RCGC0 |= (1U << 20);  /* enable clock for PWM */
   SYSCTL->RCGCPWM |= (1U << 1); // for PWM MODULE 1
   SYSCTL->RCGC2 |= (1U << 5);  /* enable clock for GPIOF */
   GPIOF->AFSEL |=(1U << 1 ) | (1U << 2) | (1U << 3); /* Set the GPIO AFSEL bits PF1 PF2 & PF3 */
   GPIOF->PCTL |=(5 << 4 ) | (5 << 8) | (5 << 12); /* Configure the PMCn fields in the GPIOPCTL register 5=PWM */
   SYSCTL->RCC |=(1U << 20 ); /*set the RCC divider for PWM */ 
   SYSCTL->RCC &= ~((0U << 17 ) | (0U << 18 ) | (0U << 19 ));
   //Configure the PWM generator for countdown mode with immediate updates to the parameters.
   PWM1->_2_CTL |= (0x0000 << 0);
   PWM1->_3_GENA |=(0x8C << 0);
   PWM1->_2_GENB |=(0x80C << 0);  
   PWM1->_3_GENB |=(0x80C << 0);
   //Set the period. For a 50Hz frequency
   PWM1->_2_LOAD |=(0x3E7F << 0);
   PWM1->_3_LOAD |=(0x3E7F << 0);
   //Set the pulse width pin for a 25% duty cycle
   PWM1->_2_CMPB |=(0x12B <<0);
   PWM1->_3_CMPA |=(0x12B <<0);
   PWM1->_3_CMPB |=(0x12B <<0);
   //Start the timers in PWM generators.
   PWM1->_2_CTL |=(1U << 0 );
   PWM1->_3_CTL |=(1U << 0 );
   //Enable PWM outputs.
   PWM1->ENABLE |=(0xE << 4);
   while(1){}

  • Meir Malul said:
    can you help me out?

    Surely - which way did you come in?   (old - yet appropriate - and still funny)

    Wouldn't you best help yourself by employing vendor's, "Tried/true/far simpler API code" rich w/examples?

    While you "seek help" you fail to describe (at all) what works - or does not - is it fair that we are left to guess?

  • Hello Meir,

    Incredibly difficult to not only maintain but work debugging of the code when API are not used. Please refer to the examples under

    D:\ti\TivaWare_C_Series-2.1.1.71\examples\peripherals\pwm

    To see how to configure the PWM and then work on the algorithm to control the brightness. There are some good online articles on rate of blink which makes the blinking invisible to the eye and yet have the affect of dim control

    Regards
    Amit
  • Amit Ashara said:
    makes the blinking invisible to the eye

    Quite similar to DRM - which makes the code dump here equally, "invisible to the eye/mind!"

  • Hello cb1,

    Yes, that is what I made the comment to use API's. But this DRM method is something that may be coming from somewhere else as we do not release the CMSIS format in TivaWare.

    Regards
    Amit