Go to Post Anyone riding a Segway looks cool...ask Andy Baker - Kyle Love [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 14-02-2004, 15:44
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Interrupt Handlers and Variable Scope

I'm trying to implement a shaft encoder which simply triggers an interrupt handler and increments a variable every time the encoder creates a pulse.

The code mostly works, in that the interrupt handler is called when the pulse on Digital Input 1 occurs, it then checks the value of digital input 10 for the B phase, and increments and decrements a counter as appropriate.

The interrupt handler is getting called, since I can put debugging printf()'s in there which show +'s and -'s every time the handler is called.

The problem is that the global variable I'm using isn't ever incremented or decremented, like a scope problem.

I've read the C18 manual about interrupt handlers, and thought I had everything taken care of:

I've already got a
#pragma interruptlow interrupt_handler_low save=section(".tmpdata)

And I've tried
#pragma interruptlow interrupt_handler_low save=variablename

but neither of these help. Ideas?

(I'd post the exact code, but it's over with the bot without an internet connection. Perhaps later this evening).
  #2   Spotlight this post!  
Unread 14-02-2004, 16:52
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: Interrupt Handlers and Variable Scope

Quote:
Originally Posted by kaszeta
The problem is that the global variable I'm using isn't ever incremented or decremented, like a scope problem.
Put the keyword "volatile" in front of your global variable declaration. I put a description of what this does in this thread.
  #3   Spotlight this post!  
Unread 14-02-2004, 18:30
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: Interrupt Handlers and Variable Scope

Quote:
Originally Posted by kaszeta
I'm trying to implement a shaft encoder which simply triggers an interrupt handler and increments a variable every time the encoder creates a pulse.

The code mostly works, in that the interrupt handler is called when the pulse on Digital Input 1 occurs, it then checks the value of digital input 10 for the B phase, and increments and decrements a counter as appropriate.

The interrupt handler is getting called, since I can put debugging printf()'s in there which show +'s and -'s every time the handler is called.

The problem is that the global variable I'm using isn't ever incremented or decremented, like a scope problem.

I've read the C18 manual about interrupt handlers, and thought I had everything taken care of:

I've already got a
#pragma interruptlow interrupt_handler_low save=section(".tmpdata)

And I've tried
#pragma interruptlow interrupt_handler_low save=variablename

but neither of these help. Ideas?

(I'd post the exact code, but it's over with the bot without an internet connection. Perhaps later this evening).
There is example code here that does exactly what you want. You'll just need to drop encoder.c/.h into your build and modify your user_routines_fast.c file so that the proper interrupt handlers are called.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
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


All times are GMT -5. The time now is 00:03.

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