Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

writing efficient code PIC microcontrollers

Status
Not open for further replies.

gehan_s

Member level 3
Member level 3
Joined
Aug 31, 2012
Messages
62
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Sri Lanka
Visit site
Activity points
1,799
Dear all,

Lately I have been working with some projects where timing is critical and hence have decided to learn how to write more efficient code.

Can you direct me some where or give some pointers regarding things like multiplication, division and ANY other ways of making my code run faster. I am using MikroC pr for PIC.

Best regards
 

various techniqes can be used, e.g. a few ideas
1. addition and subtraction take about the same time, multiplication longer and division many times longer - I have speeded up applications by sveral hundred times by changing algorithms to remove division
2. use 8 or 16 bit integer arithmetic rather than 32 or 64 bit if the application data allows
3. floating point arithmetic takes longer than integer in particular where the processor does not have a floating point coprocessor - again 32 bit floating point arithmetic is faster than 64 bit faster than 128 bit etc
4. use shift opertors << for integer multiply by 2 or >> for division by 2 (take care when using signed numbers in that the C standard does not specify if >> is logical or arithmetic shift)
5. using pointers rather than array indices to access arrays (although the code my be clearer to readers when indices are used)
6. look at loops - are there calculations which can be moved outside the loop (an optimising compler should find these for you)

you can write time critical parts of an application in assembly language (assuming one has the skill!)

assuming the technology supports it one can increase the clock speed, move a higher speed version of a processor, a more powerful family (one has to then port the application) or to processors with application specific hardware such as DSP processors or even to multiprocessors

compilers ofen have various levels of optimisation (for code size, speed, etc)
if using free versions of compilers often one has to purchase a license to obtain the best optimisation
 
Last edited:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top