Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how calculate the instruction time

Status
Not open for further replies.

girgis adly

New Member
dear all
i write a code for programming pic using micro C

void main()
{
TRISB=0;
LOOP:
PORTB=0;
Delay_us(447);
PORTB=0B00100110;
Delay_us(2717);
PORTB=0B00100101;
delay_us(3889);
PORTB=0B00100110;
delay_us(2667);
PORTB=0;
delay_us(777);
PORTB=0B00011010;
delay_us(2667);
PORTB=0B00011001;
delay_us(3889);
PORTB=0B00011010;
delay_us(2667);
PORTB=0;
delay_us(388);
goto loop;
}

i want the instruction to run (exceed) after 447 micro second but when i run the programe in protus programe the instruction run after 464 micro second i know it is a little difference but i want to know why this shift in time occur and how i can calculate it and the time the processor take to exceed the instruction i use 8 MHZ crystal (oscillator) and pic18f452
thanks for all
 
What Instruction

Dear Girgis,

I am a little confused - what instruction do you want to run at 447 µS ? What exactly are you trying to achieve?

Rupert
 
The delays do not include the instructions outside them or the extra code the compiler inserts (they will consume time too)
You have to shorten your delays accordingly.
 
thanks for replying

Dear Girgis,

I am a little confused - what instruction do you want to run at 447 µS ? What exactly are you trying to achieve?

Rupert
i write a programe for multilevel inverter i use many no of mosfets which i control it so i need to operate at a certain time i know the delay is very little but i just want to learn
 
Code Timing

Dear Girgis

Have a look at the data-sheet for the PIC you are using. It will state something like:-

'All single-cycle instructions (200 ns), except for program branches which are two-cycle'

One cycle is equivalent to FOSC/4, therefore you can calculate the time used for the processor to execute your code and then make up the difference with a suitable delay.

If you are using MPLAB try using the stopwatch feature by stepping through code and setting breakpoints, this will show you how long the code is taking to execute.

Hope this is of some help! :D
 
he is writing in C i think lol so do this guy:

Set a break point before the delay and then set another right at the first instruction of the delay. then use the stop watch to see how many cycles it takes to do the call and minus that from the delay itself then do the same for leaving the delay call. set one at the end then one where it returns. and see how long that takes. and minus that and you will have a perfect delay.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top