Tool/software: Code Composer Studio
Hello guys,
I'm doing a test program to better understand the microprocessor.
I'm using Sample - "uart_pc_echo" and "timer_a_pwm_mode" (driverlib). I am generating a PWM signal through TimerA0 and another PWM1 through dp TimerA1. The Uart communication configures the PERIOD and DUTY CYCLE of each PWM separately. When the program receives this information, it activates the PWMs, but they are not synchronized. I need this synchroniz because in the future I need to give an OFFset between these two signals.
I appreciate any help.
Thank you.
Follow the code:
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
#define __SYSTEM_CLOCK 48000000
//![Simple Timer_A Config]
/* Timer_A PWM Configuration Parameter */
Timer_A_PWMConfig pwmConfig =
{
TIMER_A_CLOCKSOURCE_SMCLK,
TIMER_A_CLOCKSOURCE_DIVIDER_2,
9650,
TIMER_A_CAPTURECOMPARE_REGISTER_1,
TIMER_A_OUTPUTMODE_RESET_SET,
965
};
//![Simple Timer_A Config]
/* Timer_A PWM Configuration Parameter */
Timer_A_PWMConfig pwmConfig1 =
{
TIMER_A_CLOCKSOURCE_SMCLK,
TIMER_A_CLOCKSOURCE_DIVIDER_2,
19300,
TIMER_A_CAPTURECOMPARE_REGISTER_1,
TIMER_A_OUTPUTMODE_RESET_SET,
1930
};
/* Statics */
const Timer_A_ContinuousModeConfig continuousModeConfig =
{
TIMER_A_CLOCKSOURCE_ACLK, // ACLK Clock Source
TIMER_A_CLOCKSOURCE_DIVIDER_1, // ACLK/1 = 32.768khz
TIMER_A_TAIE_INTERRUPT_ENABLE, // Enable Overflow ISR
TIMER_A_DO_CLEAR // Clear Counter
};
//![Simple UART Config]
/* UART Configuration Parameter. These are the configuration parameters to
* make the eUSCI A UART module to operate with a 9600 baud rate. These
* values were calculated using the online calculator that TI provides
* at:
*software-dl.ti.com/.../index.html
*/
const eUSCI_UART_Config uartConfig =
{
EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
312, // BRDIV = 13
8, // UCxBRF = 0
0, // UCxBRS = 37
EUSCI_A_UART_NO_PARITY, // No Parity
EUSCI_A_UART_LSB_FIRST, // LSB First
EUSCI_A_UART_ONE_STOP_BIT, // One stop bit
EUSCI_A_UART_MODE, // UART mode
EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling
};
//![Simple UART Config]
//Declaração de Operadores Globais
char matriz1[7] = {0, 0, 0, 0, 0, 0, 0};
int Start = 0;
int Cont = 0;
int atualizapwm1 = false;
int atualizapwm2 = false;
int ContimerA0 = 0;
int ContimerA1 = 0;
int atraso = 0;
int main(void)
{
/* Halting WDT */
MAP_WDT_A_holdTimer();
/* Selecting P1.2 and P1.3 in UART mode */
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
//![Simple Timer_A Example]
/* Setting MCLK to REFO at 128Khz for LF mode
* Setting SMCLK to 128Khz */
MAP_CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ);
MAP_CS_initClockSignal(CS_MCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
MAP_CS_initClockSignal(CS_SMCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
MAP_PCM_setPowerState(PCM_AM_LF_VCORE0);
/* Configuring GPIO2.4 as peripheral output for PWM and P1.1 for button
* interrupt */
MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4,
GPIO_PRIMARY_MODULE_FUNCTION);
MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P7, GPIO_PIN7,
GPIO_PRIMARY_MODULE_FUNCTION);
MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);
MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
/* Configuring Timer_A to have a period of approximately 500ms and
* an initial duty cycle of 10% of that (3200 ticks) */
// MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);
// MAP_Timer_A_generatePWM(TIMER_A1_BASE, &pwmConfig1);
//![Simple Timer_A Example]
/* Setting DCO to 48MHz */
FlashCtl_setWaitState( FLASH_BANK0, 2);
FlashCtl_setWaitState( FLASH_BANK1, 2);
PCM_setPowerState( PCM_AM_DCDC_VCORE1);
CS_setDCOCenteredFrequency( CS_DCO_FREQUENCY_48);
CS_setDCOFrequency(48000000);
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, 1);
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, 1);
CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, 1);
/* Configuring Continuous Mode */
MAP_Timer_A_configureContinuousMode(TIMER_A3_BASE, &continuousModeConfig);
//![Simple UART Example]
/* Configuring UART Module */
MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);
/* Enable UART module */
MAP_UART_enableModule(EUSCI_A0_BASE);
/* Enable interrupts */
MAP_Interrupt_enableInterrupt(INT_TA3_N);
/* Enabling interrupts */
MAP_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
MAP_Interrupt_enableInterrupt(INT_PORT1);
// MAP_Interrupt_enableSleepOnIsrExit();
MAP_Interrupt_enableMaster();
//![Simple UART Example]
/* Starting the Timer_A3 in continuous mode */
MAP_Timer_A_startCounter(TIMER_A3_BASE, TIMER_A_CONTINUOUS_MODE);
MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);
MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig1);
while(true) //Rotina principal
{
}
}
void PORT1_IRQHandler(void)
{
uint32_t status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, status);
uint32_t txdatatemp = 0xff;
MAP_UART_transmitData(EUSCI_A0_BASE, txdatatemp);
}
/* EUSCI A0 UART ISR - Echoes data back to PC host */
void EUSCIA0_IRQHandler(void)
{
uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE);
uint32_t TXdata = 0x00;
TXdata = MAP_UART_receiveData(EUSCI_A0_BASE);
MAP_UART_clearInterruptFlag(EUSCI_A0_BASE, status);
if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG)
{ //Se verdadeiro
if(TXdata == 0xAA)
{
Cont = 1;
}
else
{
if (TXdata == 0x55)
{
atualizapwm1 = true;
Cont = 0;
}
else
{
if(TXdata == 0x5A)
{
atualizapwm2 = true;
Cont = 0;
}
else
{
if (Cont == 1)
{
matriz1 [1] = TXdata;
MAP_UART_transmitData(EUSCI_A0_BASE, TXdata);
Cont = 2;
}
else
{
if (Cont == 2)
{
matriz1 [2] = TXdata;
MAP_UART_transmitData(EUSCI_A0_BASE, TXdata);
}
}
}
}
}
}
}
//******************************************************************************
//
//This is the TIMERA interrupt vector service routine.
//
//******************************************************************************
void TA3_N_IRQHandler(void)
{
MAP_Timer_A_clearInterruptFlag(TIMER_A3_BASE);
MAP_UART_transmitData(EUSCI_A0_BASE, 0xff);
if(atualizapwm1 == true)
{
pwmConfig.timerPeriod = matriz1[1] * 0xf1;
pwmConfig.dutyCycle = matriz1[2] * (pwmConfig.timerPeriod/0x64);
MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);
MAP_UART_transmitData(EUSCI_A0_BASE, 0x06);
atualizapwm1 = false;
}
else
{
if(atualizapwm2 == true)
{
pwmConfig1.timerPeriod = matriz1[1] * 0xf1;
pwmConfig1.dutyCycle = matriz1[2] * (pwmConfig1.timerPeriod/0x64);
MAP_Timer_A_generatePWM(TIMER_A1_BASE, &pwmConfig1);
MAP_UART_transmitData(EUSCI_A0_BASE, 0x05);
atualizapwm2 = false;
}
}
}

