I'm using a EK-TM4C123GXL board to run a tower pro sg90 servo motor.My system clock is running at 16Mhz and im using Keil to program.Given below is the code I wrote, but there is no movement on the servo.
#include "tm4c123gh6pm.h" //header file, tm4c123gh6pm register descriptions /***************************************Definition************************************/ #define SIGNAL (01U << 7) //PWM signal #define LOAD 0x270FF //LOAD value = 159,999 /***************************************************************************************/ void PWM_init() //PWM_init function enables PWM at PortB7 to work in a countdown mode. { SYSCTL_RCGC0_R |= SYSCTL_RCGC0_PWM0; //Enable pwm clock SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOB; //PORT B clock enable __asm{nop nop} //Two NOP delay to stabilize clock (Mixed ASM C Programming) GPIO_PORTB_DIR_R |= SIGNAL; //Set the B7 pin as output GPIO_PORTB_AFSEL_R |= SIGNAL; //Enable Alternate function for B7 GPIO_PORTB_PCTL_R &= ~(GPIO_PCTL_PB7_M); //PORT mux control for PB7 - Clear bit GPIO_PORTB_PCTL_R |= GPIO_PCTL_PB7_M0PWM1; //PORT mux control for PB7 - set PWM GPIO_PORTB_DATA_R |= SIGNAL; //Data enable for PB7 SYSCTL_RCC_R |= SYSCTL_RCC_USEPWMDIV; //Enable PWM divider SYSCTL_RCC_R &= ~(SYSCTL_RCC_PWMDIV_M); //Clear PWM divider filed SYSCTL_RCC_R |= SYSCTL_RCC_PWMDIV_2; //Set PWM divide as /2 PWM0_1_CTL_R = 0x00000000; //Disable PWM timer //Masking the action for Bdown & counter = LOAD PWM0_1_GENB_R &=~(PWM_0_GENB_ACTCMPBD_M | PWM_0_GENB_ACTLOAD_M); PWM0_1_GENB_R |= (PWM_0_GENB_ACTLOAD_ONE | PWM_0_GENB_ACTCMPBD_ZERO); PWM0_1_LOAD_R = LOAD; //LOAD value set as 159,999 PWM0_1_CMPB_R = LOAD*(0.9); //Initial value for comparator B is 0.9*LOAD PWM0_1_CTL_R = PWM_0_CTL_ENABLE; //Enable PWM timer PWM0_ENABLE_R = PWM_ENABLE_PWM1EN; //Enable PWM } int main() { PWM_init(); }
Please can somebody tell me whats wrong in the code?