This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280049C: How to directly read ADC result from CLA code (Post on behalf of a customer)

Part Number: TMS320F280049C
Other Parts Discussed in Thread: C2000WARE

I have a CLA routine (Task3) which is triggered by ADC EOC interrupt. The Task 3 will fetch ADCC SOC0 result, and use it for PID calculation.

I use a pointer (*claAdcCresAddr) to access ADCC SOC0 result. The pointer is properly initialized in the Cla1DataRam1 section before switching the master from CPU to CLA.
claAdcCresAddr = (Uint16*)(ADCCRESULT_BASE);//ADCCRESULT_BASE is defined to 0x00000B40U.

However, when I run the below function, the sample_Uint16 value stays at 0, even though the actual ADC result is not 0. 

__interrupt void Cla1Task3 ( void )
{
    //Local Variables
    float sample;
    Uint16 sample_Uint16;

 __mdebugstop();

    // read ADC channel
 sample_Uint16 = claAdcCresAddr[0];//0 is SOC number
 sample = (float)sample_Uint16;

 // run the PID controller
 uk = DCL_runPID_L2(&pid1, rk, sample, lk);

 __mnop();
 __mnop();
 __mnop();
}

I set a breakpoint at Line 31 (shown below). When I hover the mouse over claAdcCresAddr[0], the pop-up window shows the pointer value is 0xB40, which is the correct ADCC result address. The window also shows the value at the pointed address is 2085 (0x825).

 

Nevertheless the Registers window shows the ADCC Result0 value is 0x824.
 

When I hover mouse over the local variable sample_Uint16, the variable doesn’t appear to be assigned a value. Only the declaration is shown. The information would disappear once I press a key, so I cannot save a screenshot. So instead I am showing the Variables window, which shows the local variables sample and sample_Uint16 do not have a value. This result would remain the same after I step through the function.
 

So, even though CCS is able to read ADCC SOC0 result using the pointer address, the value cannot be passed to the local variable. What did I do wrong here?

I looked through the C2000ware examples, but did not find any example that shows how to directly read ADC result from CLA code. So please help.

Thank you very much.

  • Hi,

    Please see the cla_ex2_adc_fir32.c and the associated example: C:\ti\c2000\C2000Ware_1_00_06_00\device_support\f28004x\examples\cla

    This example successfully reads the ADC result register.

    This should help you get it working.

    sal
  • Hi Sal,

    Thank you for your reply.

    I found the example but the CLA task is written in assembly. So I instead used the cla_ex1_background_task_cla.cla example under the same folder.

    In the cla_ex1_background_task_cla.cla file, it simply passes the ADC result from register to a local int16 variable. I tried exactly the same but with no luck. The local variable can not receive the new value. Where should I check?


    Example from cla_ex1_background_task_cla.cla file:
    __attribute__((interrupt)) void Cla1Task1 ( void )
    {
    //Local Variables
    int16_t i, filter_in;

    __mdebugstop();

    filter_out = 0.0;
    filter_in = AdcaResultRegs.ADCRESULT0;

    …}

    I use RAMLS2 as CLA data ram. Does it look correct? Are the Cla1ToCpuMsgRAM and CpuToCla1MsgRAM correctly defined?

    CLA initialization:

    MemCfg_setCLAMemType(MEMCFG_SECT_LS0, MEMCFG_CLA_MEM_PROGRAM);
    MemCfg_setCLAMemType(MEMCFG_SECT_LS1, MEMCFG_CLA_MEM_DATA);
    MemCfg_setCLAMemType(MEMCFG_SECT_LS2, MEMCFG_CLA_MEM_DATA);
    MemCfg_setLSRAMMasterSel(MEMCFG_SECT_LS0, MEMCFG_LSRAMMASTER_CPU_CLA1);
    MemCfg_setLSRAMMasterSel(MEMCFG_SECT_LS1, MEMCFG_LSRAMMASTER_CPU_CLA1);
    MemCfg_setLSRAMMasterSel(MEMCFG_SECT_LS2, MEMCFG_LSRAMMASTER_CPU_CLA1);

    Linker file:
    // CLA Sections
    Cla1Prog : > RAMLS0, PAGE = 0
    .scratchpad : > RAMLS1, PAGE = 1
    .bss_cla : > RAMLS1, PAGE = 1
    .const_cla : > RAMLS1, PAGE = 1
    Cla1ToCpuMsgRAM : > CLA1_MSGRAMLOW, PAGE = 1
    CpuToCla1MsgRAM : > CLA1_MSGRAMHIGH, PAGE = 1
    Cla1DataRam1 : > RAMLS2, PAGE = 1
    ramgs0 : > RAMGS0, PAGE = 1
    ramgs1 : > RAMGS1, PAGE = 1

    PAGE 0 :
    RAMLS0 : origin = 0x008000, length = 0x000800

    Page 1:
    RAMLS1 : origin = 0x008800, length = 0x000800
    RAMLS2 : origin = 0x009000, length = 0x000800
    CLA1_MSGRAMLOW : origin = 0x001480, length = 0x000080
    CLA1_MSGRAMHIGH : origin = 0x001500, length = 0x000080
  • Problem solved. The CLA code was actually working, but debugger can’t seem to read out the variable value while debugging the CLA core. But once I copy them to Cla1ToCpuMsgRAM and debug the CPU core, I can see their values are correct.
  • Great! This may have been because you assigned the RAM to the CLA. I think this is the reason. I am not sure where sample was located but sample_Uint16 was on the scratchpad of the CLA memory.

    sal