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.

AM6442: How do I get the value of the timer

Part Number: AM6442

Hello,

I am using AM64 and I want to read the value of a timer, how do I read it, I use the _t TimerP_getCount(uint32_t baseAddr) API, but the read data is messy, what do I do now this problem?

 while(1)
    {
        GPIO_pinWriteHigh(gpioBaseAddr, pinNum);

        /* Sleep for user specified usecs */
        ClockP_usleep(delayuSec);
        NowTime = TimerP_getCount(gTimerBaseAddr[CONFIG_TIMER0]);

        DebugP_log("NowTime = %d!!\r\n",NowTime);

        /* Set gpio output low level */
        GPIO_pinWriteLow(gpioBaseAddr, pinNum);

        /* Sleep for user specified usecs */
        ClockP_usleep(delayuSec);
    }

Regards,

Gary

  • Hello Gary,

    Thanks for reaching out to Texas Instrument E2E Support Forum.

    It would be easier for me to understand the bigger picture here.

    To avoid ambiguity could you share me the project file with the timer code snippet written in it?

    This way I can reproduce this issue on my local AM64x kit.

    Looking forward to your response.

    Regards,

    Vaibhav

    ARM Based Processors | FAQ AM62x & AM62A | FAQ AM64x

  • Hello,

    /**
     *  \file    led_flash_a53ss_nortos.c
     *
     *  \brief   Example application main file. This application will toggle the led.
     *           The led toggling will be done inside an callback function, which
     *           will be called by Interrupt Service Routine. Interrupts are
     *           triggered manually and no external source is used to trigger
     *           interrupts.
     *
     *  \version 1.0
     */
    
    #include <stdlib.h>
    #include <drivers/gpio.h>
    #include <kernel/dpl/AddrTranslateP.h>
    #include <kernel/dpl/DebugP.h>
    #include <kernel/dpl/ClockP.h>
    #include "ti_drivers_config.h"
    #include "ti_board_config.h"
    #include "ti_drivers_open_close.h"
    #include "ti_board_open_close.h"
    
    int main()
    {
        uint32_t    delayuSec = 500000;
        uint32_t    gpioBaseAddr1, pinNum1, gpioBaseAddr2, pinNum2;
    
        /* Init SOC specific modules */
        System_init();
        Board_init();
    
        /* Open drivers to open the UART driver for console */
        Drivers_open();
        Board_driversOpen();
    
        DebugP_log("GPIO LED Flash Application\r\n");
    
        /* Get address after translation translate */
        gpioBaseAddr1 = (uint32_t) AddrTranslateP_getLocalAddr(GPIO_LED1_BASE_ADDR);
        pinNum1       = GPIO_LED1_PIN;
        gpioBaseAddr2 = (uint32_t) AddrTranslateP_getLocalAddr(GPIO_LED2_BASE_ADDR);
        pinNum2       = GPIO_LED2_PIN;
    
        /* Set gpio direction */
        GPIO_setDirMode(gpioBaseAddr1, pinNum1, GPIO_LED1_DIR);
        GPIO_setDirMode(gpioBaseAddr2, pinNum2, GPIO_LED2_DIR);
    
        ;
    
        while(1)
        {
            /* Set gpio output high level */
            GPIO_pinWriteHigh(gpioBaseAddr1, pinNum1);
            GPIO_pinWriteHigh(gpioBaseAddr2, pinNum2);
    
            /* Sleep for user specified usecs */
            ClockP_usleep(delayuSec);
    
            DebugP_log("TimerNum = %u\r\n",TimerP_getCount(gTimerBaseAddr[CONFIG_TIMER0]));
    
            /* Set gpio output low level */
            GPIO_pinWriteLow(gpioBaseAddr1, pinNum1);
            GPIO_pinWriteLow(gpioBaseAddr2, pinNum2);
    
            /* Sleep for user specified usecs */
            ClockP_usleep(delayuSec);
        }
    
        /* Close drivers */
        Board_driversClose();
        Drivers_close();
    
        /* Deinit SOC specific modules */
        Board_deinit();
        System_deinit();
    
        return 0;
    }

    led_flash_r5fss_nortos.syscfg I just modified two files here. I hope the result of TimerP_getCount(gTimerBaseAddr[CONFIG_TIMER0]) starts from 0.

    The maximum value then resets to 0 and is counted again, but now the result is as shown in the picture.

    If there are any missing documents, please tell me and I will provide them for you. Thank you!

    Regards,

    Gary

  • Hi Gary,

    Thanks for the code.

    Although I might miss out on few things here, like the MCU PLUS SDK version you are using and so on. 

    Can you please send me a zip file of the entire project, this way, I can have all the necessary files in one place.

    I have mailed you, please check and revert back with a zip file of the project.

    Thanks,

    Vaibhav

    ARM Based Processors | FAQ AM62x & AM62A | FAQ AM64x