Go to Post You know this crazy ChiefDelphi... nothing but useless information and kids ranting about pizza. - Amanda Morrison [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 02-02-2004, 19:50
SeanCassidy's Avatar
SeanCassidy SeanCassidy is offline
Antiregistered User
#0263 (Aftershock)
Team Role: Programmer
 
Join Date: Oct 2003
Location: Holtsville, NY
Posts: 37
SeanCassidy is an unknown quantity at this point
Interrupt timer, executing code asap?

Thanks for Innovation First for that good white paper on timers, without that I'd be lost.

Well I got the interrupt timer working, looks good. So I wrote this function to use the loop code. Here is the code:

Code:
void example(unsigned int seconds, char startEnd)
{
  static char runOnce1 = 0, runOnce2 = 0;
  if(startEnd == 1 && runOnce1 == 0)
  {
    int snapSecondCnt = secondCnt;  //Take a snapshot of the seconds
    runOnce = 1;                    //Make sure it doesn't run again
    //Run any command to start here
  }
  else if(startEnd == 0 && runOnce2 == 0)
  {
    if(secondCnt == (snapSecondCnt + seconds)) 
    {
      snapSecondCnt = 0;
      runOnce2 = 1;
      //Run any other stopping command here
    }
  }
  else
  {
    printf("example() error!\n");
  }
}

void Process_Data_From_Local_IO(void)
{
  /* Add code here that you want to be executed every program loop. */
  if (updateDisplay)
  {
    INTCONbits.GIEL = 0;            /* Disable Low Priority Interrupts */
    updateDisplay = 0;
    INTCONbits.GIEL = 1;            /* Enable Low Priority Interrupts */
    rc_dig_out04 ^= 1;              /* Pin4 toggles every 1s */
    secondCount++;
    example(10,1);    //Start - My edit!
    example(10,0);    //End   - My edit!
    printf("Pin 4 = %d, Elapsed Time (s) = %d\n",(int)rc_dig_out04,secondCount);
  }
}
Now let me explain briefly what this code does if you do not understand, it is vital to my question. The normal loop executes, until example(). It tells example to have a timer for ten seconds, and the second example is to stop the timer. I'm sure I could've done that a little better. So in example() if it's starting and it's its first time running (runOnce#) then it starts a motion, like say going forward (pwm01 = 254; pwm02 = 254; just say those are our motors at full throttle forward). The loop executes until the satisfied time is up (if(secondCnt == (snapSecondCnt + seconds))). Then it stops.

My question: does this approach even work in practice? I know that you have to be zip zip in and out of interrupts, but in the whitepaper it says that the interrupt od is the most effective timer. So does my example() start and end always take less than one second? Have I approached this totally wrong? Any tips?

I wouldn't recommend anyone to take this code for their own, it most likely doesn't work.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting Naviagation code into Default code? actorindp Programming 3 28-01-2004 18:12
Interrupts Questions mightywombat Programming 0 03-01-2004 14:50
EDU Demo Code: Serial Data Transmitter Using a State-Machine Kevin Watson Programming 3 28-12-2003 22:56
EDU Interrupt and Timer Template Code Kevin Watson Programming 8 22-12-2003 14:11
EDU Demo Code: Real-Time Clock Using a Timer Kevin Watson Programming 1 17-12-2003 15:14


All times are GMT -5. The time now is 04:22.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi