Part Number:TMS320F28027F
Tool/software: TI C/C++ Compiler
Dear TI members,
I am trying to run a code that runs an ADC (4ch), and saves it in a buffer with function DLOG_4ch. I created my project based on the template project from TI in controlSUITE (C:\ti\controlSUITE\development_kits\TemplateProjects), and I have followed the instructions to implement the ADC_4ch and the DLOG_4ch based on the Digital Power Library Manual v3.5. Unfortunately, I have been receiving the following error that I was not able to solve by myself:
undefined first referenced
symbol in file
--------- ----------------
_DLOG_4ch_BuffInit ./3ph_pwm_acdc-Main.obj
error: unresolved symbols remain
error: errors encountered during linking; "Project_Name.out" not built
>> Compilation failure
The "Project_Name.out" does not match my project name "3ph_pwm_adc", and I wish to fix that if I knew how, however this is not the real problem here. The main issue is that my main file calls the function DLOG_4ch_BuffInit even though it wasn't defined anywhere else. The manual skipped a step related to how the function should be defined. I also couldn't find the .c file of the DLOG_4ch function in the "CNF" folder of the digital power library for my type of microcontroller. I know that I could use the DLOG_4ch_IQ.c from the solar library, but I really don't know how I would interface that .c file with this project where every function is been used in .asm. At last, I tried defining it myself as void DLOG_4ch_BuffInit(int16 DBUFF[], int16 DLOG_4ch_Size); but that didn't work.
An insight on a)how I could define the DLOG_4ch function in my main.c, b)how I could fix the Project_name.out to display my project name, and c)How I could call .c functions inside my ISR (which is written in ASM) would be very welcome. My code is attached below. There is a state-machine setup that came with the template, but it is irrelevant at the moment.
//----------------------------------------------------------------------------------
// FILE: 3ph_pwm_acdc-Main.C
//
// Description: Sample Template file to edit
// The file drives duty on PWM1A using C28x
// These can be deleted and modifed by the user
// C28x ISR is triggered by the PWM 1 interrupt
//
// Version: 2.0
//
// Target: TMS320F2802x(PiccoloA),
//
//----------------------------------------------------------------------------------
// Copyright Texas Instruments © 2004-2010
//----------------------------------------------------------------------------------
// Revision History:
//----------------------------------------------------------------------------------
// Date | Description / Status
//----------------------------------------------------------------------------------
// October 2010 - Sample template project with DPLib v3 (MB)
//----------------------------------------------------------------------------------
//
// PLEASE READ - Useful notes about this Project
// Although this project is made up of several files, the most important ones are:
// "{3ph_pwm_acdc}-Main.C" - this file
// - Application Initialization, Peripheral config,
// - Application management
// - Slower background code loops and Task scheduling
// "{3ph_pwm_acdc}-DevInit_F28xxx.C
// - Device Initialization, e.g. Clock, PLL, WD, GPIO mapping
// - Peripheral clock enables
// - DevInit file will differ per each F28xxx device series, e.g. F280x, F2833x,
// "{3ph_pwm_acdc}-DPL-ISR.asm
// - Assembly level library Macros and any cycle critical functions are found here
// "{3ph_pwm_acdc}-DPL-CLA.asm"
// - Init code for DPlib CLA Macros run by C28x
// - CLA Task code
// "{3ph_pwm_acdc}-Settings.h"
// - Global defines (settings) project selections are found here
// - This file is referenced by both C and ASM files.
// "{3ph_pwm_acdc}-CLAShared.h.h"
// - Variable defines and header includes that are shared b/w CLA and C28x
//
// Code is made up of sections, e.g. "FUNCTION PROTOTYPES", "VARIABLE DECLARATIONS" ,..etc
// each section has FRAMEWORK and USER areas.
// FRAMEWORK areas provide useful ready made "infrastructure" code which for the most part
// does not need modification, e.g. Task scheduling, ISR call, GUI interface support,...etc
// USER areas have functional example code which can be modified by USER to fit their appl.
//
// Code can be compiled with various build options (Incremental Builds IBx), these
// options are selected in file "{ProjectName}-Settings.h". Note: "Rebuild All" compile
// tool bar button must be used if this file is modified.
//----------------------------------------------------------------------------------
#include "3ph_pwm_acdc-Settings.h"
#include "PeripheralHeaderIncludes.h"
#include "DSP2802x_EPWM_defines.h"
#include "DPlib.h"
#include "IQmathLib.h"
#define DLOG_SIZE 200
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// FUNCTION PROTOTYPES
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Add protoypes of functions being used in the project here
void DeviceInit(void);
#ifdef FLASH
void InitFlash();
#endif
void MemCopy();
//-------------------------------- DPLIB --------------------------------------------
void PWM_1ch_CNF(int16 n, int16 period, int16 mode, int16 phase);
void ADC_SOC_CNF(int ChSel[], int Trigsel[], int ACQPS[], int IntChSel, int mode);
// -------------------------------- FRAMEWORK --------------------------------------
// State Machine function prototypes
//----------------------------------------------------------------------------------
// Alpha states
void A0(void); //state A0
void B0(void); //state B0
void C0(void); //state C0
// A branch states
void A1(void); //state A1
void A2(void); //state A2
void A3(void); //state A3
void A4(void); //state A4
// B branch states
void B1(void); //state B1
void B2(void); //state B2
void B3(void); //state B3
void B4(void); //state B4
// C branch states
void C1(void); //state C1
void C2(void); //state C2
void C3(void); //state C3
void C4(void); //state C4
// Variable declarations
void (*Alpha_State_Ptr)(void); // Base States pointer
void (*A_Task_Ptr)(void); // State pointer A branch
void (*B_Task_Ptr)(void); // State pointer B branch
void (*C_Task_Ptr)(void); // State pointer C branch
//----------------------------------------------------------------------------------
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - GENERAL
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// -------------------------------- FRAMEWORK --------------------------------------
int16 VTimer0[4]; // Virtual Timers slaved off CPU Timer 0
int16 VTimer1[4]; // Virtual Timers slaved off CPU Timer 1
int16 VTimer2[4]; // Virtual Timers slaved off CPU Timer 2
// Used for running BackGround in flash, and ISR in RAM
extern Uint16 *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
// Used for copying CLA code from load location to RUN location
extern Uint16 Cla1funcsLoadStart, Cla1funcsLoadEnd, Cla1funcsRunStart;
// Used for ADC Configuration
int ChSel[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int TrigSel[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int ACQPS[16] = {7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7}; //always 7+1 cycles
// Used to indirectly access all EPWM modules
volatile struct EPWM_REGS *ePWM[] =
{ &EPwm1Regs, //intentional: (ePWM[0] not used)
&EPwm1Regs,
&EPwm2Regs,
&EPwm3Regs,
&EPwm4Regs,
};
// Used to indirectly access all Comparator modules
volatile struct COMP_REGS *Comp[] =
{ &Comp1Regs, //intentional: (Comp[0] not used)
&Comp1Regs,
&Comp2Regs,
};
// ---------------------------------- USER -----------------------------------------
// ---------------------------- DPLIB Net Pointers ---------------------------------
// Declare net pointers that are used to connect the DP Lib Macros here
// PWMDRV_1ch
extern volatile long *PWMDRV_1ch_Duty1; // instance #1, EPWM1
//ADCDRV_4ch
volatile long *ADCDRV_4ch_RltA; //I removed EXTERN
volatile long *ADCDRV_4ch_RltB;
volatile long *ADCDRV_4ch_RltC;
volatile long *ADCDRV_4ch_RltD;
//DLOG_4ch - instance #1
extern volatile long *DLOG_4ch_i1Ptr;
extern volatile long *DLOG_4ch_i2Ptr;
extern volatile long *DLOG_4ch_i3Ptr;
extern volatile long *DLOG_4ch_i4Ptr;
extern volatile int16 *DLOG_4ch_buff1Ptr;
extern volatile int16 *DLOG_4ch_buff2Ptr;
extern volatile int16 *DLOG_4ch_buff3Ptr;
extern volatile int16 *DLOG_4ch_buff4Ptr;
extern volatile long DLOG_4ch_TrigVal;
extern volatile int16 DLOG_4ch_PreScalar;
extern volatile int16 DLOG_4ch_Size;
// ---------------------------- DPLIB Variables ---------------------------------
// Declare the net variables being used by the DP Lib Macro here
//PWM
volatile long Duty1A;
//ADC 4ch
volatile long RltA,RltB,RltC,RltD;
//DLOG_4CH
#pragma DATA_SECTION(DBUFF1,"DLOG_BUFF");
#pragma DATA_SECTION(DBUFF2,"DLOG_BUFF");
#pragma DATA_SECTION(DBUFF3,"DLOG_BUFF");
#pragma DATA_SECTION(DBUFF4,"DLOG_BUFF");
volatile int16 DBUFF1[DLOG_SIZE];
volatile int16 DBUFF2[DLOG_SIZE];
volatile int16 DBUFF3[DLOG_SIZE];
volatile int16 DBUFF4[DLOG_SIZE];
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - CCS WatchWindow / GUI support
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// -------------------------------- FRAMEWORK --------------------------------------
//GUI support variables
// sets a limit on the amount of external GUI controls - increase as necessary
int16 *varSetTxtList[16]; //16 textbox controlled variables
int16 *varSetBtnList[16]; //16 button controlled variables
int16 *varSetSldrList[16]; //16 slider controlled variables
int16 *varGetList[16]; //16 variables sendable to GUI
int16 *arrayGetList[16]; //16 arrays sendable to GUI
int16 LedBlinkCnt;
// ---------------------------------- USER -----------------------------------------
// Monitor ("Get") // Display as:
// Configure ("Set")
// History arrays are used for Running Average calculation (boxcar filter)
// Used for CCS display and GUI only, not part of control loop processing
//Scaling Constants (values found via spreadsheet; exact value calibrated per board)
// Variables for background support only (no need to access)
int16 i; // common use incrementer
Uint32 HistPtr, temp_Scratch; // Temp here means Temporary
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// MAIN CODE - starts here
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void main(void)
{
//=================================================================================
// INITIALISATION - General
//=================================================================================
// The DeviceInit() configures the clocks and pin mux registers
// The function is declared in {ProjectName}-DevInit_F2803/2x.c,
// Please ensure/edit that all the desired components pin muxes
// are configured properly that clocks for the peripherals used
// are enabled, for example the individual PWM clock must be enabled
// along with the Time Base Clock
DeviceInit(); // Device Life support & GPIO
//-------------------------------- FRAMEWORK --------------------------------------
// Only used if running from FLASH
// Note that the variable FLASH is defined by the compiler with -d FLASH
#ifdef FLASH
// Copy time critical code and Flash setup code to RAM
// The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
// symbols are created by the linker. Refer to the linker files.
MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
// Call Flash Initialization to setup flash waitstates
// This function must reside in RAM
InitFlash(); // Call the flash wrapper init function
#endif //(FLASH)
// Timing sync for background loops
// Timer period definitions found in PeripheralHeaderIncludes.h
CpuTimer0Regs.PRD.all = mSec1; // A tasks
CpuTimer1Regs.PRD.all = mSec10; // B tasks
CpuTimer2Regs.PRD.all = mSec100; // C tasks
// Tasks State-machine init
Alpha_State_Ptr = &A0;
A_Task_Ptr = &A1;
B_Task_Ptr = &B1;
C_Task_Ptr = &C1;
VTimer0[0] = 0;
VTimer1[0] = 0;
VTimer2[0] = 0;
LedBlinkCnt = 5;
// ---------------------------------- USER -----------------------------------------
// put common initialization/variable definitions here
//===============================================================================
// INITIALISATION - GUI connections
//=================================================================================
// Use this section only if you plan to "Instrument" your application using the
// Microsoft C# freeware GUI Template provided by TI
/*
//"Set" variables
//---------------------------------------
// assign GUI variable Textboxes to desired "setable" parameter addresses
varSetTxtList[0] = &Gui_TxtListVar;
varSetTxtList[1] = &Gui_TxtListVar;
varSetTxtList[2] = &Gui_TxtListVar;
varSetTxtList[3] = &Gui_TxtListVar;
varSetTxtList[4] = &Gui_TxtListVar;
varSetTxtList[5] = &Gui_TxtListVar;
varSetTxtList[6] = &Gui_TxtListVar;
varSetTxtList[7] = &Gui_TxtListVar;
varSetTxtList[8] = &Gui_TxtListVar;
varSetTxtList[9] = &Gui_TxtListVar;
varSetTxtList[10] = &Gui_TxtListVar;
varSetTxtList[11] = &Gui_TxtListVar;
// assign GUI Buttons to desired flag addresses
varSetBtnList[0] = &Gui_BtnListVar;
varSetBtnList[1] = &Gui_BtnListVar;
varSetBtnList[2] = &Gui_BtnListVar;
varSetBtnList[3] = &Gui_BtnListVar;
varSetBtnList[4] = &Gui_BtnListVar;
// assign GUI Sliders to desired "setable" parameter addresses
varSetSldrList[0] = &Gui_SldrListVar;
varSetSldrList[1] = &Gui_SldrListVar;
varSetSldrList[2] = &Gui_SldrListVar;
varSetSldrList[3] = &Gui_SldrListVar;
varSetSldrList[4] = &Gui_SldrListVar;
//"Get" variables
//---------------------------------------
// assign a GUI "getable" parameter address
varGetList[0] = &Gui_GetListVar;
varGetList[1] = &Gui_GetListVar;
varGetList[2] = &Gui_GetListVar;
varGetList[3] = &Gui_GetListVar;
varGetList[4] = &Gui_GetListVar;
varGetList[5] = &Gui_GetListVar;
varGetList[6] = &Gui_GetListVar;
varGetList[7] = &Gui_GetListVar;
varGetList[8] = &Gui_GetListVar;
varGetList[9] = &Gui_GetListVar;
varGetList[10] = &Gui_GetListVar;
varGetList[11] = &Gui_GetListVar;
varGetList[12] = &Gui_GetListVar;
varGetList[13] = &Gui_GetListVar;
varGetList[14] = &Gui_GetListVar;
varGetList[15] = &Gui_GetListVar;
// assign a GUI "getable" parameter array address
arrayGetList[0] = &DBUFF1; //only need to set initial position of array,
arrayGetList[1] = &DBUFF2; // program will run through it accordingly
arrayGetList[2] = &DBUFF3;
arrayGetList[3] = &DBUFF4;
*/
//==================================================================================
// INCREMENTAL BUILD OPTIONS - NOTE: selected via {ProjectName-Settings.h
//==================================================================================
// ---------------------------------- USER -----------------------------------------
//----------------------------------------------------------------------
#if (INCR_BUILD == 1) // Open Loop Two Phase Interleaved PFC PWM Driver
//----------------------------------------------------------------------
// Configure PWM1 for 200Khz (Period Count= 60Mhz/200Khz = 300)
PWM_1ch_CNF(1, 300,1,0);
//==================================================================================
// CALLING THE ADC INITIALIZATION FUNCTION
//==================================================================================
/* Configure ADC channel 0 to convert ADCINA1, and ADC channel 1 to convert the ADCINA3, ADC Channel 2 converts ADCINA7 and ADC channel 5 converts ADCINB2. The ADC is configured in start stop mode and ADC Interrupt is disabled. ADC Channel 0,2 is configured to use PWM1 SOCA and channel 1,5 is configured to use PWM 5 SOCB as trigger. The following code snippet assumes that the PWM peripherals have been configured appropriately to generate a SOCA and SOCB */
// Specify ADC Channel – pin Selection for Configuring the ADC
//Map channel to ADC Pin - (SETS ADCRESULT TO RESPECTIVE PHYSICAL PORT IN LAUNCHPAD)
ChSel[0] = 1; // ADC A1
ChSel[1] = 3; // ADC A3
ChSel[2] = 9; // ADC B1
ChSel[3] = 11; // ADC B3
//1 -> A1 (ASSUMED)
//3 -> A3
//7 -> A7
//9 -> B2 (ASSUMED)
//10 -> B3
//14 -> B6
// for additional ADC conversions modify below
/*ChSel[1]=n; //An
ChSel[2]=n; //An
ChSel[3]=n; //An
ChSel[4]=n; //An
ChSel[5]=n; //An
ChSel[6]=n; //An
ChSel[7]=n; //An
ChSel[8]=n; //An
ChSel[9]=n; //An
ChSel[10]=n; //An
ChSel[11]=n; //An
ChSel[12]=n; //An
ChSel[13]=n; //An
ChSel[14]=n; //An
ChSel[15]=n; //An
*/
// Select Trigger Event for ADC conversion
// Specify the Conversion Trigger for each channel
TrigSel[0]= ADCTRIG_EPWM1_SOCA; //this is a macro that gives us 5
TrigSel[1]= ADCTRIG_EPWM1_SOCA;
TrigSel[2]= ADCTRIG_EPWM1_SOCA;
TrigSel[3]= ADCTRIG_EPWM1_SOCA;
// associate the appropriate peripheral trigger to the ADC channel
/*TrigSel[1]= ADCTRIG_EPWMn_SOCA;
TrigSel[2]= ADCTRIG_EPWMn_SOCA;
TrigSel[3]= ADCTRIG_EPWMn_SOCA;
TrigSel[4]= ADCTRIG_EPWMn_SOCA;
TrigSel[5]= ADCTRIG_EPWMn_SOCA;
TrigSel[6]= ADCTRIG_EPWMn_SOCA;
TrigSel[7]= ADCTRIG_EPWMn_SOCA;
TrigSel[8]= ADCTRIG_EPWMn_SOCA;
TrigSel[9]= ADCTRIG_EPWMn_SOCA;
TrigSel[10]= ADCTRIG_EPWMn_SOCA;
TrigSel[11]= ADCTRIG_EPWMn_SOCA;
TrigSel[12]= ADCTRIG_EPWMn_SOCA;
TrigSel[13]= ADCTRIG_EPWMn_SOCA;
TrigSel[14]= ADCTRIG_EPWMn_SOCA;
TrigSel[15]= ADCTRIG_EPWMn_SOCA;*/
// Configure the ADC with auto interrupt clear mode
// ADC interrupt after EOC of channel 0
ADC_SOC_CNF(ChSel,TrigSel,ACQPS,0,0);
// Function arguments defined as:
//-------------------------------
// ChSel[] = Channel selection made via a channel # array passed as an argument
// TrigSel[]= Source for triggering conversion of a channel,
// selection made via a trigger # array passed as argument
// ACQPS[] = AcqWidth is the S/H aperture in #ADCCLKS,# array passed as argument
// IntChSel = Channel number that would trigger an ADC Interrupt 1 on completion(EOC)
// if no channel triggers ADC interrupt pass value > 15
// Mode = Operating mode: 0 = Start / Stop mode, needs trigger event
// 1 = Continuous mode, no trigger needed
// 2 = CLA Mode, start stop mode with auto clr INT Flag
//================================================================================
// Configure the EPWM1 to issue the SOC
EPwm1Regs.ETSEL.bit.SOCAEN = 1;
EPwm1Regs.ETSEL.bit.SOCASEL = ET_CTR_PRD; // Use PRD event as trigger for ADC SOC
EPwm1Regs.ETPS.bit.SOCAPRD = ET_1ST; // Generate pulse on every event
// Call the ADC Configuration Function
ADC_SOC_CNF(ChSel,TrigSel,ACQPS,1,0);
// Digital Power CLA(DP) library initialisation
DPL_Init();
//----------------------------------------
// Lib Module connection to "nets"
//----------------------------------------
// Connect the PWM Driver input to an input variable, Open Loop System
PWMDRV_1ch_Duty1 = &Duty1A;
// ADCDRV_4ch block connections
ADCDRV_4ch_RltA=&RltA;
ADCDRV_4ch_RltB=&RltB;
ADCDRV_4ch_RltC=&RltC;
ADCDRV_4ch_RltD=&RltD;
// Setup Size, Trigger Value and Pre Scalar
DLOG_4ch_TrigVal = _IQ(0.1);
DLOG_4ch_PreScalar = 25;
DLOG_4ch_Size=DLOG_SIZE;
// Initialize the net variables
Duty1A =_IQ24(0.4); //PWM
RltA=_IQ24(0.0); //ADC
RltB=_IQ24(0.0); //ADC
RltC=_IQ24(0.0); //ADC
RltD=_IQ24(0.0); //ADC
DLOG_4ch_BuffInit(DBUFF1, DLOG_SIZE);
DLOG_4ch_BuffInit(DBUFF2, DLOG_SIZE);
DLOG_4ch_BuffInit(DBUFF3, DLOG_SIZE);
DLOG_4ch_BuffInit(DBUFF4, DLOG_SIZE);
DLOG_4ch_i1Ptr =ADCDRV_4ch_RltA;
DLOG_4ch_i2Ptr =ADCDRV_4ch_RltB;
DLOG_4ch_i3Ptr =ADCDRV_4ch_RltC;
DLOG_4ch_i4Ptr =ADCDRV_4ch_RltD;
// Point the BuffPtr to the buffer location
DLOG_4ch_buff1Ptr =DBUFF1;
DLOG_4ch_buff2Ptr =DBUFF2;
DLOG_4ch_buff3Ptr =DBUFF3;
DLOG_4ch_buff4Ptr =DBUFF4;
#endif // (INCR_BUILD == 1)
//====================================================================================
// INTERRUPTS & ISR INITIALIZATION (best to run this section after other initialization)
//====================================================================================
// Set up C28x Interrupt
//Also Set the appropriate # define's in the {ProjectName}-Settings.h
//to enable interrupt management in the ISR
EALLOW;
PieVectTable.EPWM1_INT = &DPL_ISR; // Map Interrupt
PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // PIE level enable, Grp3 / Int1
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_PRD; // INT on PRD event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on every event
IER |= M_INT3; // Enable CPU INT3 connected to EPWM1-6 INTs:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
EDIS;
//=================================================================================
// BACKGROUND (BG) LOOP
//=================================================================================
//--------------------------------- FRAMEWORK -------------------------------------
for(;;) //infinite loop
{
// State machine entry & exit point
//===========================================================
(*Alpha_State_Ptr)(); // jump to an Alpha state (A0,B0,...)
//===========================================================
}
} //END MAIN CODE
//=================================================================================
// STATE-MACHINE SEQUENCING AND SYNCRONIZATION
//=================================================================================
//--------------------------------- FRAMEWORK -------------------------------------
void A0(void)
{
// loop rate synchronizer for A-tasks
if(CpuTimer0Regs.TCR.bit.TIF == 1)
{
CpuTimer0Regs.TCR.bit.TIF = 1; // clear flag
//-----------------------------------------------------------
(*A_Task_Ptr)(); // jump to an A Task (A1,A2,A3,...)
//-----------------------------------------------------------
VTimer0[0]++; // virtual timer 0, instance 0 (spare)
}
Alpha_State_Ptr = &B0; // Comment out to allow only A tasks
}
void B0(void)
{
// loop rate synchronizer for B-tasks
if(CpuTimer1Regs.TCR.bit.TIF == 1)
{
CpuTimer1Regs.TCR.bit.TIF = 1; // clear flag
//-----------------------------------------------------------
(*B_Task_Ptr)(); // jump to a B Task (B1,B2,B3,...)
//-----------------------------------------------------------
VTimer1[0]++; // virtual timer 1, instance 0 (spare)
}
Alpha_State_Ptr = &C0; // Allow C state tasks
}
void C0(void)
{
// loop rate synchronizer for C-tasks
if(CpuTimer2Regs.TCR.bit.TIF == 1)
{
CpuTimer2Regs.TCR.bit.TIF = 1; // clear flag
//-----------------------------------------------------------
(*C_Task_Ptr)(); // jump to a C Task (C1,C2,C3,...)
//-----------------------------------------------------------
VTimer2[0]++; //virtual timer 2, instance 0 (spare)
}
Alpha_State_Ptr = &A0; // Back to State A0
}
//=================================================================================
// A - TASKS
//=================================================================================
//--------------------------------------------------------
void A1(void)
//--------------------------------------------------------
{
//-------------------
//the next time CpuTimer0 'counter' reaches Period value go to A2
A_Task_Ptr = &A2;
//-------------------
}
//-----------------------------------------------------------------
void A2(void)
//-----------------------------------------------------------------
{
//-------------------
//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A3;
//-------------------
}
//-----------------------------------------
void A3(void)
//-----------------------------------------
{
//-----------------
//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A4;
//-----------------
}
//----------------------------------------------------------
void A4(void)
//---------------------------------------------------------
{
//-----------------
//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A1;
//-----------------
}
//=================================================================================
// B - TASKS
//=================================================================================
//----------------------------------- USER ----------------------------------------
//----------------------------------------
void B1(void)
//----------------------------------------
{
//-----------------
//the next time CpuTimer1 'counter' reaches Period value go to B2
B_Task_Ptr = &B2;
//-----------------
}
//----------------------------------------
void B2(void) // Blink LED on the control CArd
//----------------------------------------
{
if(LedBlinkCnt==0)
{
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; //turn on/off LD3 on the controlCARD
LedBlinkCnt=5;
}
else
LedBlinkCnt--;
//-----------------
//the next time CpuTimer1 'counter' reaches Period value go to B3
B_Task_Ptr = &B3;
//-----------------
}
//----------------------------------------
void B3(void)
//----------------------------------------
{
//-----------------
//the next time CpuTimer1 'counter' reaches Period value go to B4
B_Task_Ptr = &B4;
//-----------------
}
//----------------------------------------
void B4(void) // SPARE
//----------------------------------------
{
//-----------------
//the next time CpuTimer1 'counter' reaches Period value go to B1
B_Task_Ptr = &B1;
//-----------------
}
//=================================================================================
// C - TASKS
//=================================================================================
//--------------------------------- USER ------------------------------------------
//------------------------------------------------------
void C1(void)
//------------------------------------------------------
{
//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C2
C_Task_Ptr = &C2;
//-----------------
}
//----------------------------------------
void C2(void)
//----------------------------------------
{
//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C3
C_Task_Ptr = &C3;
//-----------------
}
//-----------------------------------------
void C3(void)
//-----------------------------------------
{
//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C4
C_Task_Ptr = &C4;
//-----------------
}
//-----------------------------------------
void C4(void) // SPARE
//-----------------------------------------
{
//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C1
C_Task_Ptr = &C1;
//-----------------
}
MY ISR Code:
;----------------------------------------------------------------------------------
; FILE: {3ph_pwm_acdc}-DPL-ISR.asm
;
; Description: {3ph_pwm_acdc}-DPL-ISR.asm contains the ISR for the system
; It also contains the initailization routine for all the macros
; being used in the system both for CLA and C28x macros
;
; Revision/ Version: See {3ph_pwm_acdc}-Main.c
;----------------------------------------------------------------------------------
;Gives peripheral addresses visibility in assembly
.cdecls C,LIST,"PeripheralHeaderIncludes.h"
;include C header file - sets INCR_BUILD etc.(used in conditional builds)
.cdecls C,NOLIST, "3ph_pwm_acdc-Settings.h"
;Include files for the Power Library Maco's being used by the system
.include "PWMDRV_1ch.asm"
.include "ADCDRV_4ch.asm"
.include "DLOG_4ch.asm"
;=============================================================================
; Digital Power library - Initailization Routine
;=============================================================================
; label to DP initialisation function
.def _DPL_Init
; dummy variable for pointer initialisation
ZeroNet .usect "ZeroNet_Section",2,1,1 ; output terminal 1
.text
_DPL_Init:
ZAPA
MOVL XAR0, #ZeroNet
MOVL *XAR0, ACC
; Initialize all the DP library macro used here
;---------------------------------------------------------
.if(INCR_BUILD = 1)
PWMDRV_1ch_INIT 1 ; PWM1A
.endif
;---------------------------------------------------------
ADCDRV_4ch_INIT 0,1,2,3 ; ADCDRV_4ch Initialization
DLOG_4ch_INIT 1 ; DLOG_4CH Initialization
LRETR
;-----------------------------------------------------------------------------------------
; Digital Power library - Interrupt Service Routine
.sect "ramfuncs"
; label to DP ISR Run function
.def _DPL_ISR
_DPL_ISR:
; full context save - push any unprotected registers onto stack
PUSH AR1H:AR0H
PUSH XAR2
PUSH XAR3
PUSH XAR4
PUSH XAR5
PUSH XAR6
PUSH XAR7
PUSH XT
SPM 0 ; set C28 mode
CLRC AMODE
CLRC PAGE0,OVM
; CLRC INTM ; clear interrupt mask - comment if ISR non-nestable
;-----------------------------------------------------------------------------------------
; call DP library modules
;---------------------------------------------------------
.if(INCR_BUILD = 1)
PWMDRV_1ch 1 ; PWM1A
.endif
;----------------------------------------------------------
ADCDRV_4ch 0,1,2,3 ; Run ADCDRV_4ch
DLOG_4ch 1 ; Run the DLOG_4CH Macro
;-----------------------------------------------------------------------------------------
; Interrupt management before exit
.if(EPWMn_DPL_ISR=1)
.if(EPWM1)
MOVW DP,#_EPwm1Regs.ETCLR
MOV @_EPwm1Regs.ETCLR,#0x01 ; Clear EPWM1 Int flag
.endif ; EPWM1
.if(EPWM2)
MOVW DP,#_EPwm2Regs.ETCLR
MOV @_EPwm2Regs.ETCLR,#0x01 ; Clear EPWM2 Int flag
.endif ; EPWM2
.if(EPWM3)
MOVW DP,#_EPwm3Regs.ETCLR
MOV @_EPwm3Regs.ETCLR,#0x01 ; Clear EPWM3 Int flag
.endif ; EPWM3
.if(EPWM4)
MOVW DP,#_EPwm4Regs.ETCLR
MOV @_EPwm4Regs.ETCLR,#0x01 ; Clear EPWM4 Int flag
.endif ; EPWM4
.if(EPWM5)
MOVW DP,#_EPwm5Regs.ETCLR
MOV @_EPwm5Regs.ETCLR,#0x01 ; Clear EPWM5 Int flag
.endif ; EPWM5
.if(EPWM6)
MOVW DP,#_EPwm6Regs.ETCLR
MOV @_EPwm6Regs.ETCLR,#0x01 ; Clear EPWM6 Int flag
.endif ; EPWM6
MOVW DP,#_PieCtrlRegs.PIEACK ; Acknowledge PIE interrupt Group 3
MOV @_PieCtrlRegs.PIEACK, #0x4
.endif ; EPWMn_ISR
.if(ADC_DPL_ISR=1)
; Case where ISR is triggered by ADC
MOVW DP,#_AdcRegs.ADCINTFLGCLR
MOV @_AdcRegs.ADCINTFLGCLR,#0x01 ; Clear ADCINT1 Flag
MOVW DP,#_PieCtrlRegs.PIEACK ; Acknowledge PIE interrupt Group 1
MOV @_PieCtrlRegs.PIEACK,#0x1
.endif
;-----------------------------------------------------------------------------------------
; full context restore
; SETC INTM ; set INTM to protect context restore
POP XT
POP XAR7
POP XAR6
POP XAR5
POP XAR4
POP XAR3
POP XAR2
POP AR1H:AR0H
IRET ; return from interrupt
.end
; end of file
Picture of the project's files:
![]()