Higher Voltage of Low-Logic Level and Unclean Output from ATTiny2313

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

Hi AVR Experts,

 

As the title suggests, I'm having problem with the output of my ATTiny2313. I'm trying to drive my LED strip using PWM. Everything looks fine until I set the PWM duty cycle to 0. The LED doesn't turn off completely, there is still a little light shines, though, dimly.

 

I think this is really weird and check the output signal using my oscilloscope to make sure the duty cycle is really 0. Surprisingly, the duty cycle is really 0, but it has a higher voltage than the datasheet tells. It is supposed to have a maximum 0.7V, yet I have 0.8V and some spikes that peak up to 2V. However, the power supply is perfectly fine, it produces a flat 5V, you can see it in the attachment. The yellow one is my power supply voltage, the red one is the ATTiny output pin.

 

I don't understand how it happens. Can you guys tell me some clues to fix this?

 

Oh, btw I'm using the PWM to drive a TIP41C transistor in series with a 100K resistor.

Attachment(s): 

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

If the 100K resistor is in series with the transistor's base, try adding a 1 meg ohm resistor from the base to ground.

 

Better would be a 10K series resistor with a 100K resistor to ground.

 

 

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

Thanks for your reply. I will try that as soon as I get home.

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

100k base resistor with a TIP41C? Not a good choice.

 

The maximum base current you'll get is, assuming a 5v supply, (5v-0.7v)/100k = 43uA. The TIP41C has a maximum current gain of 75, so the maximum collector current you'll get is 75*43uA = 3.2mA. Is that enough to light your LEDs?

 

Either drop to 100k to something around 1k, or swap the TIP41 for a FET.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

My guess: OP uses fastPWM mode.

He'd better use Phase and Freq correct PWM instead. PWM frequency drops to half but the good news is that 0% PWM == LEDs OFF.

This is described in the datasheet btw

 

To OP: posting a schematic helps us to debug. And post the software as well.

 

Second thought: is the PWM-pin configured as output ?

Third: do you drive more LED-strips with the 2313 ? High groundloop current could be the cause as well.

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tessa and Tina, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

Last Edited: Sun. Feb 19, 2017 - 12:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry for late reply. I have tested Chuck99's idea to put a 1M resistor between the base and ground. It didn't give the result I had expected. The LED still shined at 0% duty cycle.

 

However, it did give me an idea to make a voltage divider, as shown in the attached schematic. It sort of helped to turn off the LED completely. I say sort of because there is still a glitch there.

 

The glitch can be explained by the logic of my program. The code will control the brightness for each color of my RGB LED strip. Each color has 8 level of brightness, and by pushing the button (using pin change interrupt to detect the rising edge), the level is increased by 1. After it reaches Level 8, the LED then is turned off (level 0). So, after I use the voltage divider, the blue and green LED are fine but the red has a weird level cycle there. Before I change the circuit when I still use a 100K, the cycle was fine, but now it restarts when the level reaches level 5, then it turns off when push for 3 more times. Also, the base voltage level fluctuates. Sometimes it has 1.75V at HIGH logic across the R9, sometimes it is as low as 1.4V which is really weird. Any suggestions?

Attachment(s): 

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

Everything looks fine until I set the PWM duty cycle to 0.

Are you using Fast PMW Mode? 

 

There is a "feature" in Fast PMW Mode where an output of 0 isn't 0!

When set to 0 output there is a periodic spike in the output.

This can really screw things up, and can give you your dimly lit LED, as the LED isn't really fully off.

 

The way to fix this is to have a special case in your code where you test for setting the PWM output to 0.

If you set the output to zero, then instead of 0 you invert the output signal and output 100%.

100%, full On, but with an inverted output, gives you a true full off output.

 

ATTiny2313  11.7.3  Fast PWM Mode

 

The extreme values for the OCR0A Register represents special cases when generating a PWM

waveform output in the fast PWM mode. If the OCR0A is set equal to BOTTOM, the output will

be a narrow spike for each MAX+1 timer clock cycle. Setting the OCR0A equal to MAX will result

in a constantly high or low output (depending on the polarity of the output set by the COM0A1:0

bits.)

 

I suspect your O'scope doesn't have the bandwidth needed to show the very short single clock pulse generated with the PWM set to 0 very well, hence you see the 2 V "spike" you are seeing.

 

I don't know if this is the source of your problem or not, but it might be worth looking into.

 

JC 

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

Actually, I am using Phase Correct PWM on all output pin, which shouldn't cause any spikes. 2V spikes that occur are actually more like bumps if you see the attachment from the first post. At first, I suspected my voltage regulator was a defect unit, that's why I looked at the power supply voltage through the oscilloscope. However, it was a very flat 5V.

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

Looks like your spikes are coming at about 120 Hz.  You've got a problem with mains interference somehow.

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

So, yesterday I rebuilt the circuit from scratch to see where it had gone wrong. I found out I had accidentally swapped some 1K resistors at the output pins with 10K resistors. I also replaced all bad wires with better ones on my breadboard. Well, the result is better, the behavior is more acceptable, but the 2V spikes are still there. Also, I found another glitch when I measure the output. There's an interference between the output pins. You can see it in the attachment, the result and the point of measurement.

 

In the Measurement A picture, there are 2 channels. Channel 1 refers to point A1 in the Measurement Points image, and Channel 2 refers to point A2. You can see that the output pin for GREEN_LED is affecting the RED_LED pin as well. I even measured right at tiny's pin directly, indicated in Measurement B picture that refers to point B1 and B2. Measurement C shows the graph at point B1 and PD4, the pin I don't use. It also indicates that it also affects other unused pin as well. Is this normal or am I having a defect unit? Any suggestion is appreciated.

 

Attachment(s): 

Last Edited: Sun. Feb 26, 2017 - 02:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you getting 'ground bounce'? Due to the led current running through your 0V circuit, the resistance of the wiring in that path cause a voltage drop - thus causing your 0V to bounce.

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

How and where did you connect your scope ground?

 

Your led strips probably draw a few amps of current.

Currents like these should never be routed through things like breadboards or thin wires.

When designing a PCB the layout of the GND traces is also an important factor.

(Just as good connectors, etc).

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

Hi guys,

 

I'm back from the dead now cheeky I've been very busy at work these last 2 months and haven't had any chance to continue this project. But, yesterday I did have time continuing the project.

 

I decided to check part by part when building the circuit. First, I made a blinking LED to measure the low logic level whether it exhibits the same problem. Then, I continued by using PWM to check for the same problem, added 2 more LEDs driven by PWM. Lastly, I downloaded the original program into the ATTiny and even added a new feature to use an additional button. To my surprise it just worked very well! All the outputs were clean, with only a small 10-20mV noise. Even the voltage dividers, that I had used to accomodate the higher voltage low logic level, could be removed now. Now, it has a flat 0V low logic level with only a max 80mV spikes.

 

I don't know what happened in the earlier circuit, but after rebuilding it from scratch, it just works like a charm. Also, I even tried with all of my ATTiny to see whether the last circuit was using a defective one. But, no, all chips were working correctly. Very strange indeed. indecision