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.

LP-MSPM0G3507: TIMA0 not counting properly

Part Number: LP-MSPM0G3507
Other Parts Discussed in Thread: SYSCONFIG, MSPM0G3507

Hello everyone,

I'm trying to use a timer to trigger ADC sampling on LP-MSPM0G3507 (Rev. A) using a zero event.

I'm using sysconfig of CCS Theia 1.2.0 to configure module TIMA0: specifically I'm making it to work in periodic down-counting mode, with a period of 50us, and zero events as trigger for ADC, as you can see in the following image:

Running my code I found out that the sampling was happening much faster that expected (TIMA0_CTR changing values too fast considering code), causing some erratic behaviour.

I tried to look for a way to easily measure my code timing, but considering that MSPM0G3507 doesn't seem to have available the possibility to use Clock Counts breakpoints or Profile Clock, i tried using SysTick to have a mean to compare its downcounting to the one of TIMA0: to my surprise SysTick is behaving exactly as expected, having a downcount consistent with my code.

I'm really baffled about this problem, so I'm wondering if it could involve some clocking setting I'm not aware of or something else I'm missing about this system.

The following image is how I configured SYSCTL and SYSTICK and you can find my code.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "ti/devices/msp/peripherals/hw_flashctl.h"
#include "ti/driverlib/dl_dma.h"
#include "ti/driverlib/dl_adc12.h"
#include "ti/driverlib/dl_timera.h"
#include "ti_msp_dl_config.h"
#include <sys/_stdint.h>
uint16_t Sample_Buffer[12] =
{
0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000
};
uint16_t test = 0x0000;
uint16_t DMA_transfer_control = 0x0000;
int main(void)
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Thanks in advance for your help.

Best Regards,

Stefano

  • Hi Stefano,

    How are you determining that the timer is counting too quickly? With a 64MHz TIMCLK period you would have difficulty observing this in the debug window based on the counter value.

    If you have access to an Oscope or logic analyzer you could set the TIMA0 load event to trigger a GPIO to toggle and just probe that GPIO.

    You can do that entirely in SysConfig by creating an GPIO output, and setting it as an event subscriber. Then enable the zero event of the TIMA0 instance as an event publisher on the same channel.

    If everything is being set up correctly you should see that GPIO toggle every 50us when you probe it.

    Best Regards,
    Brandon Fisher

  • Going instruction by instruction in the disassembler and comparing it to SYSTICK, that it’s set for the same period of TIMA0, I observe very a different behaviour: in the same period that systick expires TIMA0 trigger 3-4 ADC sample. I’ll try with a scope as soon as possibile, but I don’t have one available at the moment.

    Thanks for your answer.

  • Hi Stefano,

    So you are seeing this based on the number of ADC samples that occur in that systick period?

    Can you share an image of your ADC settings? Or if you're comfortable sharing your whole .syscfg file I don't mind looking over it. I want to see what the settings are for the Sampling Mode Configuration and the ADC Conversion Memory Configurations.

    Best Regards,
    Brandon Fisher

  • Hi Brandon,

    sure this are the images you requested regarding my ADC config:

    I'm trying to get 3 sample in a period of 50us, period provided by the timer zero event trigger.

    What I see right now, given that I'm understanding correctly the feedback from SysTick,  is that in the span of 50us I get more then 1 ADC trigger.

    Best Regards,

    Stefano

  • Regarding the .sysconfig file I guess it's to big to upload, you can find the generated code here:

    ti_msp_dl_config.h

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #ifndef ti_msp_dl_config_h
    #define ti_msp_dl_config_h
    #define CONFIG_MSPM0G350X
    #if defined(__ti_version__) || defined(__TI_COMPILER_VERSION__)
    #define SYSCONFIG_WEAK __attribute__((weak))
    #elif defined(__IAR_SYSTEMS_ICC__)
    #define SYSCONFIG_WEAK __weak
    #elif defined(__GNUC__)
    #define SYSCONFIG_WEAK __attribute__((weak))
    #endif
    #include <ti/devices/msp/msp.h>
    #include <ti/driverlib/driverlib.h>
    #include <ti/driverlib/m0p/dl_core.h>
    #ifdef __cplusplus
    extern "C" {
    #endif
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    ti_msp_dl_config.c

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #include "ti_msp_dl_config.h"
    DL_TimerA_backupConfig gTIMER_0Backup;
    /*
    * ======== SYSCFG_DL_init ========
    * Perform any initialization needed before using any board APIs
    */
    SYSCONFIG_WEAK void SYSCFG_DL_init(void)
    {
    SYSCFG_DL_initPower();
    SYSCFG_DL_GPIO_init();
    /* Module-Specific Initializations*/
    SYSCFG_DL_SYSCTL_init();
    SYSCFG_DL_TIMER_0_init();
    SYSCFG_DL_ADC12_0_init();
    SYSCFG_DL_VREF_init();
    SYSCFG_DL_DMA_init();
    SYSCFG_DL_SYSTICK_init();
    /* Ensure backup structures have no valid state */
    gTIMER_0Backup.backupRdy = false;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi Stefano,

    I don't see anything obvious here in configuration that jumps out at me as wrong. When you say you get 3-4 samples, does that mean 3-4 sequences of conversions? Your ADC is setup in sequence mode so I would expect 3 conversions total from a single trigger. 

    Testing the timer period with the GPIO output would still be good as well. 

    Best Regards,
    Brandon Fisher

  • Hi Brandon,

    yes, when I wrote 3-4 samples I really meant 3-4 sequences: in each sequence I get 3 samples. What I expect to do is to complete the Sample_buffer in 200us (so 4 ADC triggers, 3 sample for each trigger, 12 samples in total, Sample_buffer array is complete). What I'm experiencing is that, before Systick countdown "expires" I already have a complete Sample_buffer (so it means it took less than 50us to perform 4 ADC triggers).

    I'll be able to test it with a scope next monday, in the meantime I'll try to install CCS Theia on another PC to see if maybe it could be somewhat related to what I'm seeing.

    Just to be sure, considering I set Systick to 50us, is there any possibility that it is counting differently from TIMA0? I really don't know, maybe some CCS config I'm missing/not considering?

    What I can tell you for sure, and if you'll run my code I think you'll be able to see it too, is that Systick performs its countdown in a certain way (I see this by going step-by-step in the disassembler): given that TIMA0 is started at almost the same time as SysTick, I was expecting a time delta between the 2, but this delta should be sort of constant, am I right? Instead I see that TIMA0 is counting down much faster than Systick: could this also be some kind of display issue for the counter reg of TIMA0? I'm really just trying to consider everything possible.

    Thanks for your answers and your time.

    Stefano

    EDIT: Just to be as clear as possibile, I'm looking at SYST_CVR reg to see SysTick countdown.

  • Just to be sure, considering I set Systick to 50us, is there any possibility that it is counting differently from TIMA0? I really don't know, maybe some CCS config I'm missing/not considering?

    It should not be, given that they are sourced from the same clock in your configuration. 

    What I can tell you for sure, and if you'll run my code I think you'll be able to see it too, is that Systick performs its countdown in a certain way (I see this by going step-by-step in the disassembler): given that TIMA0 is started at almost the same time as SysTick, I was expecting a time delta between the 2, but this delta should be sort of constant, am I right? Instead I see that TIMA0 is counting down much faster than Systick: could this also be some kind of display issue for the counter reg of TIMA0? I'm really just trying to consider everything possible.

    The delta should remain constant. The inclusion of the debugger in the mix can cause some strange behavior though. TIMA0 defaults to free run mode, meaning that it continues to run while the core is halted by the debugger. 

    Whereas the SysTick halts when the debugger pauses the CPU:

    Using the debugger will pull these two out of sync, as it is periodically going to halt execution to get the debug state.

    Best Regards,
    Brandon Fisher

  • Ok great, so this really should be a non-issue.

    Just to be sure I'll still check with the scope next monday, but I think this is it, I'll set the topic as solved as soon as I'll do this test,

    Thanks for you answers and insights, and sorry if my question was silly, considering this is almost certainly not a problem.

    Best Regards,

    Stefano

    EDIT: Actually I don't need to see it on the scope, using DL_Timer_setCoreHaltBehavior(TIMER_0_INST, DL_TIMER_CORE_HALT_IMMEDIATE) I could see that the counter was working propertly. Thanks again.