Hi,
The CLAsin function from CLAmath library didn't work properly in my project, so I did a few simple experiments.
Here is the testing conditions:
Note: I only used Task1 in my experiments, and CLA_isr was triggered by EPWM1A
========================================================================================
In the Main source file:
#pragma DATA_SECTION(sineStep, "CpuToCla1MsgRAM"); float sineStep;
#pragma DATA_SECTION(SinePointCounter, "Cla1DataRAM"); Uint16 SinePointCounter;
Main ( )
{
Initialize the system and everything necessary.
.............................................
SinePointCounter = 1;
Initialize CLA registers
( note: Cla1Regs.MMEMCFG.bit.RAM1E = 1; )
sineStep = 0.0138396;
..............................................
Enable the things necessary.
}
=============================================================================================
In the "CLAShared.h" file:
extern Uint16 SinePointCounter;
extern float sineStep;
................................
==============================================================================================
In the "CLA.asm" file:
.cdecls C,LIST,"CLAShared.h"
.include "CLAmathLib_type0.inc"CLA_DEBUG .set 1 .sect "Cla1Prog" .align 2_Cla1Prog_Start:
_Cla1Task1: .if CLA_DEBUG == 1 MDEBUGSTOP .endif
..................................................................................................
Experiments Content ---- See bottom
.................................................................................................
MSTOP ; end of task (20) MNOP MNOP MNOP_Cla1T1End:
===================================================================================================
Experiments Content
experiment1:
MMOV32 MR0, @_SinePointCounter
CLAsin result, sineStep
.......................................................
In the watch window, SinePointCounter is equal to 1 ( correct), and result is also correct.
experiment2:
MMOV32 @_SinePointCounter, MR0
.........................................................................................
experiment3:
In the watch window, SinePointCounter is equal to 0 ( Wrong ) , and result is correct.
I hope someone could help me understand why Experiment #3 didn't work.
Thank you.
Here is my Linker file.
Note: It is a modifed version of the linker from the Cla_Adc example in ControlSUITE. (By the way, I am using TMS320F28035)
//*************************************************************************************************
MEMORY{PAGE 0 : /* BEGIN is used for the "boot to SARAM" bootloader mode */ BEGIN : origin = 0x000000, length = 0x000002 RAMM0 : origin = 0x000050, length = 0x0003B0 RAML0L1 : origin = 0x008000, length = 0x000C00 RAML3 : origin = 0x009000, length = 0x001000 RESET : origin = 0x3FFFC0, length = 0x000002 IQTABLES : origin = 0x3FE000, length = 0x000B50 /* IQ Math Tables in Boot ROM */ IQTABLES2 : origin = 0x3FEB50, length = 0x00008C /* IQ Math Tables in Boot ROM */ IQTABLES3 : origin = 0x3FEBDC, length = 0x0000AA /* IQ Math Tables in Boot ROM */ BOOTROM : origin = 0x3FF27C, length = 0x000D44PAGE 1 : BOOT_RSVD : origin = 0x000002, length = 0x00004E /* Part of M0, BOOT rom will use this for stack */ RAMM1 : origin = 0x000480, length = 0x000380 /* on-chip RAM block M1 */ RAML2 : origin = 0x008C00, length = 0x000400 CLA1_MSGRAMLOW : origin = 0x001480, length = 0x000080 CLA1_MSGRAMHIGH : origin = 0x001500, length = 0x000080}SECTIONS{ /* Setup for "boot to SARAM" mode: The codestart section (found in DSP28_CodeStartBranch.asm) re-directs execution to the start of user code. */ codestart : > BEGIN, PAGE = 0 ramfuncs : > RAMM0 PAGE = 0 .text : > RAML0L1, PAGE = 0 .cinit : > RAMM0, PAGE = 0 .pinit : > RAMM0, PAGE = 0 .switch : > RAMM0, PAGE = 0 .reset : > RESET, PAGE = 0, TYPE = DSECT /* not used, */ .stack : > RAMM1, PAGE = 1 .ebss : > RAML0L1, PAGE = 0 .econst : > RAML0L1, PAGE = 0 .esysmem : > RAML0L1, PAGE = 0 CLAmathTables : > RAML2, PAGE = 1 IQmath : > RAML0L1, PAGE = 0 IQmathTables : > IQTABLES, PAGE = 0, TYPE = NOLOAD Cla1Prog : LOAD = RAML0L1, RUN = RAML3, LOAD_START(_Cla1funcsLoadStart), LOAD_END(_Cla1funcsLoadEnd), RUN_START(_Cla1funcsRunStart), PAGE = 0 Cla1ToCpuMsgRAM : > CLA1_MSGRAMLOW, PAGE = 1 CpuToCla1MsgRAM : > CLA1_MSGRAMHIGH, PAGE = 1 Cla1DataRAM : > RAML2, PAGE = 1
Frank,
The macro CLAsin does not do a context save/restore operation on the registers MR0-MR3. It changes MR0 which is why you are seeing an incorrect value when you write to SinePointCounter
Regards,
Vishal
Hi Vishal,
Thank you for pointing that out. That is really important for me to know. But the question now is how I can use CLAsin in the middle of my code ?
Is that the limitation of using CLAsin or other functions from CLAmath library? only at the beginning or at the end of the task?
Could you maybe show me an example which is little bit more complicated than the example in ControlSUITE? The existing CLAmath examples are too simple, and there is only one operation in each task, so it would never reveal this kind of issue.
You can save and restore the registers in code as follows. In the CLA.asm file:
;declare these at the top of the file
_sin_tmp1 .usect "Cla1DataRAM",2_sin_tmp2 .usect "Cla1DataRAM",2
_sin_tmp3 .usect "Cla1DataRAM",2_sin_tmp4 .usect "Cla1DataRAM",2
;define the following macros
CONTEXT_SAVE .macro
MMOV32 @_sin_tmp1,MR0
MMOV32 @_sin_tmp2,MR1
MMOV32 @_sin_tmp3,MR2
MMOV32 @_sin_tmp4,MR3
.endm
CONTEXT_RESTORE .macro
MMOV32 MR0,@_sin_tmp1
MMOV32 MR1,@_sin_tmp2
MMOV32 MR2,@_sin_tmp3
MMOV32 MR3,@_sin_tmp4
;You can wrap these macros around the CLAsin macro
CONTEXT_SAVE
CLAsin result,SinePointer
CONTEXT_RESTORE
The new compiler, 6.1.0 supports C code on the CLA and is currently available through CCS. In the next few days, v400 of the CLAmath library will be releasing on controlSUITE. It provides C wrappers for all the routines and allows them to be called from within a task.
Thank you so much for your help.