{"id":2191,"date":"2018-08-01T23:41:47","date_gmt":"2018-08-01T23:41:47","guid":{"rendered":"https:\/\/deepbluembedded.com\/?p=2191"},"modified":"2023-08-17T23:53:14","modified_gmt":"2023-08-17T20:53:14","slug":"timer-preloading-tutorial","status":"publish","type":"post","link":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/","title":{"rendered":"Timer PreLoading | How To Generate Delay With Timer Module?"},"content":{"rendered":"\n\n\n\n\n
\"Previous<\/a><\/td>\nPrevious Tutorial<\/strong><\/a><\/td>\nTutorial 11<\/span><\/strong><\/span><\/td>\nNext Tutorial<\/strong><\/a><\/td>\n\"Next<\/a><\/td>\n<\/tr>\n
<\/td>\nTimer Preloading | Generate Delay With Timer (100% Accurate)<\/strong><\/span><\/td>\n<\/td>\n<\/tr>\n
<\/td>\nIntermediate level\u00a0\u2605\u2605\u2606\u2606\u2606<\/strong><\/span><\/td>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

In this tutorial, we’ll discuss how to generate accurate time intervals with timer modules using the timer preloading technique. You’ll learn both how to measure and eliminate error in timer output intervals. It’s going to be an easy yet interesting read so let’s get started!<\/span><\/p>\n

[toc]<\/p>\n


\n

\u00a0 \u00a0Components Needed for this tutorial\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n

 <\/p>\n\n\n\n\n\n\n\n\n\n\n\n\n
Quantity<\/span><\/strong><\/span><\/td>\nComponent Name<\/span><\/strong><\/span><\/td>\n<\/tr>\n
1<\/span><\/td>\nPIC16F877A<\/span><\/td>\n<\/tr>\n
1<\/span><\/td>\nBreadboard<\/span><\/td>\n<\/tr>\n
1<\/span><\/td>\nJumper Wires Pack<\/span><\/td>\n<\/tr>\n
1<\/span><\/td>\n330\u03a9 Resistors<\/span><\/td>\n<\/tr>\n
1<\/span><\/td>\nLED<\/span><\/td>\n<\/tr>\n
1<\/span><\/td>\n4MHz Crystal OSCillator<\/span><\/td>\n<\/tr>\n
1<\/span><\/td>\nLM7805 Voltage Regulator<\/span><\/td>\n<\/tr>\n
1<\/span><\/td>\n9v Battery or any Power Supply Source<\/span><\/td>\n<\/tr>\n
1<\/span><\/td>\nPICkit3 (PIC Programmer)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/h3>\n
\n

\u00a0 \u00a0The Source Of Error\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n

 <\/p>\n

Solving any kind of problems always starts by defining the problem itself. Figuring out what’s wrong or what’s the source of these tiny glitches is the first step to eliminate them all. That’s why we should point out the real reason behind the erroneous output of the timer1 module in the last tutorial (Tutorial 9 – LAB7). The step at which we were calculating the required number of timer overflows in order to get 1-second time interval as an output.<\/span><\/p>\n

For the 16-Bit Timer1 module, with a system being clocked at a rate of 4MHz, with a prescaler ratio of 1:1, with an initial value of 0 loaded in TMR1 register, and the output time interval is set to be 1-second. Then the number of overflows (X<\/strong>) needed to complete 1-second is given by the following general equation.<\/span><\/p>\n

\"timer-preloading\"<\/p>\n

By solving for X<\/strong>, we need 15.26 overflows in order to get a time interval of 1 second. In the previous tutorial, we’ve neglected the 0.26 part. That’s obviously the main source of the error!<\/span><\/p>\n

Well, the Toverflow<\/sub> is = 0.06553<\/span><\/p>\n

Hence the output time interval, Tout <\/sub>= 15 * 0.06553 = 0.982 second<\/span><\/p>\n

It should be 1 second, not 0.982 of course.\u00a0But 15.26 * 0.06553 = 1 second<\/span><\/p>\n

That’s why we should have taken that 0.26<\/strong>\u00a0fraction part into account! But how? How can the number of interrupt overflows be a floating-point number? Does it make sense to have a 4.7, 10.2, or 12.8 number of overflows?<\/span><\/p>\n

Actually, it does make sense! yet it’s absolutely doable. But it may not be a very good idea to follow as long as we can avoid getting a floating number in the first place!<\/span><\/p>\n

In this tutorial, I will explain both methods that I use and refer to as “Timer preloading”. Here is a brief description for both:<\/span><\/p>\n

\u00a0 The first method\u00a0\u00a0<\/span><\/h4>\n

I always prefer and recommend this way and find it much easier to explain and implement. In this method, we avoid getting a floating number as a value for the number of overflows (X<\/strong>). This is technically achieved by adjusting the Toverflow<\/sub> for the timer1 module by preloading a calculated value into the TMR1 register at the beginning of each round.<\/span><\/p>\n

\u00a0 The second method\u00a0\u00a0<\/span><\/h4>\n

Which I do not recommend as much. Anyway, in this method we firstly deal with the fraction part of X<\/strong>. Say it was (13.8), In this case, we’ll preload a value to get a (0.8 Toverflow). Then we’ll perform 13 complete overflows starting from (0 to 65535).<\/span><\/p>\n

\u00a0 What we’ll be doing next?\u00a0\u00a0<\/span><\/h4>\n

Well, we’ll discuss the first method as it has proven to be the easier to grasp in most cases. In the next section, I will explain the basic idea in detail. The following couple of sections are going to be a step-by-step implementation, and a practical LAB respectively. Then, the tutorial is done and you can just jump to the next one. However, the final section in this tutorial will be a full demonstration of the second method of preloading for those who are interested (It’s optional).<\/span><\/p>\n

 <\/p>\n


\n

\u00a0 \u00a0Timer Preloading Technique\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n

 <\/p>\n

The basic idea of this technique is to avoid getting a floating number as a value for the number of overflows (X<\/strong>). How can we achieve this?<\/span><\/p>\n

Let’s consider the previous case encountered in LAB7. In which we had a 16-Bit timer module (timer1), a system clocked at a rate of 4MHz, a prescaler of 1:1, and an initial value of 0. To get the Toverflow<\/sub> for this timer module in such settings, just use the general equation. By substituting for the number of overflows(X<\/strong>) by 1, you’ll get the Toverflow<\/sub><\/span><\/p>\n

Note that: For (X=1) ==>\u00a0 Tout<\/sub> = Toverflow<\/sub><\/span><\/p>\n

\"timer-preloading\"<\/p>\n

The result will be Toverflow<\/sub> = 0.06553 second<\/span><\/p>\n

And that crazy number is actually the source of pain. Why? well, if that number is the time it takes our timer1 module to reach overflow state. Then how many overflow interrupts do we need to complete a 1-second time interval?<\/span><\/p>\n

Obviously, it’s 1 \/ 0.06553<\/span><\/p>\n

which will result in 15.26<\/strong> overflow<\/span><\/p>\n

That’s why Toverflow<\/sub> must be changed!<\/span><\/p>\n

Well, it takes the timer1 module about (0.06553 seconds) to count from (0 to 65535). What if we could force it to overflow in less time? well, it can be a good solution. Especially if we chose a period of (0.05 second) which is less than 0.06553 and more importantly won’t generate a floating number when we divide 1second\/0.05second = 20. Which means that we’ll exactly need clean 20 overflows to get our desired 1-second output interval. There won’t be any remainder fractions and so.<\/span><\/p>\n

At this point, we all should be questioning the same thing. How can we force the timer1 module to overflow in just 0.05 second instead of 0.06553?<\/span><\/p>\n

Well, if counting from (0 to 65535) takes 0.06553 seconds. Then if it started counting from a specific value in between, then it can theoretically overflow nearly at any instance of time we wish!<\/span><\/p>\n

By using the general equation, setting (Tout<\/sub> = 1, X = 20, Fosc <\/sub>= 4MHz, PS = 1), and solving for TMR1. We’ll get the initial value to be preloaded in timer1 module. This will result in<\/span><\/p>\n

TMR1 = 15535<\/strong><\/span><\/p>\n

And that is the value we should preload to the TMR1 register in order to make (Toverflow<\/sub> = 0.05sec). Which means that a Tout<\/sub> of 1-second will need clear 20 overflows!<\/span><\/p>\n

That’s the basic idea behind the timer preloading technique. We’re changing the time till overflow Toverflow<\/sub> by loading a specific value in the TMR1 register at the beginning of counting, instead of starting at zero as usual!<\/span><\/p>\n

 <\/p>\n


\n

\u00a0 \u00a0Implementing Timer Preloading\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n

 <\/p>\n

Implementing the timer preloading technique in C-Code should be an easy task obviously. As long as you’ve correctly performed the calculations involved. Which means you’ve got a value to load to TMR1 and a number for the total interrupts that counts for the desired Tout<\/sub>. And here is the systematic step-by-step procedure for the timer preloading.<\/span><\/p>\n

\u00a0step1 – Configure The Timer Module\u00a0<\/span><\/h4>\n

Check the Timer1 logic diagram in the datasheet to make sure that you’re doing this right. Don’t forget to preload the value which we’ve calculated previously. Let’s consider the same settings for LAB7, thus the loading value will be (15535) and the counter X<\/strong> will go up to (20) as we’ve calculated previously. The C-Code for this step will be as follows<\/span><\/p>\n

\n
\/\/ -- [[ Configure Timer1 To Operate In Timer Mode\u00a0 ]] --\r\n\r\n\/\/ Preload The Value Which We've Calculated To The TMR1 16-Bit Register!\r\nTMR1 = 15535;\r\n\/\/ Choose the local clock source (timer mode)\r\nTMR1CS = 0;\r\n\/\/ Choose the desired prescaler ratio (1:1)\r\nT1CKPS0 = 0;\r\nT1CKPS1 = 0;\r\n\/\/ Event1 = (e.g. LED ON, Read sensor, etc)\r\n...\r\n\/\/ Switch ON Timer1 Module!\r\nTMR1ON = 1;<\/pre>\n

 <\/p>\n<\/div>\n

\u00a0step2- Write The ISR\u00a0<\/span><\/h4>\n

At each overflow, you should preload the specific value in TMR1 register. And the if-statement should check for the new value of X<\/strong> which is 20 instead of 15 (as in LAB7)<\/span><\/p>\n

\n
void interrupt ISR ()\r\n{\r\n\u00a0\u00a0 \/\/ Check The Flag Bit\r\n\u00a0\u00a0 if (TMR1IF)\r\n\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C++;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if(C==20)  \/\/ Note that we're counting up to 20 timer overflows!\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Event2 = (e.g. Toggle LED, Stop perupheral, Take ADC reading, etc)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0...\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Clear The Global Counter\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C = 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0 \u00a0 \u00a0 \/\/ Preload The Value To TMR1 Register Every Overflow Interrupt\r\n\u00a0 \u00a0 \u00a0 TMR1 = 15535;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TMR1IF = 0; \/\/ Clear The Flag Bit\r\n\u00a0\u00a0 }\r\n}<\/pre>\n

 <\/p>\n<\/div>\n

And that’s it! Implementing the timer preloading technique in this method should take no longer than 5-minutes to perform the previous couple of steps!<\/span><\/p>\n

 <\/p>\n


\n

\u00a0Generate 1sec Delay With Timer Preloading – LAB\u00a0<\/span><\/strong><\/span><\/h3>\n

 <\/p>\n\n\n\n\n\n\n
Lab Name<\/span><\/strong><\/span><\/td>\nGenerate 1-sec Delay With Timer Preloading<\/span><\/td>\n<\/tr>\n
Lab Number<\/span><\/strong><\/span><\/td>\n8<\/span><\/td>\n<\/tr>\n
Lab Level<\/span><\/strong><\/span><\/td>\nIntermediate<\/span><\/td>\n<\/tr>\n
Lab Objectives<\/span><\/strong><\/span><\/td>\nLearn how to use the timer preloading technique to generate 100% accurate time intervals with Timer1 Module. And double-check the results.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

\u00a0 \u00a0 \u00a0 \u00a01. Coding\u00a0 \u00a0 \u00a0 \u00a0<\/strong><\/span><\/h4>\n

 <\/p>\n

Open<\/strong> the MPLAB IDE and create a new project name it “Timer Preloading”. If you have some issues doing so, you can always refer to the previous tutorial using the link below.<\/span><\/p>\n

\"timer-preloading\"<\/a><\/p>\n

Set<\/strong> the configuration bits to match the generic setting which we’ve stated earlier. And if you also find troubles creating this file, you can always refer to the previous tutorial using the link below.<\/span><\/p>\n

\"timer-preloading\"<\/a><\/p>\n

Now, open the main.c<\/strong> file and let’s start developing the firmware for our project.<\/span><\/p>\n

Our first task is to configure the RB0<\/strong> to be an output pin (for LED) and set it to be OFF (initially)<\/span><\/p>\n

\n
TRISB0 = 0;\r\nRB0 = 0;<\/pre>\n

Now, we’ll configure the Timer1 module to operate in timer mode. And don’t forget to preload the 15535 value which we’ve previously calculated.<\/span><\/p>\n<\/div>\n

\n
\/\/ -- [[ Configure Timer1 To Operate In Timer Mode\u00a0 ]] --\r\n\r\n\/\/ Preload The Value Which We've Calculated To The TMR1 16-Bit Register!\r\nTMR1 = 15535;\r\n\/\/ Choose the local clock source (timer mode)\r\nTMR1CS = 0;\r\n\/\/ Choose the desired prescaler ratio (1:1)\r\nT1CKPS0 = 0;\r\nT1CKPS1 = 0;\r\n\/\/ Event1 = LED ON\r\nRB0 = 1;\r\n\/\/ Switch ON Timer1 Module!\r\nTMR1ON = 1;<\/pre>\n

Now, it’s time to configure the timer overflow interrupt and write the ISR handler for it. The configuration step is the same as we’ve been doing for a while.<\/span><\/p>\n<\/div>\n

\n
\/\/ -- [[ Interrupts Configurations ]] --\r\nTMR1IE = 1; \/\/ Timer1 Interrupt Enable Bit\r\nTMR1IF = 0; \/\/ Clear The Interrupt Flag Bit\r\nPEIE = 1;\u00a0\u00a0 \/\/ Peripherals Interrupts Enable Bit\r\nGIE = 1;\u00a0\u00a0\u00a0\u00a0\/\/ Global Interrupts Enable Bit<\/pre>\n

Then, we\u2019ll handle the Timer1 overflow interrupt by writing the ISR (interrupt service routine)<\/span><\/p>\n<\/div>\n

\n
\n
\n
void interrupt ISR ()\r\n{\r\n\u00a0\u00a0 \/\/ Check The Flag Bit\r\n\u00a0\u00a0 if (TMR1IF)\r\n\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C++;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if(C==20)\u00a0\u00a0\/\/ Note that we're counting up to 20 timer overflows!\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Event2 = Toggle LED\r\n\u00a0 \u00a0 \u00a0 \u00a0 RB0 = ~RB0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Clear The Global Counter\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C = 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0 \u00a0 \u00a0 \/\/ Preload The Value To TMR1 Register Every Overflow Interrupt\r\n\u00a0 \u00a0 \u00a0 TMR1 = 15535;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TMR1IF = 0; \/\/ Clear The Flag Bit\r\n\u00a0\u00a0 }\r\n}<\/pre>\n<\/div>\n<\/div>\n<\/div>\n
\n
\n
And That’s pretty much it! The Full Code Listing For This LAB is Shown Below<\/span><\/div>\n
<\/div>\n
Full Code Listing For LAB-8<\/strong><\/span><\/div>\n<\/div>\n<\/div>\n
\n
#include \"config.h\"\r\n#include <stdint.h>\r\n\r\nuint8_t C = 0; \/\/ Global Counter Variable\r\n\r\nvoid main()\r\n{\r\n\u00a0\u00a0\/\/ -- [[\u00a0\u00a0IO Configurations ]] --\r\n\u00a0\u00a0TRISB0 = 0;\r\n\u00a0\u00a0RB0 = 0;\r\n\r\n\u00a0\u00a0\/\/ -- [[ Configure Timer1 To Operate In Timer Mode&nbsp; ]] --\r\n\u00a0 \/\/ Preload The Value Which We've Calculated To The TMR1 16-Bit Register!\r\n\u00a0 TMR1 = 15535;\r\n\u00a0\u00a0\/\/ Choose the local clock source (timer mode)\r\n\u00a0\u00a0TMR1CS = 0;\r\n\u00a0\u00a0\/\/ Choose the desired prescaler ratio (1:1)\r\n\u00a0\u00a0T1CKPS0 = 0;\r\n\u00a0\u00a0T1CKPS1 = 0;\r\n\u00a0\u00a0\/\/ Event1 = LED ON\r\n\u00a0\u00a0RB0 = 1;\r\n\u00a0\u00a0\/\/ Switch ON Timer1 Module!\r\n\u00a0\u00a0TMR1ON = 1;\r\n\r\n\u00a0\u00a0\/\/ -- [[ Interrupts Configurations ]] --\r\n\u00a0\u00a0TMR1IE = 1; \/\/ Timer1 Interrupt Enable Bit\r\n\u00a0\u00a0TMR1IF = 0; \/\/ Clear The Interrupt Flag Bit\r\n\u00a0\u00a0PEIE = 1;\u00a0\u00a0 \/\/ Peripherals Interrupts Enable Bit\r\n\u00a0\u00a0GIE = 1;\u00a0\u00a0\u00a0\u00a0\/\/ Global Interrupts Enable Bit\r\n\u00a0\u00a0\r\n\u00a0\u00a0while(1)\r\n\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\/\/ Stay IDLE ,, Timer Interrupt Will Handle Everything For Us !\r\n\u00a0\u00a0}\r\n}\r\n\r\n\/\/ Interrupt Service Routine - ISR\r\nvoid interrupt ISR ()\r\n{\r\n\u00a0\u00a0 \/\/ Check The Flag Bit\r\n\u00a0\u00a0 if (TMR1IF)\r\n\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C++;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if(C==20)\u00a0\u00a0\/\/ Note that we're counting up to 20 timer overflows!\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Event2 = Toggle LED\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0RB0 = ~RB0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Clear The Global Counter\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C = 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0 \u00a0 \u00a0 \/\/ Preload The Value To TMR1 Register Every Overflow Interrupt\r\n\u00a0 \u00a0 \u00a0 TMR1 = 15535;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TMR1IF = 0; \/\/ Clear The Flag Bit\r\n\u00a0\u00a0 }\r\n}<\/pre>\n

And that\u2019s it! Implementing the timer preloading technique in this method should take no longer than several minutes to accomplish and develop the necessary firmware. Now, cross your fingers and Hit that compile button!<\/span><\/p>\n<\/div>\n

It should work flawlessly for you. And it’s the time to have your own hands-on experience and test some different values and settings! And I’ll be here to help you if it gets dodgy.<\/span><\/p>\n

 <\/p>\n

\u00a0 \u00a0 \u00a0 \u00a02. Simulation\u00a0 \u00a0 \u00a0 \u00a0<\/strong><\/span><\/h4>\n

The simulation results for this LAB should be a pure square wave with a 1-sec\u00a0pulse width as shown below<\/span><\/p>\n

\"timer-preloading\"<\/p>\n

Compare that output diagram with the one we got in the previous LAB7 and notice the difference<\/span><\/p>\n\n\n\n\n
\"timer-preloading\"<\/td>\n\"timer-preloading\"<\/td>\n<\/tr>\n
Without Timer Preloading<\/span><\/p>\n

The Output Time Interval T<\/strong>out<\/sub> = 0.98<\/strong> second<\/span><\/td>\n

With Timer Preloading<\/span><\/p>\n

The Output Time Interval T<\/strong>out<\/sub> = 1<\/strong> second (Exactly<\/strong>)!<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n


\n

\u00a0 \u00a0Second Method Of Timer Preloading\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n

 <\/p>\n

For those who are interested in the second way of implementing the timer preloading technique. This should be a bonus (optional) section of this tutorial. Anyway, let’s recap the main problem that we’re trying to solve via time preloading. Which is most of the time we get rational numbers as a value for X<\/strong> which is the number of overflows required to complete the desired time interval (Tout<\/sub><\/span>).<\/p>\n

Let’s consider the following case, we’ve got a system running @ 4MHz, with 16-Bit timer, 1:1 Prescaler, and we need to get a time interval of (Tout<\/sub> = 2 seconds). Assuming that the timer starts counting at zero (TMR1 = 0), then the general equation will give the following results.<\/span><\/p>\n

\"timer-preloading\"<\/p>\n

X<\/strong> = (1 \/ 0.06553) = 30.52 overflows<\/span><\/p>\n

As you’ve noticed, X<\/strong> is not an integer! We also can not neglect the fraction part (0.52 overflow) it’s not an option. But the idea of the method we’re talking about right now is to preload the timer module in order to perform a (0.52 of the full Toverflow<\/sub> period). Which is 0.52 * 0.06553 = 0.034 second. And here is the step-by-step procedure in order to calculate and implement this method of preloading.<\/span><\/p>\n

\u00a0Step1 – Calculate the initial value to be loaded\u00a0<\/span><\/h4>\n

\u00a0The time interval value for (0.52 of Toverflow<\/sub>) is = 0.034 second. So let’s substitute for Tout<\/sub> by 0.034, X = 1, and solve for the initial value TMR1<\/span><\/p>\n

\"timer-preloading\"<\/p>\n

Thus, the value which we’ll be loading to Timer1 is => (TMR1 = 34002)<\/span><\/p>\n

\u00a0Step2 – Configure The Timer1 Module\u00a0<\/span><\/h4>\n
\n
\/\/ -- [[ Configure Timer1 To Operate In Timer Mode\u00a0 ]] --\r\n\r\n\/\/ Load The Value Which We've Calculated To The TMR1 Register\r\nTMR1 = 34002;\r\n\/\/ Choose the local clock source (timer mode)\r\nTMR1CS = 0;\r\n\/\/ Choose the desired prescaler ratio (1:1)\r\nT1CKPS0 = 0;\r\nT1CKPS1 = 0;\r\n\/\/ Event1 = LED ON\r\nRB0 = 1;\r\n\/\/ Switch ON Timer1 Module!\r\nTMR1ON = 1;<\/pre>\n

 <\/p>\n<\/div>\n

\u00a0Step3 – Write The ISR Handler\u00a0<\/span><\/h4>\n

Just pay attention to where we’re loading the specific value to the TMR1 register. It’s done only once before the first overflow, and the Timer1 will be counting from (0 to 65535) for all of the consecutive 30-overflows till the end of the pre-calculated Tout<\/sub> time interval. Which means that we load it once only when (C == 31)<\/span><\/p>\n

\n
void interrupt ISR ()\r\n{\r\n\u00a0\u00a0 \/\/ Check The Flag Bit\r\n\u00a0\u00a0 if (TMR1IF)\r\n\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C++;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if(C==31) \/\/ Note That We're Taking The First Overflow Into Account!\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Event2 = Toggle LED\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0RB0 = ~RB0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Clear The Global Counter\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C = 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n      \/\/ Load The Value Which We've Calculated To The TMR1 Register\r\n      TMR1 = 34002;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TMR1IF = 0; \/\/ Clear The Flag Bit\r\n\u00a0\u00a0 }\r\n}<\/pre>\n

And That’s it! Yea it’s actually more efficient way as it seems to be. However, from my own perspective, I can see that it’s a little bit trickier and not a beginner-friendly way to do this job. Anyway, Here is the full code listing for the time preloading implementation (method-2). Cross your fingers! Hit the compile button! Then, it’s the time to play with it and do some testing on your own.<\/span><\/p>\n<\/div>\n

The Full Code Listing For LAB-8 Using The 2nd<\/sup> Method of Timer Preloading<\/span><\/strong><\/p>\n

\n
#include \"config.h\"\r\n#include <stdint.h>\r\n\r\nuint8_t C = 0; \/\/ Global Counter Variable\r\n\r\nvoid main()\r\n{\r\n\u00a0\u00a0\/\/ -- [[\u00a0\u00a0IO Configurations ]] --\r\n\u00a0\u00a0TRISB0 = 0;\r\n\u00a0\u00a0RB0 = 0;\r\n\r\n\u00a0\u00a0\/\/ -- [[ Configure Timer1 To Operate In Timer Mode&nbsp; ]] --\r\n\u00a0 \/\/ Load The Value Which We've Calculated To The TMR1 Register\r\n\u00a0 TMR1 = 34002;\r\n\u00a0\u00a0\/\/ Choose the local clock source (timer mode)\r\n\u00a0\u00a0TMR1CS = 0;\r\n\u00a0\u00a0\/\/ Choose the desired prescaler ratio (1:1)\r\n\u00a0\u00a0T1CKPS0 = 0;\r\n\u00a0\u00a0T1CKPS1 = 0;\r\n\u00a0\u00a0\/\/ Event1 = LED ON\r\n\u00a0\u00a0RB0 = 1;\r\n\u00a0\u00a0\/\/ Switch ON Timer1 Module!\r\n\u00a0\u00a0TMR1ON = 1;\r\n\r\n\u00a0\u00a0\/\/ -- [[ Interrupts Configurations ]] --\r\n\u00a0\u00a0TMR1IE = 1; \/\/ Timer1 Interrupt Enable Bit\r\n\u00a0\u00a0TMR1IF = 0; \/\/ Clear The Interrupt Flag Bit\r\n\u00a0\u00a0PEIE = 1;\u00a0\u00a0 \/\/ Peripherals Interrupts Enable Bit\r\n\u00a0\u00a0GIE = 1;\u00a0\u00a0\u00a0\u00a0\/\/ Global Interrupts Enable Bit\r\n\r\n\u00a0\u00a0while(1)\r\n\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\/\/ Stay IDLE ,, Timer Interrupt Will Handle Everything For Us !\r\n\u00a0\u00a0}\r\n}\r\n\r\n\/\/ Interrupt Service Routine - ISR\r\nvoid interrupt ISR ()\r\n{\r\n\u00a0\u00a0 \/\/ Check The Flag Bit\r\n\u00a0\u00a0 if (TMR1IF)\r\n\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C++;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if(C==31)\u00a0 \/\/ Note That We're Taking The First Overflow Into Account!\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Event2 = Toggle LED\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0RB0 = ~RB0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Clear The Global Counter\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C = 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n      \/\/ Load The Value Which We've Calculated To The TMR1 Register\r\n      TMR1 = 34002;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TMR1IF = 0; \/\/ Clear The Flag Bit\r\n\u00a0\u00a0 }\r\n}<\/pre>\n<\/div>\n

That’s it actually. Try calculating and generating a 1-second time interval. The value to preload should be nearly 34002<\/strong> and X<\/strong>=15.26 Hence, the C<\/strong> counter should be counting up to 16. Double-Check these results yourself and try other values if you wish. And I’ll be here for help!<\/span><\/p>\n

 <\/p>\n


\n

\u00a0 \u00a0Conclusion\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n

 <\/p>\n

\u00a0 1\u00a0\u00a0<\/span><\/p>\n

Use oscilloscope and logic analyzer to double check your output validity. Get familiar with your tools to find out if everything is running OK or there is a problem. You should also be able to figure out when and where changes have to be made.<\/span><\/p>\n

\u00a0 2\u00a0\u00a0<\/span><\/p>\n

The timer preloading technique that we’ve discussed in this tutorial will help you generate accurate time intervals with timer modules without any glitches. However, if improperly implemented, it’ll do more of a headache than good. So just be careful and take the time to calculate the required stuff.<\/span><\/p>\n

 <\/p>\n

If you find this useful, then share it with your network and let me know that you’re willing to see more of my tutorials<\/span>.\u00a0See You In The Next Tutorials… Good Luck ^^<\/span><\/p>\n

 <\/p>\n

 <\/p>\n\n\n\n
\"Previous<\/a><\/td>\nPrevious Tutorial<\/strong><\/a><\/td>\nTutorial 11<\/span><\/strong><\/span><\/td>\nNext Tutorial<\/strong><\/a><\/td>\n\"Next<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"

In this tutorial, we’ll discuss how to generate accurate time intervals with timer modules using the timer preloading technique. You’ll learn both how to measure and eliminate error in timer output intervals<\/p>\n","protected":false},"author":1,"featured_media":2289,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28,30,27],"tags":[13,14,15,42,41,38,32,33,16,31,17,18,44,43,34,22],"yoast_head":"\nTimer PreLoading | How To Generate Delay With Timer Module? – DeepBlue<\/title>\n<meta name=\"description\" content=\"In this tutorial, we'll discuss how to generate accurate time intervals with timer modules using the timer preloading technique.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Timer PreLoading | How To Generate Delay With Timer Module? – DeepBlue\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we'll discuss how to generate accurate time intervals with timer modules using the timer preloading technique.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"DeepBlue\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/khaled.elrawy.359\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/khaled.elrawy.359\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-01T23:41:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-17T20:53:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"720\" \/>\n\t<meta property=\"og:image:height\" content=\"340\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Khaled Magdy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Khaled Magdy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/\"},\"author\":{\"name\":\"Khaled Magdy\",\"@id\":\"https:\/\/deepbluembedded.com\/#\/schema\/person\/30259d66cf68c6c681562dbe551b7867\"},\"headline\":\"Timer PreLoading | How To Generate Delay With Timer Module?\",\"datePublished\":\"2018-08-01T23:41:47+00:00\",\"dateModified\":\"2023-08-17T20:53:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/\"},\"wordCount\":2168,\"commentCount\":15,\"publisher\":{\"@id\":\"https:\/\/deepbluembedded.com\/#\/schema\/person\/30259d66cf68c6c681562dbe551b7867\"},\"image\":{\"@id\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg\",\"keywords\":[\"Embedded C\",\"Embedded Systems Tutorials\",\"Firmware\",\"Interrupt Handler\",\"Interrupt Hanlding\",\"Interrupts\",\"Learn Embedded Systems\",\"Learn Microcontrollers Programming\",\"Microchip PIC Tutorials\",\"Microcontroller Programming\",\"Microcontrollers\",\"MPLAB\",\"Timer Module\",\"Timers\",\"Tutorials\",\"XC8\"],\"articleSection\":[\"Embedded Systems\",\"Embedded Tutorials\",\"Microchip PIC\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/\",\"url\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/\",\"name\":\"Timer PreLoading | How To Generate Delay With Timer Module? – DeepBlue\",\"isPartOf\":{\"@id\":\"https:\/\/deepbluembedded.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg\",\"datePublished\":\"2018-08-01T23:41:47+00:00\",\"dateModified\":\"2023-08-17T20:53:14+00:00\",\"description\":\"In this tutorial, we'll discuss how to generate accurate time intervals with timer modules using the timer preloading technique.\",\"breadcrumb\":{\"@id\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#primaryimage\",\"url\":\"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg\",\"contentUrl\":\"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg\",\"width\":\"720\",\"height\":\"340\",\"caption\":\"timer-preloading-tutorial\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/deepbluembedded.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Timer PreLoading | How To Generate Delay With Timer Module?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/deepbluembedded.com\/#website\",\"url\":\"https:\/\/deepbluembedded.com\/\",\"name\":\"DeepBlueMbedded\",\"description\":\"Embedded Systems And Computer Engineering Tutorials & Articles\",\"publisher\":{\"@id\":\"https:\/\/deepbluembedded.com\/#\/schema\/person\/30259d66cf68c6c681562dbe551b7867\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/deepbluembedded.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/deepbluembedded.com\/#\/schema\/person\/30259d66cf68c6c681562dbe551b7867\",\"name\":\"Khaled Magdy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/deepbluembedded.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ed20e191de77104a5b091d9bc5821c4a?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ed20e191de77104a5b091d9bc5821c4a?s=96&r=g\",\"caption\":\"Khaled Magdy\"},\"logo\":{\"@id\":\"https:\/\/deepbluembedded.com\/#\/schema\/person\/image\/\"},\"description\":\"Principal Embedded Systems Engineer with years of experience in embedded software and hardware design. I work in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI\/ML, and other fields I'm passionate about. I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?\",\"sameAs\":[\"https:\/\/deepbluembedded.com\",\"https:\/\/www.facebook.com\/khaled.elrawy.359\/\",\"https:\/\/www.instagram.com\/deepbluembedded\/\",\"https:\/\/www.linkedin.com\/in\/khaled-magdy-\/\",\"https:\/\/www.youtube.com\/channel\/UCzLSrNZD4rCjSCOVU9hknvA\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Timer PreLoading | How To Generate Delay With Timer Module? – DeepBlue","description":"In this tutorial, we'll discuss how to generate accurate time intervals with timer modules using the timer preloading technique.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Timer PreLoading | How To Generate Delay With Timer Module? – DeepBlue","og_description":"In this tutorial, we'll discuss how to generate accurate time intervals with timer modules using the timer preloading technique.","og_url":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/","og_site_name":"DeepBlue","article_publisher":"https:\/\/www.facebook.com\/khaled.elrawy.359\/","article_author":"https:\/\/www.facebook.com\/khaled.elrawy.359\/","article_published_time":"2018-08-01T23:41:47+00:00","article_modified_time":"2023-08-17T20:53:14+00:00","og_image":[{"width":"720","height":"340","url":"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg","type":"image\/jpeg"}],"author":"Khaled Magdy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Khaled Magdy","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#article","isPartOf":{"@id":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/"},"author":{"name":"Khaled Magdy","@id":"https:\/\/deepbluembedded.com\/#\/schema\/person\/30259d66cf68c6c681562dbe551b7867"},"headline":"Timer PreLoading | How To Generate Delay With Timer Module?","datePublished":"2018-08-01T23:41:47+00:00","dateModified":"2023-08-17T20:53:14+00:00","mainEntityOfPage":{"@id":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/"},"wordCount":2168,"commentCount":15,"publisher":{"@id":"https:\/\/deepbluembedded.com\/#\/schema\/person\/30259d66cf68c6c681562dbe551b7867"},"image":{"@id":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg","keywords":["Embedded C","Embedded Systems Tutorials","Firmware","Interrupt Handler","Interrupt Hanlding","Interrupts","Learn Embedded Systems","Learn Microcontrollers Programming","Microchip PIC Tutorials","Microcontroller Programming","Microcontrollers","MPLAB","Timer Module","Timers","Tutorials","XC8"],"articleSection":["Embedded Systems","Embedded Tutorials","Microchip PIC"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/","url":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/","name":"Timer PreLoading | How To Generate Delay With Timer Module? – DeepBlue","isPartOf":{"@id":"https:\/\/deepbluembedded.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg","datePublished":"2018-08-01T23:41:47+00:00","dateModified":"2023-08-17T20:53:14+00:00","description":"In this tutorial, we'll discuss how to generate accurate time intervals with timer modules using the timer preloading technique.","breadcrumb":{"@id":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#primaryimage","url":"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg","contentUrl":"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg","width":"720","height":"340","caption":"timer-preloading-tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/deepbluembedded.com\/timer-preloading-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/deepbluembedded.com\/"},{"@type":"ListItem","position":2,"name":"Timer PreLoading | How To Generate Delay With Timer Module?"}]},{"@type":"WebSite","@id":"https:\/\/deepbluembedded.com\/#website","url":"https:\/\/deepbluembedded.com\/","name":"DeepBlueMbedded","description":"Embedded Systems And Computer Engineering Tutorials & Articles","publisher":{"@id":"https:\/\/deepbluembedded.com\/#\/schema\/person\/30259d66cf68c6c681562dbe551b7867"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/deepbluembedded.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/deepbluembedded.com\/#\/schema\/person\/30259d66cf68c6c681562dbe551b7867","name":"Khaled Magdy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/deepbluembedded.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ed20e191de77104a5b091d9bc5821c4a?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ed20e191de77104a5b091d9bc5821c4a?s=96&r=g","caption":"Khaled Magdy"},"logo":{"@id":"https:\/\/deepbluembedded.com\/#\/schema\/person\/image\/"},"description":"Principal Embedded Systems Engineer with years of experience in embedded software and hardware design. I work in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI\/ML, and other fields I'm passionate about. I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?","sameAs":["https:\/\/deepbluembedded.com","https:\/\/www.facebook.com\/khaled.elrawy.359\/","https:\/\/www.instagram.com\/deepbluembedded\/","https:\/\/www.linkedin.com\/in\/khaled-magdy-\/","https:\/\/www.youtube.com\/channel\/UCzLSrNZD4rCjSCOVU9hknvA"]}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2018\/06\/Timer-Preloading.jpg","jetpack_shortlink":"https:\/\/wp.me\/p9SirL-zl","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/posts\/2191"}],"collection":[{"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/comments?post=2191"}],"version-history":[{"count":21,"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/posts\/2191\/revisions"}],"predecessor-version":[{"id":3571,"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/posts\/2191\/revisions\/3571"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/media\/2289"}],"wp:attachment":[{"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/media?parent=2191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/categories?post=2191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/deepbluembedded.com\/wp-json\/wp\/v2\/tags?post=2191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}