View previous topic :: View next topic |
Author |
Message |
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
counter value increment time |
Posted: Sun Apr 22, 2018 11:12 pm |
|
|
Hello guys my question is how much time required for each increment of counter value. for example
N=0 ;
N++ ;
How much time required for each increment of N ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Mon Apr 23, 2018 1:04 am |
|
|
Depends what 'N' 'is, the processor used, and the clock rate.
Look in the manual. Section 'Common questions and answers', sub-section 'How much time do math operations take'.
Nice little table, giving operation times for a number of different clock rates and processors.
If N is an int8, then the entry for addition on an int8 is what is involved. If N is an int16 then the entry for int16 applies. etc. etc. |
|
|
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
|
Posted: Mon Apr 23, 2018 1:48 am |
|
|
Can't find Section 'Common questions and answers'. Please mention the page from CCS C Compiler Manual 2018. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Mon Apr 23, 2018 2:00 am |
|
|
You could simulate in MPLAB SIM with a watch window and the stopwatch.
Stepping through the code will tell you for all number types.
Mike |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Mon Apr 23, 2018 3:07 am |
|
|
Compiler manual, not the pdf. Contents. About the thirteenth entry down. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Apr 23, 2018 4:44 am |
|
|
You could go 'old school'.
1) compile a small program, use 4MHz as the clock speed.
2) dump( print ) the listing ( programname.lst file).
3) look for the machine code that was built to execute those instructions.
4) find the 'instruction set' in the datasheet for your PIC.
5) lookup the instructions and see the time it takes.
Now PICs are great as most instructions only take 1 'cycle'. (goto and jumps take 2), it says so, in the chart ! 4MHz clock speed is 'magic' as the PIC will take clock speed/4 to execute a machine cycle, so each machine cycle takes 4MHz/4 so, 1 us to execute.
The good thing about doing it this way, is you can LEARN a LOT about PICs. You'll also see how CCS converts C into machine code !
Jay |
|
|
|