Other Parts Discussed in Thread: SYSCONFIG
This code includes the necessary logic for receiving duty cycle input from the user through the SCI module, calculating a new compare value based on the entered duty cycle, and updating the ePWM duty cycle accordingly. I configured SCIA , epwm0 and ecap modules in SYSconfig tool. But i am not getting the expected OUTPUT in the console.
Please refer the attached code and screen shots, please let me know how to implement the logic and what changes do i need to make in my code
//
// Included Files
//
#include "driverlib.h"
#include "device.h"
#include "board.h"
uint32_t ePwm_TimeBase;
uint32_t ePwm_MinDuty;
uint32_t ePwm_MaxDuty;
uint32_t ePwm_curDuty;
uint32_t eCapPwmDuty; // Percent = (eCapPwmDuty/eCapPwmPeriod)*100.
uint32_t eCapPwmPeriod; // Frequency = DEVICE_SYSCLK_FREQ/eCapPwmPeriod.
uint16_t newDutyCycle;
__interrupt void INT_myECAP0_ISR(void);
void main(void)
{
Device_init();
Interrupt_initModule();
Interrupt_initVectorTable();
// Configure GPIO pins
//
Device_initGPIO();
//
// Initialize the SCI and Timer Modules
//
Board_init();
// Initialize variables for ePWM Duty Cycle
ePwm_TimeBase = EPWM_getTimeBasePeriod(myEPWM0_BASE);
ePwm_MinDuty = (uint32_t)(0.95f * (float)ePwm_TimeBase);
ePwm_MaxDuty = (uint32_t)(0.05f * (float)ePwm_TimeBase);
ePwm_curDuty = EPWM_getCounterCompareValue(myEPWM0_BASE, EPWM_COUNTER_COMPARE_A);
EINT;
ERTM;
//
// Define local variables for SCI
//
char* msg; // Message sent through the terminal window
char receivedChar; // Variable used to track input from the terminal window
uint16_t rxStatus = 0U; // Variable used to store the status of the SCI RX Register
for (;;)
{
msg = "\r\nEnter Duty cycle 0-100: \0";
SCI_writeCharArray(mySCIA_BASE, (uint16_t*)msg, 30);
//
// Read a character from the FIFO.
//
receivedChar = SCI_readCharBlockingFIFO(mySCIA_BASE);
SCI_writeCharBlockingFIFO(mySCIA_BASE, receivedChar);
DEVICE_DELAY_US(1000000);
// Convert character to digit
newDutyCycle = receivedChar - '0';
// Ensure duty cycle is within the valid range
if (newDutyCycle <= 100)
{
// Calculate new compare value based on duty cycle
uint32_t newCompareValue = (newDutyCycle * (ePwm_MaxDuty - ePwm_MinDuty) / 100) + ePwm_MinDuty;
// Update ePWM duty cycle
EPWM_setCounterCompareValue(myEPWM0_BASE, EPWM_COUNTER_COMPARE_A, (uint16_t)newCompareValue);
}
rxStatus = SCI_getRxStatus(mySCIA_BASE);
if ((rxStatus & SCI_RXSTATUS_ERROR) != 0)
{
//
// If Execution stops here there is some error
// Analyze SCI_getRxStatus() API return value
//
ESTOP0;
}
//
// Echo back the character.
//
msg = " Duty cycle set successfully! \0";
SCI_writeCharArray(mySCIA_BASE, (uint16_t*)msg, 31);
}
}
__interrupt void INT_myECAP0_ISR(void)
{
Interrupt_clearACKGroup(INT_myECAP0_INTERRUPT_ACK_GROUP);
ECAP_clearGlobalInterrupt(myECAP0_BASE);
ECAP_clearInterrupt(myECAP0_BASE, ECAP_ISR_SOURCE_CAPTURE_EVENT_3);
eCapPwmDuty = (int32_t)ECAP_getEventTimeStamp(myECAP0_BASE, ECAP_EVENT_2) -
(int32_t)ECAP_getEventTimeStamp(myECAP0_BASE, ECAP_EVENT_1);
eCapPwmPeriod = (int32_t)ECAP_getEventTimeStamp(myECAP0_BASE, ECAP_EVENT_3) -
(int32_t)ECAP_getEventTimeStamp(myECAP0_BASE, ECAP_EVENT_1);
}
