element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Code Exchange
  • Technologies
  • More
Code Exchange
Forum get elapsed time since reset has been started in microcontroller
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Code Exchange to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 6 replies
  • Subscribers 46 subscribers
  • Views 1505 views
  • Users 0 members are here
  • clock
  • reset
  • Code Exchange
  • elspsed
  • bootup
  • kernel
  • microcontroller
  • time
  • cycles
Related

get elapsed time since reset has been started in microcontroller

dr.akshay_1980@yahoo.com
dr.akshay_1980@yahoo.com over 9 years ago

I want a efficient C code for my microcontroller to get the elapsed time since reset? just like aurdino has built in function millisec(). Assume the microcontroller be 8051, AVR and ARM7.

 

 

Thanx in advance..

  • Sign in to reply
  • Cancel

Top Replies

  • michaelkellett
    michaelkellett over 9 years ago in reply to balearicdynamics +1
    Here's some code for an STM32F405 uint32_t g_tick_count = 0; RCC_ClocksTypeDef RCC_Clocks; // global structure allows access to clock frequencies void init(void) { RCC_GetClocksFreq(&RCC_Clocks); // get…
  • michaelkellett
    0 michaelkellett over 9 years ago

    You need to set up a timer and an interrupt and count the timer interrupts since reset.

    The code will be different not just for each processor core type but for each different implementation of that core.

    Is this homework or do you have a serious requirement - if so it would help if you described the problem in a lot more detail, like processor type, precision required etc etc.

     

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • balearicdynamics
    0 balearicdynamics over 9 years ago in reply to michaelkellett

    Mike,

     

    there are many cases I see that the simple call of the time function always return the number of microseconds (in a long integer format, usually) from the last micro controller power-on. Or I am wrong ?

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 9 years ago in reply to balearicdynamics

    Since the OP said C and didn't specify an OS I'm assuming there isn't any code running that the OP didn't write or explicitly link.

     

    8051 s and AVRs don't have hardware on-timers - some ARM7 s might but CortexM cores don't (they do have Systick timer which you can code to do this.)

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • balearicdynamics
    0 balearicdynamics over 9 years ago in reply to michaelkellett

    Thanks Mike,

     

    Instead I have always got this fact as a sort of assumption. So there are some micro that doesn't "export" their ticks count based on the clock? My assumption was based on that time.h and the related C standard library is always available (maybe not?) on every compiler. http://pubs.opengroup.org/onlinepubs/009695399/basedefs/time.h.html

    Then sure not (very few as a matter of fact) processors / boards has a more complex time function than the bare number of clocks from the power on.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 9 years ago in reply to balearicdynamics

    Here's  some code for an STM32F405

     

     

    uint32_t g_tick_count = 0;

    RCC_ClocksTypeDef RCC_Clocks;   // global structure allows access to clock frequencies

     

     

    void init(void)

    {

    RCC_GetClocksFreq(&RCC_Clocks);                                        // get the clock frequencies, config done in startup - useful for debugging so main clocks are in global which is easily monitored

    SysTick_Config(RCC_Clocks.HCLK_Frequency / SYS_TICKS_PER_SECOND);      // 1000 ticks per second independent of actual clock frequency

     

     

    // other stuff

     

    }

     

     

    void SysTick_Handler(void)                                            // gets called once every ms

    {

    g_tick_count++;                                                       // system timer incremented here

    if (flg_adc_running == true)                                          // other code to do with this projects specifics

        {

        do_data_processing();

        }

    if (fsm_timer != 0)

        {

        fsm_timer--;

        }

    }


    Of course this system doesn't support the time.h library .


    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • balearicdynamics
    0 balearicdynamics over 9 years ago in reply to michaelkellett

    Thank you for the detailed explanation image So, I had a lot of luck in past image image

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube