I have the following code for a task that requires me to use the following code to use the Timer_A0 module in the CCS IDE to control the speeds of the motors for a robot that uses the MSP432P401R launchpad as the control unit. How do I initialize the Timer_A0 module in the C programming code below?:
#include "driverlib.h" #include "mechrev.h" /* Define macros and function prototypes if needed */ #define BTN1_PIN GPIO_PORT_P1,GPIO_PIN1 #define BTN2_PIN GPIO_PORT_P1,GPIO_PIN4 #define ENB1_PIN GPIO_PORT_P1,GPIO_PIN6 #define ENB2_PIN GPIO_PORT_P1,GPIO_PIN7 #define PWM1_PIN GPIO_PORT_P2,GPIO_PIN4 #define PWM2_PIN GPIO_PORT_P2,GPIO_PIN5 #define PWM3_PIN GPIO_PORT_P2,GPIO_PIN6 #define PWM4_PIN GPIO_PORT_P2,GPIO_PIN7 #define BMP0_PIN GPIO_PORT_P4,GPIO_PIN0 #define BMP7_PIN GPIO_PORT_P4,GPIO_PIN7 #define BMP2_PIN GPIO_PORT_P4,GPIO_PIN2 #define BMP6_PIN GPIO_PORT_P4,GPIO_PIN6 #define BMP3_PIN GPIO_PORT_P4,GPIO_PIN3 #define BMP5_PIN GPIO_PORT_P4,GPIO_PIN5 #define BTN3_PIN GPIO_PORT_P4, GPIO_PIN0 | GPIO_PIN7 #define BTN4_PIN GPIO_PORT_P4, GPIO_PIN2 | GPIO_PIN6 #define BTN5_PIN GPIO_PORT_P4, GPIO_PIN3 | GPIO_PIN5 /* Define configuration structs if needed */ /* Declare global variables if needed */ int i = 0; uint32_t counter = 0; /* Main program */ void main(void) { /* Stop Watchdog Timer */ WDT_A_holdTimer(); /* Call the mechrev_setup function included in the mechrev.h header file */ mechrev_setup(); /* Initialize GPIOs P1.1 and P1.4 for PushButtons (S1 and S2 switches) */ MAP_GPIO_setAsInputPinWithPullUpResistor(BTN1_PIN); MAP_GPIO_setAsInputPinWithPullUpResistor(BTN2_PIN); /* Initialize GPIOs P1.6 and P1.7 for Motor Driver IC Enable Pins */ MAP_GPIO_setAsOutputPin(ENB1_PIN); MAP_GPIO_setAsOutputPin(ENB2_PIN); /* Initialize GPIOs P2.4, P2.5, P2.6 and P2.7 for PWM functionality */ MAP_GPIO_setAsInputPin(PWM1_PIN); MAP_GPIO_setAsInputPin(PWM2_PIN); MAP_GPIO_setAsInputPin(PWM3_PIN); MAP_GPIO_setAsInputPin(PWM4_PIN); /* Initialize Timer A0 to generate PWM signals */ (Timer_A0 module needs to be initialized here) /* Declare local variables if needed */ /* Call the initialization grading macro */ MACRO_LAB4_INIT(); while(1) { /* Design a Polling process to detect PushButtons press and adjust the PWM duty cycles accordingly */ if (MAP_GPIO_getInputPinValue(BTN1_PIN) == GPIO_INPUT_PIN_LOW) { if(i == 1) { TA0CCR1 = 999; TA0CCR2 = 0; TA0CCR3 = 999; TA0CCR4 = 0; } if(i == 2) { TA0CCR1 = 1998; TA0CCR2 = 0; TA0CCR3 = 1998; TA0CCR4 = 0; } if(i == 3) { TA0CCR1 = 3000; TA0CCR2 = 0; TA0CCR3 = 3000; TA0CCR4 = 0; } for (i=0; i<10000; i++); // switch debouncing } else if (MAP_GPIO_getInputPinValue(BTN2_PIN) == GPIO_INPUT_PIN_LOW) { if(i == 1) { TA0CCR1 = 0; TA0CCR2 = 999; TA0CCR3 = 0; TA0CCR4 = 999; } if(i == 2) { TA0CCR1 = 0; TA0CCR2 = 1998; TA0CCR3 = 0; TA0CCR4 = 1998; } if(i == 3) { TA0CCR1 = 0; TA0CCR2 = 3000; TA0CCR3 = 0; TA0CCR4 = 3000; } for (i=0; i<10000; i++); // switch debouncing } else { TA0CCR1 = 0; TA0CCR2 = 0; TA0CCR3 = 0; TA0CCR4 = 0; } /* Note: Call the event grading macro after changing PWMs */ MACRO_LAB4_EVENT(); } } void PORT4_IRQHandler(void) { /* Check the interrupt status */ uint32_t status; status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P4); if (status) { if(MAP_GPIO_getInputPinValue(BMP0_PIN) == GPIO_INPUT_PIN_LOW || MAP_GPIO_getInputPinValue(BMP7_PIN) == GPIO_INPUT_PIN_LOW) { i = 1; counter++; } else if (MAP_GPIO_getInputPinValue(BMP2_PIN) == GPIO_INPUT_PIN_LOW || MAP_GPIO_getInputPinValue(BMP6_PIN) == GPIO_INPUT_PIN_LOW) { i = 2; counter++; } else if (MAP_GPIO_getInputPinValue(BMP3_PIN) == GPIO_INPUT_PIN_LOW || MAP_GPIO_getInputPinValue(BMP5_PIN) == GPIO_INPUT_PIN_LOW) { i = 3; counter++; } } else { counter++; } MACRO_LAB3_EVENT(); /* Clear the PORT4 interrupt flag */ MAP_GPIO_clearInterruptFlag(GPIO_PORT_P4, status); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)