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 Nils,

    I'm glad to help. (sorry for my english, I am Australian and American :-)

    With regard to temperature, it is better to describe it as temperature dependence rather than compensation.

    The short answer to your question is Xtal or synth are both better than RC.

    The long answer is:

    Since the synthesizer depends on a crystal (16 or 32 MHz) , both the synthesizer and 32768 Hz crystal options will have similar characteristics. It depends on the crystal you specify and buy, but typically in the range of +/- 10 ppm to +/- 100ppm. On page 31 of the product spec, Nordic gives the worst case values of 60 ppm or 40 ppm. Lower values usually mean more expensive parts, but not always.

    In general, crystal oscillators will always be less affected by temperature than an RC oscillator. This is why crystals are used whenever an accurate clock is needed. There are also special crystal oscillators with extra stuff to compensate for temperature effects (TCXO) and oscillators that include a miniature oven to create a stable temperature (OCXO). Look here if you want to learn more http://www.vectron.com For work with the Nordic chips, you do not need these type of oscillators, I just thought you might be interested.

    Also, you may want to consider other things: 32768 Hz RC oscillator is totally inside the chip, XTAL/Synth both require an external crystal, but if you are using the radio, you need a crystal anyway. Also the 16/32 MHz crystal oscillators requires about 400 uA (page 31 and 32). The 32768 crystal oscillator needs only 1 uA (page 33, fabulous), and the RC oscillator need 0.8 uA (page 34). These are all typical numbers.

    You asked "Why does it depend on Vcc ?"

    A crystal oscillator is only affected a tiny amount by change in VCC. An RC oscillator is affected more by change in VCC.

    The reason is that the resistor (R) and capacitor (C) are implemented with various structures on the chip, and these structures are affected by the voltage the chip runs at, and also by temperature.

    When Nordic give a +/- 2% accuracy range for the RC oscillator, that range includes the combined effects of voltage (1.8V to 3.6V, page 29), and temperature (-25C to 75C, page 29), and the general variability from one chip to another (usually described as "Process"). This is usually referred to as PVT parameters.

    Cheers, Philip

Reply
  • Hi Nils,

    I'm glad to help. (sorry for my english, I am Australian and American :-)

    With regard to temperature, it is better to describe it as temperature dependence rather than compensation.

    The short answer to your question is Xtal or synth are both better than RC.

    The long answer is:

    Since the synthesizer depends on a crystal (16 or 32 MHz) , both the synthesizer and 32768 Hz crystal options will have similar characteristics. It depends on the crystal you specify and buy, but typically in the range of +/- 10 ppm to +/- 100ppm. On page 31 of the product spec, Nordic gives the worst case values of 60 ppm or 40 ppm. Lower values usually mean more expensive parts, but not always.

    In general, crystal oscillators will always be less affected by temperature than an RC oscillator. This is why crystals are used whenever an accurate clock is needed. There are also special crystal oscillators with extra stuff to compensate for temperature effects (TCXO) and oscillators that include a miniature oven to create a stable temperature (OCXO). Look here if you want to learn more http://www.vectron.com For work with the Nordic chips, you do not need these type of oscillators, I just thought you might be interested.

    Also, you may want to consider other things: 32768 Hz RC oscillator is totally inside the chip, XTAL/Synth both require an external crystal, but if you are using the radio, you need a crystal anyway. Also the 16/32 MHz crystal oscillators requires about 400 uA (page 31 and 32). The 32768 crystal oscillator needs only 1 uA (page 33, fabulous), and the RC oscillator need 0.8 uA (page 34). These are all typical numbers.

    You asked "Why does it depend on Vcc ?"

    A crystal oscillator is only affected a tiny amount by change in VCC. An RC oscillator is affected more by change in VCC.

    The reason is that the resistor (R) and capacitor (C) are implemented with various structures on the chip, and these structures are affected by the voltage the chip runs at, and also by temperature.

    When Nordic give a +/- 2% accuracy range for the RC oscillator, that range includes the combined effects of voltage (1.8V to 3.6V, page 29), and temperature (-25C to 75C, page 29), and the general variability from one chip to another (usually described as "Process"). This is usually referred to as PVT parameters.

    Cheers, Philip

Children
No Data
Related