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.

TMS320F2800157: TMS320F2800157: Timer Configuration

Part Number: TMS320F2800157

Tool/software:

Hello,

I am currently working with the cpu timers of the TMS320F2800157 controller. I am trying to make the configuration of the timers as configurable as possible. Therefore  I created a struct that represents the config of one timer and put the values I needed in them such as TCR and TPR as the value of the whole registers and I made a const array of structs and I initialized the values that represents the value of the whole register using masking of all bits in the register. When I debug, I notice that the values of the array of structs are initialized correctly but when I assign them to the register value using for example ...TCR.all = (value of register) tha value doesn\t get set in the register. Why is that? Do I need to set the bits of the register timers bit by bit?

The following is an example of my code setting:

CpuTimer0Regs.TPR.all= Timer_Config_Array[TIMER2_INDEX].u32Tpr_R;
CpuTimer0Regs.TPRH.all = Timer_Config_Array[TIMER2_INDEX].u32Tprh_R;
CpuTimer0Regs.TCR.all = Timer_Config_Array[TIMER2_INDEX].u32Tcr_R;
CpuTimer0Regs.PRD.all = Timer_Config_Array[TIMER2_INDEX].u32Prd_R; /* set period value */


As I said the values in the struct members is correct, but they are not being set in the registers.
 

Note: i also tried EALLOW and EDIS when setting the registers but the values do not get set

  • Hello Mazen,

    Usually when writing to a register field using the .all access, you want to OR equals instead of writing the whole register to isolate the field you are writing. In the case of the TPR and TPRH registers, only the TDDR field has read and write access, not the entire register. So, I would first suggest changing your writes to the following:

    CpuTimer0Regs.TPR.all |= Timer_Config_Array[TIMER2_INDEX].u32Tpr_R;
    CpuTimer0Regs.TPRH.all |= Timer_Config_Array[TIMER2_INDEX].u32Tprh_R;
    CpuTimer0Regs.TCR.all |= Timer_Config_Array[TIMER2_INDEX].u32Tcr_R;
    CpuTimer0Regs.PRD.all |= Timer_Config_Array[TIMER2_INDEX].u32Prd_R; /* set period value */

    Could you try reading your struct value into variables instead of the register to verify that the struct accesses are being done correctly via the debugger?

    I'm assuming these struct members are uint32_t type based on your naming convention. Note that the TPR, TPRH and TCR registers are 16-bit registers so these should be changed to uint16_t struct members to avoid error.

    Best Regards,

    Delaney

  • Hello Delaney, 

    I've adjusted my code for the comments you have said to be done and this is the code right now:

     volatile u16 u16Tpr_R = Timer_Config_Array[TIMER0_INDEX].u16Tpr_R;
     volatile u16 u16Tprh_R = Timer_Config_Array[TIMER0_INDEX].u16Tprh_R;
     volatile u16 u16Tcr_R = Timer_Config_Array[TIMER0_INDEX].u16Tcr_R;
     volatile u32 u32Prd_R = Timer_Config_Array[TIMER0_INDEX].u32Prd_R;
     volatile u32 u32PerfAct = Timer_Config_Array[TIMER0_INDEX].u32PerfAct;
     volatile u32 u32PerfAvg = Timer_Config_Array[TIMER0_INDEX].u32PerfAvg;
     volatile u32 u32PerfMax = Timer_Config_Array[TIMER0_INDEX].u32PerfMax;
     volatile u32 u32PerfMin = Timer_Config_Array[TIMER0_INDEX].u32PerfMin;
     volatile u16 u16PerfOvf = Timer_Config_Array[TIMER0_INDEX].u16PerfOvf;

     EALLOW;
        /* Set reset values for bootloader compitability */
        CpuTimer0Regs.TPR.all |= u16Tpr_R;
        CpuTimer0Regs.TPRH.all |= u16Tprh_R;
        CpuTimer0Regs.TCR.all |= u16Tcr_R;


        CpuTimer0Regs.PRD.all |= u32Prd_R; /* set period value */

        EDIS;

    When I debug, the values are placed in the volatile variables I have created correctly but at the |= assignments, the registers are not being written. Why is this? Does this mean that the registers of the timers cannot be written by the .all approach
  • Hi Mazen,

    No, it should be possible to write the CPUTIMER registers with the .all approach. Can you send me your code and I will try to replicate the issue?

    Best Regards,

    Delaney

  •     volatile u16 u16Tpr_R = Timer_Config_Array[TIMER0_INDEX].u16Tpr_R;
        volatile u16 u16Tprh_R = Timer_Config_Array[TIMER0_INDEX].u16Tprh_R;
        volatile u16 u16Tcr_R = Timer_Config_Array[TIMER0_INDEX].u16Tcr_R;
        volatile u32 u32Prd_R = Timer_Config_Array[TIMER0_INDEX].u32Prd_R;
        volatile u32 u32PerfAct = Timer_Config_Array[TIMER0_INDEX].u32PerfAct;
        volatile u32 u32PerfAvg = Timer_Config_Array[TIMER0_INDEX].u32PerfAvg;
        volatile u32 u32PerfMax = Timer_Config_Array[TIMER0_INDEX].u32PerfMax;
        volatile u32 u32PerfMin = Timer_Config_Array[TIMER0_INDEX].u32PerfMin;
        volatile u16 u16PerfOvf = Timer_Config_Array[TIMER0_INDEX].u16PerfOvf;

        EALLOW;
        /* Set reset values for bootloader compitability */
        CpuTimer0Regs.TPR.all |= u16Tpr_R;
        CpuTimer0Regs.TPRH.all |= u16Tprh_R;
        CpuTimer0Regs.TCR.all |= u16Tcr_R;


        CpuTimer0Regs.PRD.all |= u32Prd_R; /* set period value */
        EDIS;

    This is my code inside a function. When this function is executed, I notice by debugging that the values are correctly placed in the volatile variables I created but when it comes to assigning these valuues to the register, no change happens inside the register.
    `
  • Hi Mazen,

    Can you send your structure definition as well? I wasn't able to replicate the issue when trying to write to these registers in code. Also, when debugging, did you make sure "Continuous Refresh" was enabled in the Register View? If it was not, it's possible the values were actually written but just didn't update in the CCS viewer.

    Best Regards,

    Delaney