Part Number: LAUNCHXL-F280039C
Other Parts Discussed in Thread: SYSCONFIG
Tool/software:
Hello Experts,
Condition:-
I am trying to toggle GPIO22 (LED5 on the Launch Pad - LAUNCHXL-F280039C) using CLA.
I have imported the given example project - "cla_ex4_pwm_control", which is available on the resource explorer
In the example project, I have made a few additions to configure GPIO22 (main.c) and tried to toggle the GPIO in the .cla file, but it is not working (toggling)
Question:-
I can see that the duty of EPWM varies, which ensures that the CLA task is executing; however, the GPIO does not toggle, which is present within the same CLA task.
main.c
//
// Included Files
//
#include <cla_ex4_pwm_control_shared.h>
#include "driverlib.h"
#include "device.h"
#include "board.h"
//
// Function Prototypes
//
void initEPWM(void);
void initCLA(void);
//
// Main
//
void main(void)
{
//
// Initialize device clock and peripherals
//
Device_init();
//
// Disable pin locks and enable internal pullups.
//
Device_initGPIO();
//
// GPIO0 is set to EPWM1A
// GPIO1 is set to EPWM1B
//
GPIO_setControllerCore(0, GPIO_CORE_CPU1);
GPIO_setPadConfig(0,GPIO_PIN_TYPE_STD);
GPIO_setPinConfig(GPIO_0_EPWM1_A);
GPIO_setControllerCore(1, GPIO_CORE_CPU1);
GPIO_setPadConfig(1,GPIO_PIN_TYPE_STD);
GPIO_setPinConfig(GPIO_1_EPWM1_B);
// Adding GPIO22 for toggle
GPIO_setAnalogMode(22,GPIO_ANALOG_DISABLED);
GPIO_setDirectionMode(22,GPIO_DIR_MODE_OUT);
GPIO_setQualificationMode(22,GPIO_QUAL_SYNC);
GPIO_setPinConfig(GPIO_22_GPIO22);
GPIO_setMasterCore(22, GPIO_CORE_CPU1_CLA1);
//
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
//
Interrupt_initModule();
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
Interrupt_initVectorTable();
//
// Disable sync(Freeze clock to PWM as well)
//
SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
//
// Initialize EPWM module
//
initEPWM();
//
// Initialize resources
//
Board_init();
initCLA();
//
// Enable global interrupts.
//
EINT;
//
// Enable sync and clock to PWM
//
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
for(;;)
{
}
}
//
// EPWM Initialization
// EPWM1 : generates output of frequency EPWM1_FREQ (100 KHz)
// EPWM4 : Triggers CLA task at frequency EPWM4_FREQ (10 KHz)
//
void initEPWM(void)
{
//
// Set up EPWM1 to
// - run on a base clock of SYSCLK
// - have a period of EPWM1_PERIOD
// - run in count up-down mode
//
EPWM_setClockPrescaler(EPWM1_BASE, EPWM_CLOCK_DIVIDER_1,
EPWM_HSCLOCK_DIVIDER_1);
EPWM_setTimeBasePeriod(EPWM1_BASE, EPWM1_PERIOD);
EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, EPWM1_PERIOD/10U);
EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP_DOWN);
EPWM_setTimeBaseCounter(EPWM1_BASE, 0U);
//
// Configuring action-qualifiers for EPWM1 to generate symmetric
// and complementary outputs on channel A and B
//
EPWM_setActionQualifierAction(EPWM1_BASE, EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
EPWM_setActionQualifierAction(EPWM1_BASE, EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
EPWM_setActionQualifierAction(EPWM1_BASE, EPWM_AQ_OUTPUT_B,
EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
EPWM_setActionQualifierAction(EPWM1_BASE, EPWM_AQ_OUTPUT_B,
EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
//
// Enabling Counter Compare shadow mode
//
EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_SYNC_CNTR_ZERO);
//
// Set up EPWM4 to
// - run on a base clock of SYSCLK
// - have a period of EPWM4_PERIOD
// - run in count up mode
EPWM_setClockPrescaler(EPWM4_BASE, EPWM_CLOCK_DIVIDER_1,
EPWM_HSCLOCK_DIVIDER_1);
EPWM_setTimeBasePeriod(EPWM4_BASE, EPWM4_PERIOD);
EPWM_setTimeBaseCounterMode(EPWM4_BASE, EPWM_COUNTER_MODE_UP);
EPWM_setTimeBaseCounter(EPWM4_BASE, 0U);
//
// Enabling EPWM4 interrupt at TBCTR = 0 to trigger
// CLA task
//
EPWM_setInterruptSource(EPWM4_BASE, EPWM_INT_TBCTR_ZERO);
EPWM_enableInterrupt(EPWM4_BASE);
EPWM_setInterruptEventCount(EPWM4_BASE, 1U);
//
// EPWM 1 and 4 should run freely in emulation mode
//
EPWM_setEmulationMode(EPWM1_BASE, EPWM_EMULATION_FREE_RUN);
EPWM_setEmulationMode(EPWM4_BASE, EPWM_EMULATION_FREE_RUN);
}
//
// CLA Initialization
//
void initCLA(void)
{
//
// Force task 8, the one time initialization task
//
CLA_forceTasks(CLA1_BASE, CLA_TASKFLAG_8);
}
.cla
//#############################################################################
//
// FILE: cla_ex4_pwm_control_cla.cla
//
// TITLE: Controlling PWM output using CLA
//
// Task 8 initializes the global variables for CLA
//
// Task 1 implements control logic to update duty value of PWM output
//
//#############################################################################
//
//
// $Copyright:
// Copyright (C) 2025 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <cla_ex4_pwm_control_shared.h>
#include <stdint.h>
#include "epwm.h"
#include "driverlib.h"
#include "device.h"
#include "board.h"
//
// Globals
//
// Note that the globals defined in the .cla source are global to the cla source
// file. i.e. they may be shared across tasks. But they cannot be assigned an
// initialized value here. To do so, one-time initialization task is used that
// is triggered by software at the beginning
//
// Duty value
float duty ;
//-----------------------------------------------------------------------------
//
// Task 1 - PWM control loop
//
// Description: PWM control logic can be implemented here.
//
//-----------------------------------------------------------------------------
__attribute__((interrupt)) void Cla1Task1 ( void )
{
HWREG(GPIODATA_BASE + GPIO_O_GPASET ) = 0x00400000UL;
//GPIO_writePin(22,0);
//
// Uncomment this to debug the CLA while connected to the debugger
//
//__mdebugstop();
//
// Write to the COMPA register to realize a particular duty value
//
EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A,
(uint16_t)(duty * EPWM1_PERIOD + 0.5f));
//
// Update duty value and use the limiter
//
duty += 0.1f;
duty = (duty > 0.9f) ? 0.1f : duty;
// volatile uint32_t i;
// for (i = 0; i < 20000000; i++)
// {
// // Empty loop for delay
// }
// volatile uint32_t j;
// for (j = 0; j < 20000000; j++)
// {
// // Empty loop for delay
// }
// volatile uint32_t k;
// for (k = 0; k < 20000000; k++)
// {
// // Empty loop for delay
// }
HWREG(GPIODATA_BASE + GPIO_O_GPACLEAR ) = 0x00400000UL;
//GPIO_writePin(22,1);
//
// Clear EPWM4 interrupt flag so that next interrupt can come in
//
EPWM_clearEventTriggerInterruptFlag(EPWM4_BASE);
}
//-----------------------------------------------------------------------------
//
// Task 2 - Title Here
//
// Description: Description/steps here.
//
//-----------------------------------------------------------------------------
__attribute__((interrupt)) void Cla1Task2 ( void )
{
}
//-----------------------------------------------------------------------------
//
// Task 3 - Title Here
//
// Description: Description/steps here.
//
//-----------------------------------------------------------------------------
__attribute__((interrupt)) void Cla1Task3 ( void )
{
}
//-----------------------------------------------------------------------------
//
// Task 4 - Title Here
//
// Description: Description/steps here.
//
//-----------------------------------------------------------------------------
__attribute__((interrupt)) void Cla1Task4 ( void )
{
}
//-----------------------------------------------------------------------------
//
// Task 5 - Title Here
//
// Description: Description/steps here.
//
//-----------------------------------------------------------------------------
__attribute__((interrupt)) void Cla1Task5 ( void )
{
}
//-----------------------------------------------------------------------------
//
// Task 6 - Title Here
//
// Description: Description/steps here.
//
//-----------------------------------------------------------------------------
__attribute__((interrupt)) void Cla1Task6 ( void )
{
}
//-----------------------------------------------------------------------------
//
// Task 7 - Title Here
//
// Description: Description/steps here.
//
//-----------------------------------------------------------------------------
__attribute__((interrupt)) void Cla1Task7 ( void )
{
}
//-----------------------------------------------------------------------------
//
// Task 8 - One Time Initialization Task
//
// Description: This task will initialize the CLA global variables
//
//-----------------------------------------------------------------------------
__attribute__((interrupt)) void Cla1Task8 ( void )
{
//
// Uncomment this to debug the CLA while connected to the debugger
//
//__mdebugstop();
duty = 0.1f;
}
//
// End of File
//


