Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: ixarka on May 26, 2008, 05:46:18 PM

Title: Sharp IR causing microcontroller reset
Post by: ixarka on May 26, 2008, 05:46:18 PM
Hello all,

I've spent the better part of this afternoon trying to solve this problem.  I've also tried searching these boards, figuring someone else must have encountered this problem before but couldn't find anything.  If this question was answered in a previous post, please point me to it.

Here's my setup:

I've got a PIC18F wired up to a sharp GP2Y0A21YK0F.  I've got some LED's and a 7-segment display that visualize what the ir sensor is outputting.  When I run this circuit using the PICkit2 attached to the breadboard (using power from the USB port) everything works great.  If I disconnect the PICKit2 and attempt to power the whole thing off of 4 AA's, then the first LED in my startup test pattern lights up, but then nothing happens.  It's like the PIC has frozen or crashed.  If I disconnect the Sharp IR from the circuit, the LED test pattern blinks just fine and everything else appears to work. 

I've got a 5V regulator to make sure the supply voltage is good and a capacitor (tried both a 0.1uF and a 470uF) wired in parallel with the Vcc and Gnd of the IR sensor.  I've also tried disconnecting the output pin of the IR sensor (ie, I've just plugged in Vcc and Gnd) and the problem still occurs.  I tried another Sharp IR as well, and the problem still occurs.


Any idea what could be going on?  Any help would be much appreciated.
Title: Re: Sharp IR causing microcontroller reset
Post by: Commanderbob on May 26, 2008, 09:34:11 PM
Make sure your batteries are new. The SharpIR sensors take large bursts of power that can reset the PIC. Make sure you have a few caps next to the sensor.
Title: Re: Sharp IR causing microcontroller reset
Post by: bens on May 26, 2008, 10:05:59 PM
The sharp IR datasheet recommends putting a 10uF capacitor or larger between Vcc and ground somewhere close to each sensor you use.  This is to smooth out disturbances caused by large power drains that occur while the sensor is emitting it's IR.

- Ben
Title: Re: Sharp IR causing microcontroller reset
Post by: JonHylands on May 27, 2008, 06:05:03 AM
What kind of voltage regulator are you using, and what kind of AA batteries are you using? (Alkaline or NiMh/NiCd)

If you're using Alkaline, and they are brand new and fresh, you're looking at 6 volts output. If you're using a 7805 as your voltage regulator, the dropout voltage is 2 volts, so you need at least 7 volts in to maintain a 5-volt output. If you're using NiMh or NiCad, you're not even at 5 volts output from the pack. If you're using a low-dropout regulator (like an LM2940), which drops 0.5 volts, then a 6-volt source should be okay.

As another poster has mentioned, Sharp IR rangefinders are notorious for chewing current, sometimes as much as half an amp at startup.

Recommendations:

- make sure you've got more voltage than you need - if you're using NiMh, use 6 or 8 cell packs, if you're using Alkaline, 5 or 6 cells
- use a low drop-out voltage regulator. Note if you use the LM2940, it has strict requirements about capacitors on the input and output legs.

- Jon
Title: Re: Sharp IR causing microcontroller reset
Post by: SixRingz on May 27, 2008, 08:49:58 AM
My advice is to try the same setup but with different power supplies for the MCU and the sensor(s). Just make sure to ground them properly... (connect grounds)
Title: Re: Sharp IR causing microcontroller reset
Post by: ixarka on May 27, 2008, 09:27:02 PM
Many thanks to all of you!  It's working now.  I was using 4 NiMh AA batteries, along with the 7805 regulator.  I never thought to measure the voltage across the regulator, since the little blurb on the back of the radioshack one made no mention of a voltage drop.  I thought the whole point of a regulator was to keep the output voltage constant, regardless of input voltage (by varying maximum output current).  Anyway, the output of the 5V regulator was at 4.4 volts.  I switched out my battery pack for a 9V alkaline.  That didn't fix the problem, though.

Turns out the capacitor really does have to be "close" to the Sharp IR.  I had it on my breadboard, next to where I plugged in power, and it doesn't work.  But if I place it directly across the Vcc and Gnd of the sharp IR, everything works fine!  Yet another circuit abstraction demolished.

Thanks again.
Title: Re: Sharp IR causing microcontroller reset
Post by: Commanderbob on May 27, 2008, 09:51:31 PM
Yep, the placement of some parts is extremely important. ;)
Justin
Title: Re: Sharp IR causing microcontroller reset
Post by: JonHylands on May 28, 2008, 06:54:11 AM
You need a decently big capacitor somewhere downstream of the voltage regulator. If you put it on the battery side of the regulator, you're not getting any benefit from it.

On Seeker 2, my mini-sumo, I use a 1000 uF 6.8 volt electrolytic capacitor just downstream from the voltage regulator. I also have a 0.01 uF ceramic cap across the Vcc and ground pins right next to the microcontroller.

(http://www.huv.com/miniSumo/seeker2/Seeker-II-Pieces.jpg)

Big version:

http://www.huv.com/miniSumo/seeker2/Seeker-II-Pieces.jpg (http://www.huv.com/miniSumo/seeker2/Seeker-II-Pieces.jpg)

If you look at the circuit board, on the left you can see the LM2940 low drop out regulator, the two small caps it uses, the large 1000 uF cap to the right of that, and the 0.01 uF cap just below the microcontroller (PIC 16F876). The other two caps above the PIC in that image are 18 pF caps for the 20 MHz crystal.

- Jon
Title: Re: Sharp IR causing microcontroller reset
Post by: winglessbuzzard on July 30, 2009, 08:15:16 AM
Anyone... please help with a very basic question.  When you say "capacitor wired in parallel with the Vcc and Gnd of the IR sensor."  Does this mean that:

let's say the capacitor pins are pin 1 and pin 2
do you make the following 4 attachments:

Vcc to pin 1
Analog input pin on your microcontroller to pin 1
GND from the sharp IR to pin 2
Your Main Ground to pin 2

It seems like that's what it suggests, but in this scenario it doesn't look like the capacitor is doing anything since the Vcc will take the path of least resistance and just continue flowing down the wire to the analog input on the microcontroller (since they're both attached to the same pin on the capacitor).  I'm a little confused (obviously) and any help would be greatly appreciated.
Title: Re: Sharp IR causing microcontroller reset
Post by: SmAsH on July 30, 2009, 03:10:56 PM
vcc and gnd should be common with the power bus (if there is one), so you would put the + of the capacitor to +5V regulated and - of the capacitor to gnd.
this just supplies extra current whenever there are spikes to "smooth" them out.
Title: Re: Sharp IR causing microcontroller reset
Post by: winglessbuzzard on July 30, 2009, 03:37:42 PM
SmAsH,

Ok... so the capacitor should be in no way attached to the V-out on the IR sensor.  Judging by your response, please tell me if this is correct:

IR VCC to + side of capacitor
IR GND to - side of capacitor
IR V-out to microcontroller analog pin
+ 5V regulated to + side of capacitor
Main Ground to - side of capacitor

(hopefully that's correct)

I may be missing a concept, but it still seems to me that the power would flow directly to/from the IR sensor, completely ignoring the Capacitor in this setup (following the path of least resistance).
Title: Re: Sharp IR causing microcontroller reset
Post by: SmAsH on July 30, 2009, 04:06:51 PM
yes, thats correct.
the capacitor is just there as a reservoir... current will just flow past it, but if there is ever any extra or any lack the capacitor will fill it in...
its just to smooth out any noise/spikes.