Go to Post Time flies when you're freaking out. - Koko Ed [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 08-02-2008, 15:54
Nathan's Avatar
Nathan Nathan is offline
Registered User
FRC #1501 (Team T.H.R.U.S.T.)
Team Role: Alumni
 
Join Date: Sep 2006
Rookie Year: 2007
Location: United States
Posts: 149
Nathan has a spectacular aura aboutNathan has a spectacular aura aboutNathan has a spectacular aura about
printf() inside interrupt routine?

Is it ok to use printf twice inside my interrupt routine? It seems when I put the print statements in the interrupt routine stops getting called.

Thanks,
Nathan
__________________
Save money with PriceWombat, a shopping comparison and price tracking tool (that I made!).

Check out my hobby electronics business!

My former robotics team: Huntington County 4-H Robotics
  #2   Spotlight this post!  
Unread 08-02-2008, 16:46
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 861
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
Re: printf() inside interrupt routine?

This isn't a good idea as printf is very slow taking up mS when interrupt code should be in uS. You would be better off to have the ISR flag a variable that calls a printf in your main loop.
__________________
FIRST Team 501 PowerKnights - Mentor
FIRST Team 40 Checkmate - Mentor Alum
FIRST Team 146 Blue Lightning - Alumni
  #3   Spotlight this post!  
Unread 08-02-2008, 17:01
Nathan's Avatar
Nathan Nathan is offline
Registered User
FRC #1501 (Team T.H.R.U.S.T.)
Team Role: Alumni
 
Join Date: Sep 2006
Rookie Year: 2007
Location: United States
Posts: 149
Nathan has a spectacular aura aboutNathan has a spectacular aura aboutNathan has a spectacular aura about
Re: printf() inside interrupt routine?

The problem with that is the device interrupts at a very high speed. I think many, many, interrupts will happen before the 26ms loop runs.

But, what you suggested is actually what I'm doing right now.

Nathan
__________________
Save money with PriceWombat, a shopping comparison and price tracking tool (that I made!).

Check out my hobby electronics business!

My former robotics team: Huntington County 4-H Robotics
  #4   Spotlight this post!  
Unread 08-02-2008, 20:08
usbcd36's Avatar
usbcd36 usbcd36 is offline
Registered User
AKA: "DOS"
FRC #2399 (The Fighting Unicorns)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Solon, OH
Posts: 151
usbcd36 is a jewel in the roughusbcd36 is a jewel in the roughusbcd36 is a jewel in the rough
Re: printf() inside interrupt routine?

Why don't you total the interrupts the device generates (like Kevin's encoder code does) then use a printf in the slow loop?
  #5   Spotlight this post!  
Unread 08-02-2008, 20:37
Nathan's Avatar
Nathan Nathan is offline
Registered User
FRC #1501 (Team T.H.R.U.S.T.)
Team Role: Alumni
 
Join Date: Sep 2006
Rookie Year: 2007
Location: United States
Posts: 149
Nathan has a spectacular aura aboutNathan has a spectacular aura aboutNathan has a spectacular aura about
Re: printf() inside interrupt routine?

Well, the "device" I mentioned is actually a camera.. So the interrupts are bytes of tracking information.

Nathan
__________________
Save money with PriceWombat, a shopping comparison and price tracking tool (that I made!).

Check out my hobby electronics business!

My former robotics team: Huntington County 4-H Robotics
  #6   Spotlight this post!  
Unread 08-02-2008, 21:40
usbcd36's Avatar
usbcd36 usbcd36 is offline
Registered User
AKA: "DOS"
FRC #2399 (The Fighting Unicorns)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Solon, OH
Posts: 151
usbcd36 is a jewel in the roughusbcd36 is a jewel in the roughusbcd36 is a jewel in the rough
Re: printf() inside interrupt routine?

Why exactly do you need to print this data for every interrupt?

Why don't you store the data in variables and print it every slow loop? This wouldn't be as accurate, but 26.2 ms does give you a pretty good update rate.
  #7   Spotlight this post!  
Unread 08-02-2008, 23:56
Nathan's Avatar
Nathan Nathan is offline
Registered User
FRC #1501 (Team T.H.R.U.S.T.)
Team Role: Alumni
 
Join Date: Sep 2006
Rookie Year: 2007
Location: United States
Posts: 149
Nathan has a spectacular aura aboutNathan has a spectacular aura aboutNathan has a spectacular aura about
Re: printf() inside interrupt routine?

usbcd36 - I was debugging my driver and wanted to be able to see every byte printed out in the order it arrived. Eventually I discovered this was not possible to do because of how blazingly fast the camera sends tracking data.

So I am essentially doing what you suggest, storing the values and printing out a select few in the slow loop.

Before today I was completely unaware of how processor intensive a printf statement is. I have a blinking LED that's supposed to blink every 250 loops in the fast loop (which is around 250ms) and it works. But when I have even ONE printf statement in the fast loop it slows down to around one blink per second. So ONE printf statement slowed the program down by about a factor of 4! The IFI people weren't kidding when they insctructed in the manual to use only short printf statements for debugging!

Thanks,
Nathan
__________________
Save money with PriceWombat, a shopping comparison and price tracking tool (that I made!).

Check out my hobby electronics business!

My former robotics team: Huntington County 4-H Robotics
  #8   Spotlight this post!  
Unread 09-02-2008, 00:11
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,171
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: printf() inside interrupt routine?

If you reeeeealy need to do this, there any open source programs (google rs-232 monitor) that use the multiple serial ports on a PC to monitor a link. Most of them will log all the data coming and going to a text file.

HTH
  #9   Spotlight this post!  
Unread 09-02-2008, 11:39
Nathan's Avatar
Nathan Nathan is offline
Registered User
FRC #1501 (Team T.H.R.U.S.T.)
Team Role: Alumni
 
Join Date: Sep 2006
Rookie Year: 2007
Location: United States
Posts: 149
Nathan has a spectacular aura aboutNathan has a spectacular aura aboutNathan has a spectacular aura about
Re: printf() inside interrupt routine?

Cool, thanks. I may look into that..
__________________
Save money with PriceWombat, a shopping comparison and price tracking tool (that I made!).

Check out my hobby electronics business!

My former robotics team: Huntington County 4-H Robotics
  #10   Spotlight this post!  
Unread 09-02-2008, 12:54
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: printf() inside interrupt routine?

Quote:
Originally Posted by Nathan View Post
...I was debugging my driver and wanted to be able to see every byte printed out in the order it arrived.
Why not send the data right back out the other serial port?

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #11   Spotlight this post!  
Unread 09-02-2008, 13:32
Nathan's Avatar
Nathan Nathan is offline
Registered User
FRC #1501 (Team T.H.R.U.S.T.)
Team Role: Alumni
 
Join Date: Sep 2006
Rookie Year: 2007
Location: United States
Posts: 149
Nathan has a spectacular aura aboutNathan has a spectacular aura aboutNathan has a spectacular aura about
Re: printf() inside interrupt routine?

Quote:
Originally Posted by Kevin Watson View Post
Why not send the data right back out the other serial port?

-Kevin
I thought that's what printf did?
__________________
Save money with PriceWombat, a shopping comparison and price tracking tool (that I made!).

Check out my hobby electronics business!

My former robotics team: Huntington County 4-H Robotics
  #12   Spotlight this post!  
Unread 09-02-2008, 17:29
Adam Shapiro's Avatar
Adam Shapiro Adam Shapiro is offline
Registered User
FRC #0555 (Montclair Robotics)
Team Role: Alumni
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Montclair, NJ
Posts: 401
Adam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud of
Send a message via AIM to Adam Shapiro
Re: printf() inside interrupt routine?

Quote:
Originally Posted by Nathan View Post
I thought that's what printf did?
Printf converts the data you pass to it into a human-readable string format. For instance, the value 100 would be converted into the following three characters: '1' '0' '0'. What Kevin is suggesting is for you to simply send the byte values themselves out of the serial port. This can be done very quickly and won't impact the ISR very much. You can then read those values into the computer and view them at your leisure, or record them and process them with an additional application (which may be quite useful for what it seems you're trying to do).
__________________
Mentor to Teams 555, 1929, and 2070!
Currently working in hardware design at Cisco.
Cornell University DARPA Urban Challenge - http://www.cornellracing.com
Co-Captain Team 555 - 2003,2004,2005
Trust, Love, and Magic
  #13   Spotlight this post!  
Unread 09-02-2008, 20:03
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: printf() inside interrupt routine?

Quote:
Originally Posted by Nathan View Post
I thought that's what printf did?
As Adam pointed out, and assuming you're using my serial port driver, it's as simple as this:

Code:
 // first, find out how much data, if any, is present in 
 // serial port 1's received data queue?
 byte_count = Serial_Port_One_Byte_Count();
 
 // have we received any data?
 if(byte_count > 0)
 {
  // we have fresh data, so read each received byte one at a time
  for(j = 0; j < byte_count; j++)
  {
   // get the next data byte
   data = Read_Serial_Port_One();
 
   // send it out the other serial port
   Write_Serial_Port_Two(data);
 
  // work with camera data here
  }
}
-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #14   Spotlight this post!  
Unread 10-02-2008, 13:24
mentorbob mentorbob is offline
Registered User
FRC #1307
 
Join Date: Feb 2008
Location: Dover, NH
Posts: 1
mentorbob is an unknown quantity at this point
Re: printf() inside interrupt routine?

Nathan,
It wouldn't be a good idea to call a library routine like printf from inside an interrupt, even if the interrupt only happened every second. Most library routines are not re-entrant. If you were in the middle of a printf when the interrupt occurred, calling printf from inside the interrupt would mess up the printf in progress.

Bob
  #15   Spotlight this post!  
Unread 10-02-2008, 16:44
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: printf() inside interrupt routine?

Quote:
Originally Posted by mentorbob View Post
Nathan,
... Most library routines are not re-entrant. ...
Bob
hmmm, I checked the MCC 18 library and found a couple routines that are non-reentrant as they appear that they might use some globals (e.g. strtokpgmram), but the majority of the library, including print/put/etc., appears to be re-entrant friendly by using only auto variables. The compiler will use .tmpdata and other managed resources, per usual, but interrupt routines should be saving the appropriate ones as needed already.

Do you know for certain that the library is non-reentrant? That would be good info to know as there are many library calls used that are not directly called by the user, like FXM3232 which is used for long x long multiplication.

Its still not a good idea to call printf() from within an interrupt routine due to the time delays associated with outputing the formated data, but not being re-entrant doesn't appear to be a reason in this case. I easily could be wrong, but looking at printf, vprintf, etc down the call train didn't reveal any obvious globals being referenced that would make the routine non-reentrant.
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
Routine declaration syntax error (Or: Where's wlado?) Astronouth7303 Programming 15 24-03-2004 05:51
printf isn't printf-ing. Help! Meandmyself Programming 14 15-02-2004 16:27
Pre-Match/Post- Match Pit Routine Mark_lyons General Forum 14 31-03-2002 15:19
Master uP Initialization Routine Ulibrium Technical Discussion 5 24-01-2002 16:43


All times are GMT -5. The time now is 01:08.

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