Problem with powering ATtiny441 and 12v LED on the same circuit

Go To Last Post
28 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone,

 

I am still kind of new in prototyping electronics, and recently made a board with ATtiny441 that should drive 2 12-volt RGB LEDs.

On the breadboard everything seemed to work fine, however when assembled I does not work as intended.

Please find the electronic diagram attached. I checked it against the board many times and it matches 100%.

 

Symptoms:

1. The reset button have to be held for 2-5 seconds before MCU actually resets.

2. The program burns fine, but does not execute in intended manner. The encoders have to change colors - which they do on the breadboard - but do either nothing or in 5% of tests change to a random color.

3. After reset, the colors are random on both channels and sometimes flicker.

4. The MCU gets really hot in 70% of starts.

5. The Voltage Regulator gets very hot. Tried replacing it with a buck converter but light flickers and heats up too.

6. With the Voltage regulator out of the circuit, the resistance between logical "-" and "+" is about 1MOhm, between power "-" and "+" is 1.4MOhms if that's any helpful.

 

My best bet is the circuitry around the battery and the Voltage Regulator.

Want to hear your opinion before blaming MCU and desoldering it.

 

Any advice will help. I spent about 3 month trying to find the problem.

 

Best,

Gary

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Is your 5V supply actually stable? Normally you add capacitors at the input and the output of the voltage regulator (7805).

 

Also a 100nF decoupling capacitor is usually added close to the MCU VCC pin.

 

Also normally you add a current limiting resistor at the base of a BJT transistor, your MCU though has a maximum current output so you might be okay(?).

 

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, you probably definitely need resistors on the base of the transistors from the encoders!

 

The connection of the encoders though seems a bit odd to me, but then again I'm not really familiar with using encoders... What is the idea? (Do you have a part number?)

- Brian

Last Edited: Mon. Sep 10, 2018 - 09:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yo-jae wrote:
I spent about 3 month trying to find the problem.

So what tests have you actually done in that time?

And what did you find from those tests?

 

What test equipment do you have?

Oscilloscope?

Logic Analyser?

Debugger?

Voltmeter?

Ammeter?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

For this kind of stuff, it's more popular to use the ULN2803A Darlington array. It has 8 channels and built-in components to minimize errors like you did, not using base resistors. Or forgetting flyback diodes for inductive loads.

Diagram of each channel:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Geronimo's updated schematic is a big improvement, but it is still missing a critical component.

 

You need a series resistor in series with each LED in the 3 color LED's. 

i.e. you need 6 more resistors, in addition to those Geronimo already added.

 

Right now the LEDs and the 2222 transistor act as an almost short circuit across the 12 V supply.

The LEDs have a small forward voltage drop, perhaps 1.2 V, the transistor has another small Vce voltage drop, so you are shorting out the 12 V supply.

You need a series resistor for EACH LED in the package.

What is the LED's current rating?

(low power 20 mA LEDs, "high power" leds? etc.)

(Without looking up Vce, and a quick back -of-the-napkin estimate of 2V)

Assuming I led is 20 mA, and its Vf = 1.2 V

 

R = V/I = ( 12 - (1.2 + 2)) / 20m = 440 ohms.

 

So, to be save on Ilimit for the leds, use 510 ohm resistors, or something similar.

 

Note that you may have fried your 2222 drivers, and the LEDs, and perhaps the output drivers on the uC...

 

It would be best to start over with new components.

 

It may have "worked" before if your 12V source was a small battery, or something that was very limited in its output current capability, and had a high internal resistance.

 

Please post your NEW and Improved schematic before you power it up and one/some of us will give it a quick look over.

 

Also, yes, the by-pass cap (0.1 uF) across the Vcc/Ground pins on the micro, as physically close to the micro as possible, is required for reliable operation.

 

Also, fully agree that you need to look at a data sheet for the 78... voltage regulator and ADD the input and output caps to the circuit.

 

Last comment, the pull-up resistor on the reset\ pin can be higher.

I usually use 10K, some other's use 4.7K, (typically for noisy environments, (factory, radio transmitter, etc.)).

 

Good luck with your project, you are close.

 

JC

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
It may have "worked" before if ... something that was very limited in its output current capability, and had a high internal resistance.

A (presumably solderless) "breadboard" was mentioned in the OP ... 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

DocJC wrote:
You need a series resistor in series with each LED in the 3 color LED's.

 

yo-jae wrote:
that should drive 2 12-volt RGB LEDs

 

I assumed LED's with built-in resistors because OP did write "12V LEDs" (even if it's not shown in the diagram), but if they are not built-in then yes, they are definitely needed!

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

The MCU gets really hot in 70% of starts.

Throw it in the trash & put in a fresh one to save a big headache & messing around.  Your LEDs could also be toast, depending on their ratings & how strong the driver was (assuming the leds were being overdriven due to lack of resistors).

 

Why are your encoders tied to the led drivers in some strange manner (ex: collectors to encoder 2)?

 

Use the GND symbol in your drawing.  Parts should be oriented so things head to gnd in a downward direction, not upwards (if at all possible).  Thus a pulldown resistor pulls "down" to gnd.  A lot of your schematic is "upside down".

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you GeronimoEl TangasDocJC, avrcandies. Your answers are very helpful.

 

I updated the circuit with all corrections, and decided to use ULN instead of MMPQ.

 

The schematic is upside down, but it's already drawn. Next time I'll do it the right way, sorry about that.

 

Also, not sure whether I should use resistors in between ATtiny and ULN. Some examples have them, some don't. I just ordered them and did not receive yet, so didn't have a chance to try it. 

 

The 2 diodes in the middle (ex MMPQ emitters) is a "coupler" for a signal from encoder presses. When either encoder is pressed, the PA0 would receive high and treat PB1 and PB2 as signal for respective encoder press. When low, PB1 and PB2 would interpret encoder-2 rotation. Yes, if user presses and rotates at the same time it would cause total undefined but I am being optimistic about the user.

 

Please review the latest diagram. Hope it looks better this time.

 

Best,

Gary

Attachment(s): 

Last Edited: Wed. Sep 12, 2018 - 07:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You should use the gnd symbol wherever gnd is used...it will make you diagram MUCH better.

 

Get rid of R8/R9 (R3 is already your pull down)...they also cause you encoder signals to be dragged down  (through diodes & r3)

 

R1/R2 reduces your signal...why not make them 100 ohm (for a short circuit current limit). Or get rid of them.

 

Maybe add a schottky diode in series with batt, since you can afford the drop down to 5v, then it protects against wrong power polarity being applied. 

 

Is 1k for the leds too high (need to know leds specs)??  if there was no led Vdrop you'd have about 11 ma max (allowing 1v drop on driver).  A few volts Vled will  reduce the current further.

 

 

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yo-jae wrote:
Also, not sure whether I should use resistors in between ATtiny and ULN. Some examples have them, some don't.

 

The ULN comes in different versions (ULN280x), the ULN2803 is meant to be used with 5V devices and doesn't need any additional input resistors (they are built-in).

 

 

 

If you were using a 3.3V MCU, you might need the ULN2801, which has no input resistors, and you'd have to add a smaller external input resistor to each input.

Last Edited: Wed. Sep 12, 2018 - 09:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why R8/R9? What is the idea?

 

When you push one of the switches you will get a high signal on PA0 (4.3V) but you will also get a high signal on either PB0 or PB1 (4.1V) at the same time!

When you turn encoder 2 you will get a high signal on PB0 or PB1 (3.66V) but you will also get a voltage on PA0! It shouldn't be high enough to get you a logical 1 on the pin, but it's well above the "maximum low level voltage" of 0.3*VCC, you will have 2.43V!

If both A and B on encoder 2 can be on at the same time, you will have 3.13V at PB0 and PB1, which should be enough to read as a logic 1, but only just (min 3V)! And also you will have 2.2V on PA0.

 

 

So, eliminate R8 an R9 (unless you have a great reason not to?), and while you're at it you could also get rid of one of the diodes! Or actually both! (Why the diodes at all?)

 

- Brian

Last Edited: Wed. Sep 12, 2018 - 11:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks everyone, really appreciate your help.

 

avrcandies, Will use GND instead of the wire in next revision. Otherwise updated the circuit with Shottky diode, and removed useless 2k2.

I am using LED stripe LC-128 and from their specs, 9-10 cells per channel will give me roughly 800 Ohm, so I made it 1k to be safe. Still kind of boggles my mind why all the energy cannot be converted to a light...

 

El Tangas Sounds like I don't have to use any resistors for PWM channels. Thank you.

 

Geronimo My mistake on re-designed diagram.

Thanks a lot for pointing out, updated with proper circuitry.

I don't want PB1 and PB0 both high when one button is pressed, that's why I "decoupled" them.

Forgot why I needed 4 diodes initially. There should be really 4 of them.

Also added my idea which may explain how MMPQ2222A was used in the initial circuit.

That part was working and utilized my MMPQs 100%, however needed 2 resistors each button - so I will use 4 diodes this time.

 

Really value your help guys. Thanks again

 

Gary

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

NO

Put your diode in SERIES with the battery, you have many volts to spare & can afford a 0.25V drop.

 

Are you trying to start a fire (either the battery or diode)?

Do not cross wires while making a connection...too easy to miss or get lost on the copier.

     

 

 

note these connection leave no ambiguity or room for accidents:

 

 

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yo-jae wrote:
I don't want PB1 and PB0 both high when one button is pressed

 

Why do you want any of them to be high when you press either Sw1 or Sw2? To detect which button was pressed?

So what happens if for example the encoder pulls high PB0, but you press Sw2 which pulls high PB1 or vice versa?

You still wouldn't be able to figure out which button is pressed!

 

Maybe you'd be better off with simply using two or three resistors (as voltage divider), switch PA0 to ADC and detect the voltage on the pin to figure out which button is pressed!

Sure you'd have to read the ADC cyclically, but as a bonus you'd be able to read if Sw1, Sw2 or both are pushed simultaneously with just one pin!

 

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies it is a valid note about connections. I wonder if I can also configure KiCad for ark-type wire crossings.

 

Geronimo valid solution, I agree it will work mucho better. However I am not too familiar with ADC and not sure how will it act on low battery. Definitiely way to improve this in future (and I like using 3 resistors instead of 4 diodes) but this revision I want something working. 

 

Thanks everyone for your input. As a result of collective efforts, here is final chematics:

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't know much about the exact specs of your encoder.   But note if it is adjusted/turned so switch Enc 2  "A"  is closed (line high), then D6  will have no effect when the button is pushed (since the line is already high via switch A)

The other encoder can do the same & both could happen at the same time...then neither D5 or D6 would have an effect.  D1 & D2 would still do their job.

 

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yo-jae wrote:
However I am not too familiar with ADC and not sure how will it act on low battery.

 

If you use VCC as your ADC reference voltage, the actual VCC voltage should not affect your readings!

It will still be the same proportion of your reference and hence the same ADC value.

 

Also you are using a voltage regulator after your battery, so VCC should be fairly constant at 5V unless your battery voltage drops below 7V or so.

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok avrcandiesGeronimo - I am convinced about ADC on PA0.

Thanks Geronimo for the calculations. Now it's time to build a prototype.

Best,

Gary

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

So, using Vcc as the ADC Vref, you could use the adc result:

 

000-204   COUNTS: NO SWITCH PRESSED

205-511   COUNTS: SWITCH 2

512-655   COUNTS: SWITCH 1

656-1023 COUNTS: BOTH 1&2

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Gentlemen,

Thank you all for help and support.
After long period of blockers and issues I am finally satisfied with the result.

Ordered PCBs from JLCPCB - utterly happy with quality.
Decided to read only ADCH for encoder presses - 8 bit precision is plenty.
Had to add additional flag check for middle range conversion - to ensure high-ranged button was not pressed. On button release it sometimes registered both button pressed, as the voltage drop is not immediate.

Added LP filter to eliminate flickering (did not solder condensers in for sake of debugging)
Now it's time for fine tuning and additional stuff as I have 3 kb free.

Best regards and Happy Thanksgivings,
Gary

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Geronimo wrote:
I assumed LED's with built-in resistors because OP did write "12V LEDs" (even if it's not shown in the diagram), but if they are not built-in then yes, they are definitely needed!

You are right. Just tested with 20-section (by 3 LED each) stripe and it shines much brighter with resistors shorted. The resistors are indeed present on the stripe. I will add small resistors there cause I also want to add LP filters (basic cap filter) to the outputs.

Last Edited: Wed. Dec 5, 2018 - 07:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Gary,

 

Just wanted to drop a small advice. to make your circuit and schematics a little bit clear, you can use the symbols (3V3/ +BATT/ GND..etc -> Check Place component on the right side) instead of connecting each wire from A-B. also you can use local or global flags from each GPIO to the intended pin target.

 

This has the benefit later when you export the net list to pcbnew. then you could make a better PCB. Global flags and local flags can be found on the right bar on Eeschema as well.

 

Good luck,

Moe

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yo-jae wrote:
I wonder if I can also configure KiCad for ark-type wire crossin

 

Now here comes the benefit of global/local labels*

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

To make it simpler: in the above the LDO outputs stable 3V3, this output can be connected to any pin to give an input of 3V3 (in our case its the MCU). GND planes symbols are connected to gnd by default when u add the symbol. its just the matter later how good you want your ground plane.

 

Likewise here, the glabal label LED_1 (here name used for reference) can be connected to ur LED pin and no need to use the wire all the way from PB1 to the intended pin.

This will help you a lot later if you want to swap some pins (Forward annotation/backward annotation).

 

Regards,

Moe

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Likewise here, the glabal label LED_1 (here name used for reference) can be connected to ur LED pin and no need to use the wire all the way from PB1 to the intended pin.

This should be used sparingly & when a severe constraint requires it.  Using it unnecessarily can degrade the schematic, until it no longer visually shows what is connected to what (which is what a schematic should teach).  At that point, one might as well simply list the pin number names & connections in an excel spreadsheet (which at least can be sorted).   If you don't clearly "see" a signals connections between parts many unseen errors can & do creep in., which would otherwise be readily apparent. 

 

This will help you a lot later if you want to swap some pins

As would simply updating the connecting wires.  Drawing a schematic is not a race; it should establish a long-term quality document.  Saving 5 minutes today won't help the service tech 5 years from now whilst he tries to visualize how components are connected.

 

 

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

Likewise here, the glabal label LED_1 (here name used for reference) can be connected to ur LED pin and no need to use the wire all the way from PB1 to the intended pin.

This should be used sparingly & when a severe constraint requires it.  Using it unnecessarily can degrade the schematic, until it no longer visually shows what is connected to what (which is what a schematic should teach).  At that point, one might as well simply list the pin number names & connections in an excel spreadsheet (which at least can be sorted).   If you don't clearly "see" a signals connections between parts many unseen errors can & do creep in., which would otherwise be readily apparent. 

 

This will help you a lot later if you want to swap some pins

As would simply updating the connecting wires.  Drawing a schematic is not a race; it should establish a long-term quality document.  Saving 5 minutes today won't help the service tech 5 years from now whilst he tries to visualize how components are connected.

 

 

 

- Well, you apparently missed my point. What I was pointing here where to find these stuff, because the OP was mentioning if its possible to do arc "jumper", and I proposed here using the global or local labels as a way to avoid this.

- I dont see any problem in using them. I've seen many schematicsts from STM's, Nordic's dev kits where its used heavily. at the end the person who is looking at them is either an engineer or a person who supposedly understands something.

 

anyway, thanks for commenting

 

Regards,

Moe