Go to Post Act humble, avoid hubris, and post widely and thou shalt receivith postive rep. ;) - artdutra04 [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 23-12-2003, 23:00
Anthony Kesich's Avatar
Anthony Kesich Anthony Kesich is offline
Programmer Turned Engineer
AKA: SonKenshin
#1097 (Site 3 Engineernig)
Team Role: Leadership
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Sacramento, CA
Posts: 186
Anthony Kesich has a spectacular aura aboutAnthony Kesich has a spectacular aura about
Send a message via AIM to Anthony Kesich
Time to feel stupid....

OK, seeing as I am fairly new to C, i have one question which i know will make me feel stupid: what are interupts? Are they as self-explanitory as pointers (i.e. pointers point so interupts interupt)? Also, what would be a pactical use for an interupt and are they quirky and strange like pointers where they seem simple enough but are the bane of every programmer's existance?

-Kesich
__________________
C is screwing up my English--I'm ending all my sentences in semi-colons;

Horray for most things! -George Carlin

"Sure, I'll play rugby. Besides, I have a lot of experience running from really big guys who want to cream me." -Me, Freshman year
  #2   Spotlight this post!  
Unread 23-12-2003, 23:42
FotoPlasma FotoPlasma is offline
\: |
no team
 
Join Date: Jul 2001
Rookie Year: 2001
Location: San Jose
Posts: 1,900
FotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond repute
Send a message via AIM to FotoPlasma
Re: Time to feel stupid....

http://www.chiefdelphi.com/forums/sh...ad.php?t=22885
http://www.chiefdelphi.com/forums/sh...ad.php?t=22837
http://www.chiefdelphi.com/forums/sh...ad.php?t=22662
http://www.chiefdelphi.com/forums/sh...ad.php?t=21633

Err. Maybe not so much the first link, but the other three should help.
  #3   Spotlight this post!  
Unread 24-12-2003, 00:19
IrisLab's Avatar
IrisLab IrisLab is offline
Mentor
AKA: Dave Page
#1466 (Webb School)
Team Role: Mentor
 
Join Date: Dec 2003
Location: Knoxville, Tennessee
Posts: 33
IrisLab will become famous soon enough
Re: Time to feel stupid....

Quote:
Originally Posted by Anthony Kesich
OK, seeing as I am fairly new to C, i have one question which i know will make me feel stupid: what are interupts?
-Kesich
Interrupts are not unique to C. I'll do my best to put my 2 cent explanation. Interrupts are really a capability of microprocessor and not a language construct. They are not like pointers or other "C" things.

The PICs in the new RCs allow interrupts, which is to say that the new processors support interrupts.

So, what is an interrupt?

A typical microprocessor crunkes and chugs away on a piece of code in a sequential manner. Step 1, 2, 3,...,N on and on dilengently following the sequence of N steps that a programmer has laid out.

This straightforward execution model works fine in a very simple environment. However, let's say you are running a program on a computer with a mouse. An N-step program is running and suddenly the user clicks the mouse at Step 3 of the sequence. The user has to wait until the end of the Nth step before his mouse click is processed by the computer if the processor doesn't have interrupts.

Now, fortunately, most modern computers use interrupt processors. So, the mouse click intiates and interrupt. The processor stops at Step 3 temporarily stores is "state" in a temporary array. The processor jumps to a section of code to handle the "mouse interrupt". When its done, the processor reloads state and continues with Step 3 of ther original program.

So, interrupts are exactly that. When you program an interrupt, the processor halts it's current execution whenever the interrupt becomes true. Usually an interrupt is a high or low bit on a particular pin of the processor.

Now, where might you wanna use interrupts with FIRST robotics? One idea might be if you have a "bummer switch" that tells you when your robot hits a wall. You could tie this switch to one of the interrupts. When you bump into something, the processor could then run a special "I've bummped into the wall" piece of code.

That seems like a lot of trouble, right? Why not just check the switch at the top of the normal 17ms control loop? Well, in the case of the "bummer switch" an interrupt may not be necessary, but it illustrates the idea.

Interrupts are very important to real-time programming when waiting 17 ms to respond to an event may be an eternity. This capability is especially true for autonomous mode operations.

I hope this explanation is helpful. Maybe some computer science folks can correct/elaborate furhter.
__________________
David Page
  #4   Spotlight this post!  
Unread 24-12-2003, 00:26
Anthony Kesich's Avatar
Anthony Kesich Anthony Kesich is offline
Programmer Turned Engineer
AKA: SonKenshin
#1097 (Site 3 Engineernig)
Team Role: Leadership
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Sacramento, CA
Posts: 186
Anthony Kesich has a spectacular aura aboutAnthony Kesich has a spectacular aura about
Send a message via AIM to Anthony Kesich
Thumbs up Re: Time to feel stupid....

Thanks IrisLab. Thats exactly what i thought it was, but i wanted to confirm. Seeing as 17ms is just faster than 1/59th of a second, it seems to me that interupts are overkill and you could make much better use of your programming space (800 lines), but i'll still keep them in mind if they ever become a necessity.
__________________
C is screwing up my English--I'm ending all my sentences in semi-colons;

Horray for most things! -George Carlin

"Sure, I'll play rugby. Besides, I have a lot of experience running from really big guys who want to cream me." -Me, Freshman year
  #5   Spotlight this post!  
Unread 24-12-2003, 16:33
IrisLab's Avatar
IrisLab IrisLab is offline
Mentor
AKA: Dave Page
#1466 (Webb School)
Team Role: Mentor
 
Join Date: Dec 2003
Location: Knoxville, Tennessee
Posts: 33
IrisLab will become famous soon enough
Re: Time to feel stupid....

Quote:
Originally Posted by Anthony Kesich
Thanks IrisLab. Thats exactly what i thought it was, but i wanted to confirm. Seeing as 17ms is just faster than 1/59th of a second, it seems to me that interupts are overkill and you could make much better use of your programming space (800 lines), but i'll still keep them in mind if they ever become a necessity.
Actually, that 17ms contol loop is just off the top of my head. I can't remember the time, but I believe that's close. However, that number is only approximate. The control loop is not guaranteed to be every 17ms. If your code becomes too long, you'll stretch beyond that 17ms cycle easily. The 17ms is NOT guaranteed.

With interrupts, you are pretty guaranteed to get things done with greater time precision.

A common thing to do is to set an interrupt timer. Like a high-precision time clock. You could, for example, set the timer to go off at every 6 ms. The interrupt will occur at that regular interval, regardless of the length of your code. You are guaranteed to have the interrupt to run every 6ms.

The key with interrupts is GUARANTEE and precision TIMING. I wouldn't casually write these capabilities off. Especially for a good autonomous mode.
__________________
David Page
  #6   Spotlight this post!  
Unread 28-12-2003, 22:06
Random Dude Random Dude is offline
Oregon State Head FTA
AKA: Chris
no team (Oregon Robotics Tournament & Outreach Program)
 
Join Date: Aug 2002
Rookie Year: 1998
Location: Oregon
Posts: 142
Random Dude will become famous soon enoughRandom Dude will become famous soon enough
Re: Time to feel stupid....

Quote:
Originally Posted by IrisLab
Actually, that 17ms contol loop is just off the top of my head. I can't remember the time, but I believe that's close. However, that number is only approximate. The control loop is not guaranteed to be every 17ms. If your code becomes too long, you'll stretch beyond that 17ms cycle easily. The 17ms is NOT guaranteed.

The 17ms figure is correct for the EDU bot (it's ~26ms for the full size)

However your code should NOT take that long to execute. If it does you will start having problem with missing communication packets from the OI. If you take too long (not sure of the exact time) the master microprocessor will shut down the robot (since it figures that the user code is stuck in an infinite loop).

That being said, assuming you keep your user code relatively compact. The user code (specifically the function Process_Data_From_Master_uP() ) should execute fairly close to every 17ms. From what I can determine, the timing is controlled by the reciept of data from the master micro.


Quote:
Originally Posted by Anthony Kesich
Thanks IrisLab. Thats exactly what i thought it was, but i wanted to confirm. Seeing as 17ms is just faster than 1/59th of a second, it seems to me that interupts are overkill and you could make much better use of your programming space (800 lines), but i'll still keep them in mind if they ever become a necessity.

I'm not quite sure where you are getting that 800 lines from, would you care to elaborate on it?

Also, while 17ms is approaching the upper limit of human reaction times, it can be, (though not always) an eternity in a computer. For instance in 2002 I was trying to design a system to keep track of what zone the robot was in at all times. (If you're not familiar in 2002 the playing field was divide into 5 sections by 1" strips of tape). However, one of the problems that cropped up was that if the robot was moving at any sort of reasonable speed, the sensor would not detect the crossing of the line becuase it would only be high for a really brief period (5-6ms I think).

So unless the program just happened to be checking the sensor during that brief period, it would never know that there had been a line. Now, If there had been interrupts on that controller, I could have used those to immediately (well within a microsecond or so) known that I had crossed the line.

And while you could design some external hardware involving a latch, to detect the pulse, it would add complexity and additional things to fail.
  #7   Spotlight this post!  
Unread 07-01-2004, 18:45
galewind's Avatar
galewind galewind is offline
... more like a temperate breeze
AKA: Chris Gregory
FRC #1089 (Team Mercury)
Team Role: Teacher
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Hightstown, NJ
Posts: 410
galewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond repute
Send a message via AIM to galewind
Re: Time to feel stupid....

Am I correct in saying that the drastic increase of MIPS (from 0.01 to 10.0) will mean that the length of your code should no longer impact the execution time -- so that you will always be able to execute a loop once every 17 (or ~26) ms?

edit: not referring to the local IO loop, just the uP loop.
__________________
Chris G
Advisor, Team Mercury (1089), Hightstown High School
  #8   Spotlight this post!  
Unread 08-01-2004, 08:25
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: Time to feel stupid....

Quote:
Originally Posted by galewind
Am I correct in saying that the drastic increase of MIPS (from 0.01 to 10.0) will mean that the length of your code should no longer impact the execution time -- so that you will always be able to execute a loop once every 17 (or ~26) ms?
In general, the code (and code requirements such as I/O) will grow to fill all available space/time. There have already been posts in these fori where users have run out of space (one gentleman could not load his program into ROM and asked what could be deleted) and time (another was using interrupts at a very high repetition rate to decode shaft position).

The task of the design engineer is to choose and implement a design that is within the capabilities of system constraints. The PIC 18C considerably increases (loosens) the system constraints we must stay within but not infinitely.

Now I will borrow Car Knack's Cloak of Prediction from Mr. Beatty:

"Before 3/1/2004, more than one engineer or EIT will complain that the new controller is not powerful enough."
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...

Last edited by Mike Betts : 08-01-2004 at 12:14.
  #9   Spotlight this post!  
Unread 08-01-2004, 11:44
galewind's Avatar
galewind galewind is offline
... more like a temperate breeze
AKA: Chris Gregory
FRC #1089 (Team Mercury)
Team Role: Teacher
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Hightstown, NJ
Posts: 410
galewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond repute
Send a message via AIM to galewind
Re: Time to feel stupid....

I suppose that what I'm getting at is --

Is it true that adding one block of code (obviously not an infinite loop, but, say, another case to a switch) to an already "reasonably" sized Default_Routine will not force you to change the timings of your loop counters as drastically as before?
__________________
Chris G
Advisor, Team Mercury (1089), Hightstown High School
  #10   Spotlight this post!  
Unread 08-01-2004, 12:14
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: Time to feel stupid....

Quote:
Originally Posted by galewind
I suppose that what I'm getting at is --

Is it true that adding one block of code (obviously not an infinite loop, but, say, another case to a switch) to an already "reasonably" sized Default_Routine will not force you to change the timings of your loop counters as drastically as before?
Quite correct. You can now have many pages of code which will execute with no obvious effect of the system, if it is done carefully.

The easiest trap to fall into is to use floating point arithmetic or calls to the math.h libraries. Since the PIC is a integer machine, a floating point operation can cause literally thousands of machine operations to be performed. These operations take time and time can add up.

Even some integer operations can take longer than you think. Since the PIC has no firmware for division, dividing 30,000 by 3 (without optimization) involves 10,000 machine cycles (subtract 3 from 30,000 10,000 times).

Don't get me wrong, the PIC is a very powerful microcontroller. But just as a power drill is a powerful tool, it is not great at driving a 10 penny nail.

To borrow from another thread: Choose the path you follow wisely.
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...

Last edited by Mike Betts : 08-01-2004 at 12:16.
  #11   Spotlight this post!  
Unread 08-01-2004, 15:10
galewind's Avatar
galewind galewind is offline
... more like a temperate breeze
AKA: Chris Gregory
FRC #1089 (Team Mercury)
Team Role: Teacher
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Hightstown, NJ
Posts: 410
galewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond reputegalewind has a reputation beyond repute
Send a message via AIM to galewind
Re: Time to feel stupid....

Thanks, that's the type of answer I was hoping for.

When we did our autonomous programming before, if we had added a few more lines of code to a specific step or routine, we had to subtract from the number of times the main do loop was executed to compensate for the additional amount of time spent. It was quite tedious changing values so frequently, which cost us precious rounds (we didn't start programming autonomously until after we shipped and had no 2nd controller to accurately test on).

From what I'm understanding, this won't be as big of a problem this year, and code can be more accurately written around theoretical timings vs "time-trial" timings.

Thanks for your help!
__________________
Chris G
Advisor, Team Mercury (1089), Hightstown High School
Closed Thread


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
ill probably feel stupid but i do anyway so... Anthony Kesich Programming 8 05-11-2003 12:53
Solution to Timing Loops Steven Carmain Programming 39 10-02-2003 13:33
How long should production time be??? archiver 1999 4 23-06-2002 23:16
And here's Fishy for stupid question time.. A. Leese Chairman's Award 1 23-10-2001 22:38
need help with time zone! Ken Leung General Forum 6 25-06-2001 12:44


All times are GMT -5. The time now is 19:54.

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