Posts

Showing posts from May, 2018

How long the piece of code is executed?

Image
Hello, Does anyone know how long piece of code is executed? Today I will teach you how to check it. To measure time there are needed two timestamps t1 and t2. Timestamp t1 describes time when the measurment is started, t2 when the measurment is finished. For this puprpose one gpio will be used. Speaking more precisely: t1 is when the rising edge occured t2 is when the falling edged occured Time of execution doSomething2 function equal is t2 - t1. It is showed at the picture below: Time will be measured by logic analyzer like this: This is one of the cheapest logic analyzer, but for this purpose is excellent. The oscilloscope can be used also. What will happen if the interrupt occurred during measurement? An interrupt breaks the execution of instructions and diverts its execution to interrupt service ...

Two ways to compare a variable in a condition statement

Image
Hello Imagine, we have to compare whether variable is equal 1. In this case variable is called "flag". There are two ways(even more) to achieve this task. First one is here: if(flag == 1) Second one is following: if(1 == flag) At the first glance both ways are the same, but really one of them is better. Do you know which one is better and why? Let's assume, that one equal sign has been skipped. What would happen in first case, and what in seceond case? In first case compiler does not report an error. In addition flag is set to true, therefore the output of the program is not the same, which we would expect. Is not it? In second case compiler report an error because this assignment is not possible. Therefore this sort of bug can be solved immediately. Definitely second method is bett...

What is this blog about?

Hi! My name is Mateusz In this blog I will write about embedded systems, microcontrollers, C language, FPGA's. See you soon.