This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

comprehension question Timer

Hi,

maybe i have a silly question, but i didn't programm timers before. I know how they work. But how is it possible that there are only three Timers in the 51822 and so many parts of the programm part (PWM,BLE,GPIOTE...) which need a timer? How can i organize my timers?

and is it possible to run one timer and write a function like "get_actual_time" which gives me the time in the moment i call the function?

Best reagards, Nils :)

Parents
  • Hi Nils,

    I don't have any sample code of the round robin scheduler that I can share.

    But I have attached my code for setting up RTC1 for a 1ms interrupt, with two 32 bit counters for milliseconds and seconds since the "beginning of time" .

    To build the scheduler, you would add the timer_variables and bool stuff after line 73.

    You can use either of the two 32 bit counters to do some other neat things in your code, like this:

    [b] temp = RTC1_Milliseconds; while(RTC1_Milliseconds < (temp+37)) {} // wait here for 37 ms

    temp = RTC1_Seconds;
    {
        // lots of stuff goes in here that takes a long time to execute
    }
    printf("Execution time in seconds:  %6d\n", RTC1_Seconds - temp);[/b]
    

    The example code supplied refers to one of my header files, which must also be included in routines that use this stuff. the only relevant lines to this example in the header are:

    [b]extern uint32_t RTC1_Milliseconds; extern uint32_t RTC1_Seconds; [/b]

    Enjoy.

    RTC1_ms_timer.c

  • Hi Philip,

    thanks for this great answer you helped me pretty much with the understanding how to use the rtc or the timer.

    Thanks for this great example, perfect for me but i have some question.

    • Why is the prescaler 31, you want to devide the timervalue by 32 is 31 right?
    • Why restarts the rtc_counter if it is bigger then 42 ? why this value?

    Thank you for helping, i am a newbie who trys to understand all this stuff. It is a lot to learn but with such examples it works fine :)

Reply
  • Hi Philip,

    thanks for this great answer you helped me pretty much with the understanding how to use the rtc or the timer.

    Thanks for this great example, perfect for me but i have some question.

    • Why is the prescaler 31, you want to devide the timervalue by 32 is 31 right?
    • Why restarts the rtc_counter if it is bigger then 42 ? why this value?

    Thank you for helping, i am a newbie who trys to understand all this stuff. It is a lot to learn but with such examples it works fine :)

Children
No Data
Related