July 25, 2009

The IDE and The Compiler

This is a very basic article. I would say for newbie's or for those who are misguided. Also, I was asked this question by some one recently. The question or rather statement "Tourbo C is a nice compiler for it has a very nice gui. Gcc gui is not good."

Well the problem here is that we are getting confused with the compiler and the IDE (Integrated Development Environment). The compiler is usually a parser ( Text paser for simplicity) that runs through a text file ( which we typically name with extensions like .c, .h etc) and feed it to this parser. The job of the parser ( or compiler hence forth) is to parse the file and output another file based on certain rules which should be adhered to by the writer of the text ( or code henceforth ). The other file that is usually output is object file. Note that as intermediate step the compiler generates assembly code which usally not output ( unless you tell the compiler to show you this specifically by a commandline option -S for gcc) . The object code which can be linked to form the executable. COFF & ELF are common object file formats, however compiler writers are free to choose what the want.

Now coming to the IDE. IDE has really got nothing to do with your compiler. The key words are explained here
Integrated: Usually every compiler vendor comes up with his/her own Editor to help the coder to write his code. Why a specific editor? Typically, each compiler provides it own set of special key words etc which the editor can highlight is specific colors and other features like codesense are provided for the ease of the coder.
Development : Yeah! we all write code to do something or develop something
Environment : This is the key term. The IDE provides an environment for the coder where he doesn't need to know the intricacies of compiler and more low level details of how to use it. You can can just take the IDE and start writing your code without bothering about what are the command line arguments that need to be passed to compiler. Also, you need not worry about feeding the include paths etc ( not all IDE's have this feature).

Now i try to defend gcc. I have used gcc with two ( or three??) IDE's and it works great. The simple ones are dev-ccp & code::Blocks. The difficult ones are actually extinct now....codewright.  Note that the best part about gcc is that it is a single compiler that will allow you to compiler with a whole lot of customizations through the command line arguments. I remember a project where i was using gcc only for creating dependency files which used to get fed to a embedded compiler which unfortunately did not have the capability to make dependency files ( Folks at my previous firm will know about this!!).
Why we need dependency file will be explained in another post soon.  Bis dan.....
 Please leave your comment. You can subscribe to this blog by using the links under "Subscribe" section.




Powered by ScribeFire.

July 19, 2009

Engine basics - Knocking

This post talks a bit about a concept called "Knocking" which is very common in Spark Ignition Engines having very high compression ratio.
The question we need to answer first is what is Knocking?
"Knocking" is a metallic pinging sound that is caused inside the engine cylinder & leads to high intensity vibrations in the Engine block ( usually causing metal fatigue in the cylinder walls). If the engine knocks for very long duration then this might have serious impact on the usability of the engine and on the engine life.
What causes "Knocking"?
Flame front:
The power inside the cylinder which is generated when a spark ignites the air-fuel mixture leading to a flame front. The flame front is a high velocity pressure wave that travels, after originating near the spark plug, downwards to push the piston head and ensure that our engine keeps running.
Now, what happens is that based on the fuel quality among many other factors there are certain spots inside the cylinder with some carbon deposits.If the cylinder temperature keeps rising due to ignitions then at some point of time these hot spots reach a temperature where they are capable to ignite the air fuel mixture or the yet unburnt gases (also called End gas). Simply put there is sufficient heat accumulation at certain points that these act as potential spark plugs.
The Problem:
This causes a problem because we do not have any control over these spontaneously created spark plugs ( so to say). This means that they can ignite the end gas at any point of time. In homogeneous operation of engine ( more about this mode in future posts), the mixture is fairly rich and these hot spots have energy sufficient to create a ignition of the air-fuel mixture.  This phenomenon  is often known as "Detonation".This ignition causes a pressure wave to travel from the spot towards the periphery. This Flame-Front if collides with the flame front travelling from the spark plug will result  in wo very high pressure waves to bang into each other. This leads to very high pressure peaks which put extreme amounts of stress on the cylinder walls. Continuous Knocking might lead to permanent stresses getting formed in the cylinder walls & the piston head which eventually will lead to their failure.
How to Avoid it ?
A few years back when "leaded Petrol" used to rule the market the folks added something known as Anti-Knock in the petrol to ensure that it did not knock. This however, lead to higher amount of particulate matter in the exhaust and also was not good for the cylinder walls.The anti knock was a Lead compound which i cannot remember at this point of time.
These days we use more of "Unleaded Petrol" and there has to be  different mechanism to control the "Knocking". This is done these days by ensuring that the engine temperature doesn't reach very high ( then there is lesser chance of hot spots getting created). One of the methods employed to do this is EGR. Exhaust Gas Recirculation, ensures that he temperature of the engine come down apart from having benefits like enhanced fuel efficiency and reduced NOx in the exhaust. However, that is a different topic and will be dealt a little later. The other method used in conjunction with the EGR is spark retard. Spark retard will ensure that you ignite the air-fuel mixture late enough that there will be no pressure peaks. When we do not have pressure peaks the chances of knocking are lesser.
Finally, use of high octane fuel will result in better combustion of the fuel and lesser hot spot contribution because of poor fuel quality. The reduction of hot-spots will result in reduced Knocking even at higher engine temperatures.
Some links that give more info on how it is detected etc
[1]

Please leave your comment. You can subscribe to this blog by using the links under "Subscribe" section.



Powered by ScribeFire.



July 17, 2009

No Posts for some time

I have been busy with my Targetlink & Simulink Modelling activity & also a bit held up with the Income Tax Filing process ( Though this time it is quite simple & i love it !!). There have been some sawtooth waveforms formed by the BSE Sensex index of late & this is giving me some sleepless nights....Hope to put in some interesting stuff soon....






Powered by ScribeFire.

July 3, 2009

Const Keyword - Coding Myth 3

This post talks about the "C" keyword "const". It is very often thought that making a variable "const" ensures that it gets placed in the non-volatile memory (ROM or flash). But how true is this?

Well to start with w.r.t the ansi "C" compiler, the "const" keyword just tells the compiler that the user doesn't intend to modify the variable.
E.g.
           const unsigned int Gctrl_NoOfGears= 10;
so if i try to do this
           Gctrl_NoOfGears +=1;
I can either except a warning or an error. something like this
error: assignment of read-only variable `Gctrl_NoOfGears'
However, does this warrant me that the variable is now placed inside the memory in an non-volatile area.
Well, the answer is it is compiler (settings) dependent.
Why?
Most embedded compilers are very smart and automatically place the constants in the ROM/ flash area. However, some times the flash or ROM is used only as program memory and NOT as data memory. In which case there is no way (directly) that the compiler can place this in the program memory. Also In these processors the program memory is not directly accesible because the program & data are stored in differrent memory location & have different busses to access.  In such processors writing
const char DisplayStr[] = "Welcome";
will not cause DisplayStr to go into the ROM area.
You will have to do this via some compiler pragma's like
#pragma section start ROM
const char DisplayStr[] = "Welcome";
#pragma section end ROM
to make the compiler understand that it has to place the value in ROM & not in the RAM area.
Do I have to worry?
As a novice or some one programming for a simple system NO. However, when you are running low on resources and for various other reasons it makes sense to have a look at what the compilers is doing when you say "const". I repeat MOST compilers are clever enough to put the data into the ROM automatically.
The best practice is always to have a glance into the map file to ensure that you have everything at the right places.
Also, in one of the future posts i will be talking about another usages of const and how some constants are present even without your knowledge ( also little talk about const volatile...the common question in any interview on "C").

Please leave your comment. You can subscribe to this blog by using the links under "Subscribe" section.

Previous coding myths here {1} ,{2}




Powered by ScribeFire.