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.

Stellaris LM4F120H5QR PWM configuration problem

Greetings,

Im facing a problem configuring a general purpose timer module for pwm output on pin PF1:

Currently my config funtion looks like this

void
configure_pwm()
{
  SYSCTL->RCGCTIMER |=     0x01;   //Enable TIMER0 Module
  SYSCTL->RCGCGPIO  |=   1 << 5;   //Clock GPIOF
  GPIOF->AFSEL      |=     0x02;   //Select alternate function on pin PF1
  GPIOF->PCTL       |=     0x70;   //Select T0CCP1 function for pin PF1
  TIMER0->CTL        &=   0 << 8;   //Ensure the timer (Timer B) is disabled before making changes
  TIMER0->CFG        |=     0x04;   //Select the 16 bit timer configuration
  TIMER0->TBMR       |=     0x0A;   //TnAMS = 0x1, TnCMR = 0x0, TnMR field = 0x02
  TIMER0->CTL        &=   0 <<14;   //Timer B output is not inverted
  TIMER0->TBPR        =   0x007A;   //Prescaler value
  TIMER0->TBILR       =   0x1200;   //Load timer start value
  TIMER0->TBPMR       =   0x003D;   //load the prescale match value
  TIMER0->TBMATCHR    =   0x0900;   //load the match value
  TIMER0->CTL        |=   1 << 8;   //Enable timer B PWM generation
}

I must be missing something but i can't find what it is. Maybe you can provide some insight into this matter. System Clock is 80 Mhz.

Thanks in Advance.

  • Hi Felipe,

        See, the PWM example code for comparison. It is at "TivaWare_C_Series-1.0\examples\peripherals\pwm". Also, I would advice to use Tivaware C API's.

    -kel

  • Thank you Markel, i am aware of the TivaWare library but i wanted to understand why it would not work. Finally i got it to work after re-reading the datasheet, i was missing the GPIO output pin configuration :).

    void
    configure_pwm_PF1()
    {
      SYSCTL->RCGCTIMER  |=     0x01;   //Enable TIMER0 Module
      SYSCTL->RCGCGPIO   |=   1 << 5;   //Clock GPIOF
     
      GPIOF->AFSEL       |=     0x02;   //Select alternate function on pin PF1
      GPIOF->PCTL        |=     0x70;   //Select T0CCP1 function for pin PF1
      GPIOF->DEN         |=   1 << 1;   // PF1 is digital

      unsigned ctl = TIMER0->CTL;
      ctl &= ~0x00000100;
      TIMER0->CTL        =   ctl;       //Ensure the timer (Timer B) is disabled before making changes
      TIMER0->CFG        |=     0x04;   //Select the 16 bit timer configuration
      TIMER0->TBMR       |=     0x0A;   //TnAMS = 0x1, TnCMR = 0x0, TnMR field = 0x02
      TIMER0->CTL        &=   0 <<14;   //Timer B output is not inverted
      TIMER0->TBPR        =   0x007A;   //Prescaler value
      TIMER0->TBILR       =   0x1200;   //Load timer start value
      TIMER0->TBPMR       =   0x003D;   //load the prescale match value
      TIMER0->TBMATCHR    =   0x0900;   //load the match value
      TIMER0->CTL        |=   1 << 8;   //Enable timer B PWM generation
    }

  •      Hi Felipe, I tried to compile your piece of code but i got a lot of errors, could you please informe me what header files did you use? I using Keil light.

    Thanks in advance

    Hamilton

  • Greetings Hamilton,


    I used Rowley CrossWorks so the register names and the header files may be different than Keil's, but the general configuration procedure might be similar.


    Atte,


    Felipe.