CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how many instruction is certain function

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

how many instruction is certain function
PostPosted: Mon Oct 15, 2012 12:34 pm     Reply with quote

Hi!
I already asked about this question but I still don't understand.
How can I know how many instructions are needed for certain function?
For example How many instructions is
output_toggle(pin_xx) function. I have already take a look at the datasheet->instructions, but there is explained on assembler. The problem is I don't know assembler. Is there another way to solve my problem?
temtronic



Joined: 01 Jul 2010
Posts: 9169
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Oct 15, 2012 12:47 pm     Reply with quote

You need to print out the listing ( your_program_name.lst) and then look for the function you're interested in.

I suggest creating the simple 'blinking LED' program to see how it works.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Mon Oct 15, 2012 12:52 pm     Reply with quote

Do a search here.
No fixed answer. Several things affect even a simple instruction like this,while complex things like maths, can have dozens of answers:
For the simple I/O instructions:
1) Will depend on the chip.
2) Will depend on the I/O mode selected.
3) Will depend on what happens in front.

Reasons are:
1) Different operations on PIC16/18/24.
2) If standard I/O is selected TRIS will be updated as well.
3) On PIC 16 chips bank switching may be involved.

For maths, you then add the size of the variables involved, andwhere variables are placed.

A search here will find descriptions of all this, and solutions to time any particular instruction.

Best Wishes
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue Oct 16, 2012 2:47 am     Reply with quote

Also add in whether they are called with constant or variable parameters....

They aren't really functions in the normal C sense. They don't have fixed code, C or assembler. Instead they are requests to the compiler to put in appropriate code to provide that function given the available hardware and firmware resources. In other words, whatever code it needs to get the job done on that processor in that code context.

If you are really that time critical that every processor cycle counts then really you need more experience than you've got, and/or you need to go to assembler for the really critical bits to ensure known, repeatable timing.

However, so very often the application doesn't require as precise timing, and the programmer has misinterpreted some hardware requirement or something similar resulting in unnecessarily complex and difficult systems design, which so often means no real systems design at all.

I'm a professional, I do this for a living day in, day out. I don't need to know, and have never needed to know what you are asking. I have a good feel for what is faster and what is slower, and I know what to avoid. I very occasionally have to put in a cycle or two delay here and there at higher clock speeds, possibly conditionally compiled on clock speed, to ensure meeting of minimum timing requirements, for things such as DAC output latches (in other words, updating DAC outputs after sending new settings via SPI or I2C). Rarely do I need to do anything more precise. But then I usually design my own hardware too, and make sure I don't need any "special" timing, or else provide it in hardware as appropriate.

So, I have to ask the question: Why do you think you need to know how long these functions take?

RF Developer
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Oct 16, 2012 10:37 am     Reply with quote

When I have a time based program and I have a swol RC oscilator (4MHz) and I need to put some extra functions inside my code I should decrease my delay time to keep the overal cycle time.
For example: I have a
Quote:
whyle
cycle. That cycle should not be more than 20ms. I have already create that cycle, but I need to put some extra functions like:
Quote:
if(); statement ext.
So how many micro seconds i should decrease of the delay_us(x) to keep the timing of cycle the same?
That is why want to know functions cycle needed.
I hope you understand RF_Developer!
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Oct 16, 2012 10:44 am     Reply with quote

temtronic wrote:
You need to print out the listing ( your_program_name.lst) and then look for the function you're interested in.

I suggest creating the simple 'blinking LED' program to see how it works.

hth
jay

And how exactly does it work? I mean the printing of listing?
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Tue Oct 16, 2012 10:51 am     Reply with quote

When a program is compiled, it creates a .lst file. This is the assembler.
Seriously though, go back to what I said about searching here. The MPLAB stopwatch function, is by far the easiest way of getting your timing.

Best Wishes
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed Oct 17, 2012 2:01 am     Reply with quote

rikotech8 wrote:
When I have a time based program and I have a swol RC oscilator (4MHz) and I need to put some extra functions inside my code I should decrease my delay time to keep the overal cycle time.
For example: I have a
Quote:
whyle
cycle. That cycle should not be more than 20ms. I have already create that cycle, but I need to put some extra functions like:
Quote:
if(); statement ext.
So how many micro seconds i should decrease of the delay_us(x) to keep the timing of cycle the same?
That is why want to know functions cycle needed.
I hope you understand RF_Developer!


No, I don't understand.

What does "swol" mean?

You say you are using an RC 4MHz oscillator. That means that you timing is going to vary considerably: it is not stable with temperature and other factors. That means a few microseconds here and there is not likely to matter.

20ms is a long loop time. My loops, for much more complex code than I've ever seen on this forum, at 10MHz (crystal oscillator) on a PIC18F8585 take just over 2ms, and include some floating point (to convert ADC readings to volts, amps, etc.). To give a loop time of no more than 20ms should be easy for most code. What is your code doing to use up all that time? Do you have ANY delay_ () calls in your code?

Time critical code is better handled with timers providing a timebase tick, and your main loop then goes as fast as practical, this means the timing error is no greater than the maximum loop time.

Also, my comments regarding hardware stand: its a better way of getting precise timing IF it is really required.

All of this is just simple embedded systems design. Again I have to ask if your systems design is satisfactory. If you were one of my engineers, I'd be asking you some very detailed questions as to why you want to do what you say you need to do, and point you to some other, better, more flexible, ways of doing it.

RF Developer
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Oct 17, 2012 3:04 am     Reply with quote

You're making life too complicated for yourself.

If you have to re-calculated your timing loops very time you change your code you'll never finish. What happens when you've got conditional code which may go along several different paths. Each path will have to be carefully analysed to make sure that they all take the same number of cycles to execute. I don't think so!

Do what RF_Developer is suggesting.

Set up one of the hardware timer to create a (say) 20ms tick, i.e. interrupt at every 20ms and set a 20ms_flag.

Then your main goes like this

Code:
main(void)
{
  initialise_system();

  while (1)
  {
     do_other_code();
     while (!20ms_flag) {} // wait here till 20ms_flag == 1
     20ms_flag = 0;
  }
}


Your do_other_code can take ANY length of time from a few us to just short of 20ms before you run into problems. As you edit your code it will execute once every 20ms without any further effort from you.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group