|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
*unofficial* FIRST IR module driver released
UNOFFICIAL CONTENT. This code was not written by IFI or FIRST.
Well, thanks to the Holly Area School system, I got bored and wrote some alpha (for now) code that should let anyone with MPLAB interface to the new FIRST IR receiver module. I don't even know if the thing works right now, since I have not been to the shop and don't have a board yet. But, I'm pretty sure this can help teams interested in doing the same who have their board. Figuring out how to hook it up is up to you for now. The white wire goes to the CMD wire for that input, and black goes to ground. Power it off a PWM output with the backup battery, unless you really know what you are doing and can stabilize the voltage from the main battery--just be sure to keep the backup battery charged, or you will see strange behavior. Let me know if you have any suggestions/concerns/problems/questions and I'll try to address them. Here's the goods: http://www.trucktownthunder.com/firstir_mplab_v0_2.zip It'll be listed on our index as soon as I lose the laziness from today being a snow day. Cheers, JBot Last edited by JBotAlan : 17-12-2007 at 15:53. Reason: Link updated for latest version |
|
#2
|
|||||
|
|||||
|
Re: FIRST IR module driver released
Jacob,
I saw in your code that you're restricting the inputs to IOs 1-6 because they have selectable pullup resistors. This isn't necessary. The outputs of the IR board can sink 8.5mA when driven low, which is easily enough to counteract any pullup resistor. Admittedly, this would be a problem if the IR outputs went to High-Z when there wasn't a signal, but i think it's safe to assume that as long as they have power, they're driving the outputs between high and low and thus you don't have to worry about pullups. |
|
#3
|
|||||
|
|||||
|
Re: FIRST IR module driver released
Quote:
Quote:
All right, I'll make the changes. I was hoping to be able to do something like that--I don't want to mess with configuration bits like that, because I don't want to change the function of other code that relies on the pullups. Thanks for your expertise, because, obviously I just don't have it. Yet. And I'm not supposed to, being that I'm a high school senior... Maybe someday. MI Tech, here I come... JBot |
|
#4
|
||||
|
||||
|
Re: FIRST IR module driver released
Nice code.
But uhm, why does this need a 'driver' per se? Doesn't it just drive a pin high if a code is recognized? Just like reading buttons from the OI pannel or waiting for a limit switch? -q ![]() |
|
#5
|
|||||
|
|||||
|
Re: FIRST IR module driver released
Quote:
Just figured I'd throw this out there. I really don't care if anyone uses it or not. At this point, if the rules stay the same as last year's, I'll have to re-write it come 1/5/08. Hopefully they change the programming/build window rule up a bit. JBot Last edited by JBotAlan : 17-12-2007 at 12:03. |
|
#6
|
|||
|
|||
|
Re: FIRST IR module driver released
Quote:
To power this device while attached to the robot, it would be wise to design a power supply. See http://en.wikipedia.org/wiki/Voltage_stabilizer for a starting point. To connect this device to the robot controller, it would be wise to use opto-isolators/optocouplers to protect the devices from each other. See http://en.wikipedia.org/wiki/Opto-isolator for more information. ~Phil |
|
#7
|
|||||
|
|||||
|
Re: FIRST IR module driver released
Quote:
(Gross oversimplification to follow) Typically, digital outputs come in two general flavors, two-state and tri-state. Two state outputs either drive a pin to high voltage, or drive a pin two low voltage as you seem familiar with. Tri-state outputs have this third additional state called High-Z where the output is at a high resistance. This only becomes important or even necessary if you have two outputs both wired to the same input. If you want them both to reliably drive the input at different times, you can't just assume that driving output A low will let output B signal high and low reliably. That would depend entirely on the resistances of the traces an a host of other factors that might not stand still over time. In most cases it wouldn't ever work, period, and the input would always see a low voltage. So, instead, you put output A into a High-Z state and it no longer affects the signal because no current is passing through it. (To a first order approximation) (End oversimplification) That's all ignoring the host of other output styles available and a lot of other issues, but that's the gist of the purpose of a High-Z state. It's simply to more or less remove that particular output from the circuit that's driving the input. Pull-up resistors serve a slightly different function. Without a pull-up resistor, an input with nothing connected to it isn't in any well defined state and might, in fact, fluctuate wildly between high and low states. With the pull-up (or down in some cases) resistor, if there isn't an active device sourcing or sinking current on the other end of the circuit, a trickle of current flows through the pull-up resistor giving more or less 0 volts of drop across the resistor, meaning the input is at (high) volts. When the circuit is sinking current to ground either through a dead short like a limit switch or via a digital output like on the IR module, the pull-up resistor ends up making a voltage divider with the short or digital output. Since the resistor is such a high value (100k) the 5V contributes little to the final voltage at the input, and you end up with ~(low) volts at the input. The main reason for turning off pull-up resistors is that they can slightly slow down logic transitions and introduce noise from the power supply into the digital input. For all this and more, I heartily recommend "The Art of Electronics" by Horowitz and Hill. It's a bit thick and expensive and the '89 2nd edition is a little dated... but a new edition is set for March and the do a rather good job of introducing things with as little math as possible at first to help you get a good feel for it. |
|
#8
|
||||
|
||||
|
Re: FIRST IR module driver released
Quote:
According to the "The board contains an IR sensor, a CMOS microcontroller, a 5V voltage regulator,...." No additional power supply should be needed. That is why section 6 states, "6 Operating Voltage, Output Current 6.1 Operating voltage range The onboard voltage regulator needs at least 7 volts DC, and can accept more than 15 volts. To avoid problems, a reasonably clean voltage source is recommended to power this board. Avoid having any noise glitches on this supply that go below 7 volts DC." I would agree, running it from the main +12 V battery may be a little risky, but running it from the 7.2Vdc backup adds an additional load to that battery that will need to be accounted for. So, how do you handle this??? As long as the rules will allow it, use a large mAh battery for the backup, say 1500mAh??? |
|
#9
|
|||
|
|||
|
Re: FIRST IR module driver released
I haven't reviewed the code fully yet, but I do have a comment about style.
You have written the following: Code:
//If we're in debug mode, include stdio.h for printf.
#ifdef IR_DEBUG_MODE
#include <stdio.h>
#endif
//then, somewhere in the body..
#ifdef IR_DEBUG_MODE
printf("FIRSTIR:" ... );
#endif
B) Instead of having to type preprocessor If's all the time, you can consolidate your printf's with something like this.. In the .h file: Code:
#define IR_DEBUG 1 #ifdef IR_DEBUG #define IRDEBUG(S,A,B,C,D) printf(S,A,B,C,D) #else #define IRDEBUG(S,A,B,C,D) ; #endif Code:
IRDEBUG("FIRSTIR: CMD Inputs...0: %d, 1: %d, 2: %d, 3: %d\r\n",IR_CMD0_INPUT, IR_CMD1_INPUT, IR_CMD2_INPUT, IR_CMD3_INPUT);
|
|
#10
|
||||
|
||||
|
Re: FIRST IR module driver released
this may be a really foolish question,
but if you look at the page for the documentation on the sensor(http://www.usfirst.org/uploadedFiles...20_121007.pdf), it looks like you have to physically push a button to program the ir chip, and thus the sensor will be learning a code prior to the match, and thus there is no need for code to receive the ir pattern as the code is stored in the chip i believe that based on this what is going to happens is that each team will be given an ir pattern at the beginning of the match, and then will complete a goal using that code |
|
#11
|
|||||
|
|||||
|
Re: FIRST IR module driver released
Quote:
At this point, this code has been written on the assumptions that a) FIRST is not changing the controller this year, and b) we actually are using this sensor on the robot. Both conditions are guesses, so this piece of software may be totally useless for the 08 season. We'll see. Thanks for the style hints, Tom. If you have any more, I'd love to hear them. After writing these files, it seems they are kind of...messy. But I tried my best with the limited knowledge I have, and that's all I can hope to do. JBot |
|
#12
|
|||
|
|||
|
Re: FIRST IR module driver released
Quote:
If the device is running in and of itself, connected to nothing but a battery like the KOP backup battery, then the voltage supplied by the battery would be sufficiently clean for the simple regulator (that is onboard the device) to power the device. If the device is being powered by the 12v battery of a complete robot, there are many other noisy loads on it that can easily drop the voltage below 7 volts for however short a time. That is probably enough to cause a problem for the embedded micro controller if it is anything like any other PIC that I've worked with. So I would probably add another stage of voltage regulation just like the regulator circuit on the device, but with larger capacitors and think that would probably be fine, but I'm not so confident in that idea as to post it as a solution. ~Phil |
|
#13
|
||||
|
||||
|
Re: FIRST IR module driver released
Well, since the board has a 7805 linear regulator on it, simply throw a large noise filter capacitor on it, and run it off the main battery. The capacitors will keep the voltage at a steadyish 12v, and the 7805 will burn off the rest of the voltage as heat.
|
|
#14
|
||||
|
||||
|
Re: FIRST IR module driver released
Quote:
Honestly, I don't know if adding a couple caps is legal, but it certainly would provide the filtering needed, assuming they were large enough. So, instead of advising adding more caps, I opted for using a more robust power source. The backup battery will have enough power as long as it has enough capacity. As of last year, a larger backup battery was within the rules, as long as you charged it from the KOP charger. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| FIRST Lego League Game Released | Pavan Dave | FIRST Lego League | 8 | 13-11-2007 08:57 |
| FIRST Scouting Network 0.2b Has Been Released | Adam Richards | General Forum | 7 | 19-03-2006 12:08 |
| Serial Driver and 2K6 Encoder Driver Not compatible | Tom Bottiglieri | Programming | 6 | 12-02-2006 01:11 |
| FIRST inspired subwoofer box... pics finally released!! | Elgin Clock | Chit-Chat | 7 | 03-12-2003 16:47 |
| Who is the most SKILLED driver in FIRST? | Austin | General Forum | 40 | 05-06-2003 12:33 |