View Single Post
  #4   Spotlight this post!  
Unread 14-01-2008, 18:28
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 589
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Programming the Infrared board

Quote:
Originally Posted by Abrakadabra View Post
Hi Brad -

Thanks for doing this. This is also a good example of showing that you can use the IFI headers in a WPILib program, something that's not so apparent on first glance.

Some questions:

- I think I understand what RegisterRepeatingTimer() does, although it is not really documented. The header file says that timer interrupt handlers are "called with interrupts disabled". However, do you not also need to disable interrupts when you access the shared globals in the main( ) routine?
You're right... not documented, I'll try to fix that. It is called as an interrupt service routine so you want the code to be fast. As far as the shared globals in the main routine... good question. I don't think it's a problem because the interrupt service routine never turns them off and there is only a single value. If you wanted to count the number of times the IR code was received in the ISR and decrement the count in the main program, then it would have to be protected. As it is, I don't think you lose anything, but I could be wrong.

Quote:
Originally Posted by Abrakadabra View Post
- The variables "changed" and "previous" in your ISR don't seem to do anything? Again, I think I understand what you are trying to do (e.g. collect all the commands in between times that the program actually checks for them), but "previous" never gets set to anything other than zero, and "changed" is calculated, but then not used. Would it not be simpler to just say:
Code:
 irCommands |= current;
and then the main() routine can turn off each bit as it gets processed? I think that's what the code is essentially doing now, since "previous" is always zero.
You are so right about the previous variable not being set... I must have been sleeping. And I showed it to a few people and nobody else noticed. What I was trying to do was only set the bit on a change from off to on so. I didn't want two polls to look like two events. If you just OR the new value into the result, then if in one ISR call the bit is set, then before the next 30ms period, the main program clears the bit, then the next timer interrupt notices that the bit is still set, it would like to two button presses.

Thanks for noticing the problem!

Brad
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote