Car battery voltage regulation for ATtiny85 (and other MCs)

So my tachometer project is working good up until I try to power the ATtiny85 with my motorcycle's 12V battery. I Am using an LM7805 5V regulator to get down to the proper voltage. The problem is that my outputs (LED's) freak out and do random things when I power it from the battery if the bike is running. If I connect everything to my motorcycle except use a 9V DC wall adapter and run that through the regulator it works fine. The same goes for swapping the supply with a 9V battery. I have been looking into voltage regulators and the only thing I can see that I am doing wrong is I'm not putting a couple tiny capacitors between the Vin and ground and Vout and ground on my regulator like this: 5v Regulator by Thedasdet on DeviantArt

I think I am getting huge spikes of voltage from my battery which causes my regulator to fail (even though it is rated up to 18V, and I didn't think a car battery spikes as much as 50% over itself). But then if that happened, wouldn't my MC get fried? I don't know. All I know is that there is noise or some kind of interference coming from my motorcycle battery only when the bike is running.

Attached is my crudely drawn schematic.

Thanks a lot!

Ok, I just came across this. Although he didn't actually build it yet (or say anything about that) I really think he knows what he is doing. Should I go ahead and build this?

The voltage regulator needs the input and output capacitors to work effectively. There will definitely be a lot of high frequency noise coming across the 12v from the distributor cap. You will probably need a 12v inline noise filter before the regulator. I would also recommend a 0.1uF decoupling capacitor across the VCC and GND pins on the ATtiny85.

http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

You need at least a 100uf cap on input side of the LM7805 in this application as well as a 0.1uF on the output. Also, as already suggested put a 0.1uF across Vcc and Gnd of the ATtiny. If you can get a hold of a 50mH to 100mH choke rated at twice the current your circuit draws would also be very nice and quite possibly a requirement. I am assuming your circuit draws less than about 100-200ma. Those 4-amp automotive radio filters are pretty bulky.

BTW, what kind of bike is it?

There are a myriad of solutions for that kind of noise which comes from the electronic ignition... But I'd try a Buck mode converter and shielded wiring to sensors.. Grounded AT the Controller, Only. There are buck mode converters that can take 60 to 80V 10 MS spikes available and If I was REALLY worried I would kick it back to whatever voltage I needed. The reason why it works is the switch and the energy storage inherent in the coil and capacitor used as the storage elements..
In the 1980's I was designing radio/intercon interfaces for offroad racing and that was something that worked well... They can be had for 2 - 3 dollars on Ebay.. "Free Shipping Too",,,

Doc

An LM3914 would be a much better deal as a voltage monitor and can easily be expanded to a spread type of meter that reads a small range of voltages...
There are some relevant app notes in the data sheet and I'm Sure that Mr Google has a big lot of answers if the data sheet doesn't,
Data sheet attached...

Doc

LM3914N.pdf (371 KB)

So I went ahead and built my regulator, there it is below. It worked alright when I just had it on a breadboard but I haven't got to try the board on my bike since it's a little too late to be revving my bike up.

Also, for everyone saying that I need a 0.1 uF across Vcc and GND, well there already is one. The 0.1 uF capacitor's pos and neg nodes are on the same nodes as if I were to put one there distinctly.

BillO:
You need at least a 100uf cap on input side of the LM7805 in this application as well as a 0.1uF on the output. Also, as already suggested put a 0.1uF across Vcc and Gnd of the ATtiny. If you can get a hold of a 50mH to 100mH choke rated at twice the current your circuit draws would also be very nice and quite possibly a requirement. I am assuming your circuit draws less than about 100-200ma. Those 4-amp automotive radio filters are pretty bulky.

BTW, what kind of bike is it?

It's a 1996 Ninja ZX6.

Okay, let us know how it works out. The ZX6 electrical system, while not really clean, would be cleaner than something like a KTM EXC. If it still gets upset, the choke would be the next thing to try. Something like this:

I would still include ZD1 and D1 per the schematic in your second post. ZD1 protects you from high voltage spikes and D1 protects from reverse voltage spikes. The parts cost just pennies.

I have blown up 78L05 regs before by not using input capacitors, Capacitors are a must end of. The theory goes one 10+uF and a 100nF each side but i see that these days many dispense with the 100nF - no comment there I'm not such an expert.

You can use an lm7809 for your 9V - whats the problem ?

I typed a long reply and it was rejected...

It worked fine save for some coding tweaks while my motorcycle was just sitting on its stand in my garage doing some rev tests. But upon actually taking it out and riding it, the thing kept restarting (I have a short startup sequence of the LEDs) and freaking out.

So I have come to the conclusion that my motorcycle's (1996 Kawasaki Ninja ZX6) electrical system is so unstable that no sort of digital electronics can run off it.

On a side note, I found a guy that did an LED tachometer on youtube but he did not use a microcontroller, used a frequency to voltage converter straight off the ignition coil, and used some LED drivers.
My First LED Tachometer - YouTube!

sparkylabs:
I have blown up 78L05 regs before by not using input capacitors

Really? how?