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 your usefull informations. Every time you telling me how to understand the things i realy get more and more points of reference (sorry for my english, i am german :D), thanks because this is great for a newbie. I just read the part you told me. Is it better , for tempreture compensating, to use an RC or an XTAL or to synth?

    Why does it depent on Vcc ?

    best regards Nils :)

Reply Children
No Data
Related