For loop time

for loop time for PIC

Page 1 of 1

4 Replies - 703 Views - Last Post: 11 May 2010 - 12:30 PM Rate Topic: -----

#1 TheBlackMac  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-May 10

For loop time

Posted 11 May 2010 - 12:13 PM

hey

i wondering how much time it'll take to complete one for loop for with hex number like

{
int i;
for(i=0x1;i--;);

}

I'm using a PIC16F877 with a clock of 20 MHz

simply I need a delay of 4.147 ms

This post has been edited by JackOfAllTrades: 11 May 2010 - 12:38 PM
Reason for edit:: Disabled emoticons

Is This A Good Question/Topic? 0
  • +

Replies To: For loop time

#2 VentiLator  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 40
  • Joined: 07-March 09

Re: For loop time

Posted 11 May 2010 - 12:17 PM

you want your programm to do nothing for 4.147ms?

you can do that by using sleep() from unistd.h.

sleep(1) will make your programm sleep for one second.

or am i totally missing your goal?

This post has been edited by VentiLator: 11 May 2010 - 12:18 PM

Was This Post Helpful? 0
  • +
  • -

#3 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: For loop time

Posted 11 May 2010 - 12:21 PM

{
for(int i=0x1;i--;)/>;
}



First off, you are running an empty control statement because of the ';' after the for, so really it won't take any time, and second, since 0x1h == 1d, than it would only take one iteration to get to zero...


@ventiLator , if this is on windows, their sleep function is in milliseconds, so you would want Sleep(4174);


EDIT:: It won't loop until neg numbers, it will stop at zero, but I imagine it wouldn't take long, depending on the actual instructions you have in your for loop

This post has been edited by IngeniousHax: 11 May 2010 - 12:29 PM

Was This Post Helpful? 0
  • +
  • -

#4 VentiLator  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 40
  • Joined: 07-March 09

Re: For loop time

Posted 11 May 2010 - 12:26 PM

afaik you'll need windows.h for Sleep().
Was This Post Helpful? 0
  • +
  • -

#5 TheBlackMac  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-May 10

Re: For loop time

Posted 11 May 2010 - 12:30 PM

I want to control the sampling time for my controller.

the original sampling time is 19.6*10^-6 sec and my input signal is normal 60 Hz, and i'm taking 4 samples per period.

so by putting a delay before the sampling command ADGO (which is kind of unfamiliar to me, since i'm following an example for that matter.)

if you have other way of sampling techniques that would make my life much easier, i'd be thankful.

thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1