Trying to initialize PWM on PB4 on the TM4C123 Microcontroller

0

As the tittle states I am trying to initialize PWM for PB4 on the TM4C123 microcontroller using Keil as the IDE. So far I have been able to initialize PB6 and PB7 but i'm not sure why PB4 isn't working. Do you guys know whats I'm doing wrong? Thanks in advance for your help. I have posted my working code for initalizing port B6 and the one that isnt working for port B4.

// PWM clock rate = processor clock rate/SYSCTL_RCC_PWMDIV
//                = BusClock/16
//                = 80 MHz/16 = 5 MHz 
// Output on PB7/M0PWM1
void PWM0B4_Init(uint16_t period, uint16_t duty) 
{
    
    volatile unsigned long delay;
    SYSCTL_RCGCPWM_R |= 0x01;             // 1) activate PWM0
    SYSCTL_RCGCGPIO_R |= 0x02;            // 2) activate port B
    // delay = SYSCTL_RCGCGPIO_R;         // allow time to finish activating
    while((SYSCTL_PRGPIO_R&0x02) == 0){};
    GPIO_PORTB_AFSEL_R |= 0x10;           // enable alt funct on PB4
    GPIO_PORTB_PCTL_R &= ~0x000F000;      // configure PB4 as M0PWM2
    GPIO_PORTB_PCTL_R |= 0x0004000;
    GPIO_PORTB_AMSEL_R &= ~0x10;          // disable analog functionality on PB4
    GPIO_PORTB_DEN_R |= 0x10;             // enable digital I/O on PB4 ** double check **
    SYSCTL_RCC_R = 0x00100000 |           // 3) use PWM divider
   (SYSCTL_RCC_R & (~0x000C0000));        //    configure for /16 divider
    
    PWM0_1_CTL_R = 0;                     // 4) re-loading down-counting mode
    PWM0_1_GENB_R = (PWM_1_GENB_ACTCMPBD_ONE|PWM_1_GENB_ACTLOAD_ZERO);

    // PB4 goes low on LOAD
    // PB4 goes high on CMPB down
    PWM0_1_LOAD_R = period - 1;           // 5) cycles needed to count down to 0
    PWM0_1_CMPB_R = duty - 1;             // 6) count value when output rises
    PWM0_1_CTL_R |= 0x00000001;           // 7) start PWM0
    PWM0_ENABLE_R |= 0x00000004;          // enable PB4/M0PWM2 **** check

}

// change duty cycle of PB4
// duty is number of PWM clock cycles output is high  (2<=duty<=period-1)
void PWM0B4_Duty(uint16_t duty)
{
    
    PWM0_1_CMPB_R = duty - 1;             // 6) count value when output rises
}




void PWM0B6_Init(uint16_t period, uint16_t duty)
{

  SYSCTL_RCGCPWM_R |=0x01;                  // 1) activate PWM0 
  SYSCTL_RCGCGPIO_R|=0x02;                  // 2) activate portB
  while ((SYSCTL_PRGPIO_R&0x02) == 0) {};           
  GPIO_PORTB_AFSEL_R |= 0x40;               // enable alt funct on PB6
  GPIO_PORTB_PCTL_R &= ~0x0F000000;         // configure PB6 as PWM0
  GPIO_PORTB_PCTL_R |= 0x04000000;              
  GPIO_PORTB_AMSEL_R &= ~0x40;              // disable analog functionality on PB6
  GPIO_PORTB_DEN_R |= 0x40;                 // enable digital I/O on PB6
  SYSCTL_RCC_R = 0x00100000 |               // 3) use PWM divider
  (SYSCTL_RCC_R & (~0x000C0000));            // configure for /16 divider to C
  PWM0_0_CTL_R = 0;                         // 4) re-loading down-counting mode
  PWM0_0_GENA_R = 0xC8;                     // low on LOAD, high on CMPA down
  // PB6 goes low on LOAD
  // PB6 goes high on CMPA down
  PWM0_0_LOAD_R = period - 1;               // 5) cycles needed to count down to 0
  PWM0_0_CMPA_R = duty - 1;                 // 6) count value when output rises
  PWM0_0_CTL_R |= 0x00000001;               // 7) start PWM0
  PWM0_ENABLE_R |= 0x00000001;              // enable PB6/M0PWM0

}

// change duty cycle of PB6
// duty is number of PWM clock cycles output is high (2<=duty<=period-1)
void PWM0B6_Duty(uint16_t duty)
{

  PWM0_0_CMPA_R = duty - 1; // 6) count value when output rises

}
c
keil
pwm
asked on Stack Overflow Sep 21, 2020 by teamusa7 • edited Sep 24, 2020 by teamusa7

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0