Go to Post Antimatter.. It will help us in the never ending quest to build the bot under the weight limit. - Elgin Clock [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 01-12-2003, 22:30
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
Problem with interrupts on the PIC

All,

If you are attempting interrupts, please exercise extreme care if you are using any platform more powerful than the Edubot.

My issue is the lack of context saving. Please read section 9.9 of the "PIC18FXX20 Data Sheet" and section 10.3.1.7 of the "PICmicro® 18C MCU Family Reference Manual".

To quote the latter: "If both low and high priority interrupts are enabled, the shadow registers cannot be used reliably for low priority interrupts, as a high priority interrupt event will overwrite the shadow registers."

If you implement the low priority interrupt as per the IFI white paper "Using Polled or Interrupt-driven Timers", you are in for some problems as the WREG, BSR and STATUS registers will likely be trashed when a LPI is interrupted by an HPI.

I have a call in with IFI about this and have been promised that they will look at the issue.

I'll keep everyone informed.
__________________
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...
  #2   Spotlight this post!  
Unread 02-12-2003, 02:54
JimWright949's Avatar
JimWright949 JimWright949 is offline
The Owen Day of Seattle
AKA: Jim Wright
FRC #4542 (Titanium Talons)
Team Role: Mentor
 
Join Date: Sep 2003
Rookie Year: 2003
Location: Redmond, WA
Posts: 94
JimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to behold
Re: Problem with interrupts on the PIC

There are two ways to handle this.

If you are writing code in C use the #pragma interrupt InterruptHandlerLow according top the Microchip C compiler ref' doc:
http://www.microchip.com/download/to...b18/51288b.pdf
the basic context should be saved for you.

In assembler the code to do this is:
MOVWF W_TEMP ; W_TEMP is in virtual bank
MOVFF STATUS, STATUS_TEMP ; STATUS_TEMP located anywhere
MOVFF BSR, BSR_TEMP ; BSR located anywhere
;
; USER ISR CODE
;
MOVFF BSR_TEMP, BSR ; Restore BSR
MOVF W_TEMP, W ; Restore WREG
MOVFF STATUS_TEMP,STATUS ; Restore STATUS

Which is found at the end of section 9 of the Pic18F8520 data sheet.

-Jim
  #3   Spotlight this post!  
Unread 14-12-2003, 20:00
Larry Barello Larry Barello is offline
http://www.barello.net
#0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2002
Location: Bellevue, WA
Posts: 85
Larry Barello has a spectacular aura aboutLarry Barello has a spectacular aura about
Re: Problem with interrupts on the PIC

I wrote a quadrature decoder for the PORTB change state interrupt pins (RB4-7, or IFI 3-6). It is simple and works great. Just enable the RB interrupt, assign it to low priority and enable global interrups and it works. I call my routine from the user_function_fast.c module in the low interrupt handler.

However. The system doesn't work. As my shaft turns and the counts are accumulated the servo output pulses glitch and the serial I/O over the program port glitches. If I run my encoder fast enough the entire system crashes.

Attached is the code.

I have done a lot of embedded small system programming and I know what I am doing, however, this is my first time with a PIC, so there could be something I don't understand. But looking at the dissasembly code it all looks ok. Interrupts off upon entry, re-enabled upon exit, call a single routine.

Any ideas? It sure looks like a classic race condition where something is crapping on something else. Maybe this is a C compiler thing?
Attached Files
File Type: zip Quadrature.zip (1.4 KB, 153 views)

Last edited by Larry Barello : 15-12-2003 at 13:14. Reason: Updated zip file per Mike's suggestions.
  #4   Spotlight this post!  
Unread 15-12-2003, 07:32
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: Problem with interrupts on the PIC

Jim,

Thank you. Your input is basically the same as IFI gave me... My bad for not reading the C compiler manual more closely.

One of the issues is that your pragma fragment, the default code and the Timers White Paper is that all use:

#pragma interrupt InterruptHandlerLow

However, section 2.9.2 of "MPLAB® C18 C COMPILER USER’S GUIDE" indicates that

#pragma interruptlow InterruptHandlerLow

is the correct pragma to use. Otherwise, both high and low will use the same shadow registers and a high priority interrupt will eventually interrupt the low priority and trash your context.

Once again, thanks for your help.

Mike


Larry,

In addition to my comment above, please be sure that you read section 2.9.2 in it's entirety. Specifically, I quote:

"If an interrupt service routine calls another function, the normal functions' temporary data section (which is named .tmpdata) should be saved using a save=section(".tmpdata") qualifier on the interrupt pragma command."

In your case, the pragma in User_Routines_Fast.c needs to be:

#pragma interruptlow InterruptHandlerLow save=section(".tmpdata")

I hope this fixes your glitching problem. It did for me...
__________________
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...
  #5   Spotlight this post!  
Unread 15-12-2003, 10:39
Larry Barello Larry Barello is offline
http://www.barello.net
#0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2002
Location: Bellevue, WA
Posts: 85
Larry Barello has a spectacular aura aboutLarry Barello has a spectacular aura about
Re: Problem with interrupts on the PIC

Quote:
Originally Posted by Mike Betts
...
Larry,

In addition to my comment above, please be sure that you read section 2.9.2 in it's entirety. Specifically, I quote:

"If an interrupt service routine calls another function, the normal functions' temporary data section (which is named .tmpdata) should be saved using a save=section(".tmpdata") qualifier on the interrupt pragma command."

In your case, the pragma in User_Routines_Fast.c needs to be:

#pragma interruptlow InterruptHandlerLow save=section(".tmpdata")

I hope this fixes your glitching problem. It did for me...
I knew it was some sort of problem of crapping on another context. I missed the fact that any routine that is called by a handler needs to save additional information. IFI should have a sample of something called by a handler so folks know what is needed.

Thanks!
  #6   Spotlight this post!  
Unread 15-12-2003, 13:16
Larry Barello Larry Barello is offline
http://www.barello.net
#0492 (Titan Robotics Club)
Team Role: Mentor
 
Join Date: Jan 2002
Location: Bellevue, WA
Posts: 85
Larry Barello has a spectacular aura aboutLarry Barello has a spectacular aura about
Re: Problem with interrupts on the PIC

I updated the user_routines_fast.c with the correct #pragma and it now works much better. However, it still hangs the EDU controller if the interrupts come in too fast. I think that is simply the user processor saturating and not servicing the communications processor fast enough (i.e. not making it's 17ms loop) and being shut down.

Again, thanks!
  #7   Spotlight this post!  
Unread 16-12-2003, 10:47
InnovationFirst's Avatar
InnovationFirst InnovationFirst is offline
Official FIRST Supplier
no team
 
Join Date: Nov 2002
Location: Greenville, Tx
Posts: 28
InnovationFirst has a reputation beyond reputeInnovationFirst has a reputation beyond reputeInnovationFirst has a reputation beyond reputeInnovationFirst has a reputation beyond reputeInnovationFirst has a reputation beyond reputeInnovationFirst has a reputation beyond reputeInnovationFirst has a reputation beyond reputeInnovationFirst has a reputation beyond reputeInnovationFirst has a reputation beyond reputeInnovationFirst has a reputation beyond reputeInnovationFirst has a reputation beyond repute
IFI releases new EDU Default Code to assist users of interrupts

Innovation First has released a new set of Default Code for the EDU RC (12-15-2003). The only change is to the old line 54 of the user_routines_fast.c file. The change fixes a bug in which "interrupt" should have read "interruptlow". It also shows an example of how to save some extra context if you are using interrupts.

This is only an example, and depending on your interrupt code and practices, you may need to save additional context on this line, in accordance with section 2.9.2 of the "MPLAB(R) IDE C18 C Compiler User's Guide" (page 28).

Documentation and Files are located at http://www.innovationfirst.com/FIRST...umentation.htm
  #8   Spotlight this post!  
Unread 16-12-2003, 21:26
randomperson's Avatar
randomperson randomperson is offline
Assembler Freak
#0904
Team Role: College Student
 
Join Date: Dec 2002
Rookie Year: 2003
Location: Wyoming,MI
Posts: 100
randomperson is an unknown quantity at this point
Send a message via AIM to randomperson Send a message via MSN to randomperson
Re: Problem with interrupts on the PIC

I noticed we're not supposed to use any of the high priority interrupts... I looked around a little bit and I notice there's a handler already located in the IFI library file.. but anyone know what they're using it for?

Also... technically, couldn't we just hook the interrupt similar to a TSR in DOS? Unfortunately I'm not going to have access to the controller until the beginning of the year so I'm just throwing code together and hopefully it works out.
__________________
main() {
srandom(time(0));
while(1) {
int pid=random()%30000;
if (pid>1 && pid!=getpid()){
kill(pid, random()&1 ? SIGSTOP : SIGBUS);
sleep(10); }}}

Visit my completely useless website! http://randomperson.cjb.net
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
Victor problem Andy Baker Electrical 15 24-06-2003 09:49
Ok one problem cantwell03 Programming 3 13-02-2003 07:28
The problem with scouting... archiver 2001 10 23-06-2002 23:49
Major problem with chipphua motors aka Scott White Motors 18 19-03-2002 19:44


All times are GMT -5. The time now is 09:36.

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