Maker Pro
Maker Pro

Attiny85 and unrecognized HIGH levels

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
I am working on RC aircraft projects. Most of the time I am using the Attiny85.
As you already know, radio control systems use PWM for servo control. Pulses of 1000 - 2000 microseconds every 20 milliseconds tell the servos what to do.
My projects are;
- Kill switch for gasoline engine ignition
- Servo reverser
- Servo slower
- Landing gear door sequencer
- Electronic switch (as a replacement for mechanical switches)
- Landing gear motor controller

All but the last project are working fine. Most of them have been tested for more than one year at the field. But I have problems with the last project.

RC Aircraft systems are being powered by batteries and regulators but there is no fixed standart voltage. So the electronic components must work at voltages between 4.8V and 8.4V. For this reason I always use a low dropout voltage regulator (LM2950) in my projects.

I always use one digital pin of the Attiny85 to read the incoming PWM pulse. I use the "pulseIn()" function of the Arduino IDE most of the time and there are no problems. But in the last project I noticed that the pulseIn() function cannot read the pulse width correctly. The HIGH level of the RC receiver output cannot be recognized as HIGH by the Attiny85. I added a transistor stage at the input and as the polarity of the PWM signal is now reversed I changed the code accordingly. This solved the problem.

What I want to know is...

I am using the same basic circuitry (Attiny85, internal oscillator @ 8 MHz, LM2950 as voltage regulator) in all my projects and I am using similar RC receivers (Hitec Optima series). Why do the first 5 projects work flawlessly and the 6th not?
Any ideas would be welcome...
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
I guess you're wanting to express exasperation. You've succeeded.

However, if you want anything more than vague ideas, you'll need to provide more than vague details.

My guesses are noise, ground bounce, ringing, stay capacitance or a low level signal.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,747
Joined
Nov 17, 2011
Messages
13,747
Some of the details we may want to know:

The HIGH level of the RC receiver output cannot be recognized as HIGH by the Attiny85
What voltage is the high level output of the receiver?

in the last project I noticed that the pulseIn() function cannot read the pulse width correctly.
What is the expected value, what does the function return instead?

I added a transistor stage at the input
What does this circuit look like?
 

Bluejets

Oct 5, 2014
6,942
Joined
Oct 5, 2014
Messages
6,942
RC Aircraft systems are being powered by batteries and regulators but there is no fixed standart voltage. So the electronic components must work at voltages between 4.8V and 8.4V. For this reason I always use a low dropout voltage regulator (LM2950) in my projects.

This, amongst other parts, makes no sense.

I'll second a request for a diagram of everything you've done.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
It makes perfect sense to me. The battery voltage might be anywhere between 4.8 and 8.4V so he is using a low dropout regulator to get a known voltage for his ATTINY, probably 3.3V since you cant get 5V from 4.8 with a low dropout regulator.

Bob
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
First of all, thank you very much for your input.
I will try to provide you with more detail.

First of all, the main rationale of the project:
The landing gears of the aircraft are being extended and retracted using an electric motor. The system does not have (unreliable) endpoint switches. So the control module senses the current and shuts down the motor when there is an overcurrent.
The control module receives power and PWM signal from the RC receiver.
You can see the schematic of this part of the circuit here:
1.jpg
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
The PWM signal is a (positive) pulse of 1000 - 2000 microseconds duration repeated every 20 milliseconds. 1000 corresponds to "gear down" and 2000 corresponds to "gear up". So if a gear up command arrives and the current gear position is down, the module energizes one of the relays. The contact of the two relays are connested in an H-bridge configuration.
This is the relay driver part.

2.jpg
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
Power to the relay coil and to the motor come from a separate battery.
After one of the relays have been energized, the software begins a timed loop (10 seconds) and in the loop it continuously measures the voltage accross a shunt resistor (not shown here).
The shunt resistor is located at the "lower" end of the motor and is 0.33 ohms.

The usual current draw of the motor is around 300 mA. If it stalls the current rises above 1000 mA.
Attiny85 has a 10 bit ADC. 1023 corresponds to Vcc and 0 corresponds to 0V.
1000 mA and 0.33 ohms make a voltage of 330 mV. 330 mV corresponds to a reading of 67 in the ADC.

My previous research has shown that a value of 100 is more reliable because during the travel of the landing gear there can be some current spikes and this can lead to premature shut down of the motor.

Anyway, this parameter can be set in the software and I am able to fine tune it according to the actual retract gear system.

This is my PCB:
PCB.jpg
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
First I have printed this PCB using toner transfer method and produced several units which work fine. Then I decided to use more professional PCB's and placed an online order to a China based PCB manufacturer. My current problem started with these new boards.

20170513_215833.jpg 20170417_203455.jpg
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
Now I have installed the module into the RC aircraft. After power on the module behaves erratically. Does not obey the commands and powers the motor randomly.

First I thought it can be inductive parasitic signals from the relay. I changed the 100 nF capacitors to 10 μF electrolytics (I am not sure whether this is a logical and good step). But the problem persisted.
I remoed the LM2950 and supplied the circuit directly with 5.8V. The problem persisted.
I tested the circuit with a servo tester supplied with 5V and it worked fine!
These findings led me to think that there is a problem with logic levels. So I added the following circuit and changed the code to look for a negative pulse instead of a positive one. I also activated the internal pullup resistor of the corresponding microcontroller pin.

3.jpg
 
Last edited:

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
What I cannot understand is, why the exactly the same circuit board produced by myself works and why this professionally fabricated boards have problems...
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
It makes perfect sense to me. The battery voltage might be anywhere between 4.8 and 8.4V so he is using a low dropout regulator to get a known voltage for his ATTINY, probably 3.3V since you cant get 5V from 4.8 with a low dropout regulator.

Bob
Actually not 3.3V but 5 V. Because 4.8 V is meant for more beginner type aircraft. This aircraft is being supplied with 5.7 - 5.8 V.
Maybe I can use 3.3V but I am not sure whether in this case I need precautions to not exceed 3.3V at the input of the microcontroller.
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
Now some additional data.
I have forgotten to say that the circuit works with a cheap servo tester as PWM pulse generator without any problems.
I have just checked the signals with an oscilloscope.
My receiver output is a 3.3V pulse. The output of the servo tester is 4.5V!!! This finding suggests that the problem is really with logic levels but I cannot understand why there were no problems with the other projects.
 
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Using a zener on its own may cause heavy currents to flow. You'll want to add some series resistance to limit the current.

3.3V sends have very soft knees. I'd recommend a pair of diodes and a pair of resistors.

I can't draw the schematic right now. I'll try to do it in about 12 hours of nobody else has.
 

Bluejets

Oct 5, 2014
6,942
Joined
Oct 5, 2014
Messages
6,942
Are you using 2.4g system? I have seen reference to using the servo signal from these in the past, just cannot remember offhand what it was. Think I'd be double checking the commercially made boards though.
 
Last edited:

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,747
Joined
Nov 17, 2011
Messages
13,747
This is a rather simple level shifter/limiter:
upload_2017-5-30_7-3-15.png
A low input voltage (e.g. < 0.8 V) will turn on Q1 and a low signal will be present at the output to the microcontroller.
A high input voltage (>2.7 V) will turn off Q1 and a 3.3 V high signal will be present at the output. If the µC has an internal pull-up resistor, R2 may be left out.
This circuit effectively works up to an input voltage equal to base emitter reverse breakdown voltage + 3.3 V. A 2N2222 for example has a reverse base emitter breakdown voltage of 6 V, therefore this circuit will work up to 9.3 V.

Anyway, we still have no explanation why the commercially made boards fail whereas the handmade board works. Do you have access to an oscilloscope to measure the signal waveforms on both types of pcb?
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
Using a zener on its own may cause heavy currents to flow. You'll want to add some series resistance to limit the current.

3.3V sends have very soft knees. I'd recommend a pair of diodes and a pair of resistors.

I can't draw the schematic right now. I'll try to do it in about 12 hours of nobody else has.

I will of course add a series resistor to teh zener. :) Thank you...
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
Are you using 2.4g system? I have seen reference to using the servo signal from these in the past, just cannot remember offhand what it was. Think I'd be double checking the commercially made boards though.

Yes it's a 2.4 system. The 2.4 GHz receivers usually work at an internal voltage of 3.6 V and their output signals are 3.3V.
You can see the board layout in the post #8. What can be wrong with such a simple design? It is really interesting...
 

sumeryamaner

May 29, 2017
50
Joined
May 29, 2017
Messages
50
This is a rather simple level shifter/limiter:
View attachment 34323
A low input voltage (e.g. < 0.8 V) will turn on Q1 and a low signal will be present at the output to the microcontroller.
A high input voltage (>2.7 V) will turn off Q1 and a 3.3 V high signal will be present at the output. If the µC has an internal pull-up resistor, R2 may be left out.
This circuit effectively works up to an input voltage equal to base emitter reverse breakdown voltage + 3.3 V. A 2N2222 for example has a reverse base emitter breakdown voltage of 6 V, therefore this circuit will work up to 9.3 V.

Anyway, we still have no explanation why the commercially made boards fail whereas the handmade board works. Do you have access to an oscilloscope to measure the signal waveforms on both types of pcb?

At the output of the receiver there are 3 pins for each channel. Signal - positive supply - ground. Positive supply is not 3.3V but it is what the receiver gets as an input (5.7 - 5.8 V in our situation). That means I do not have access to 3.3V. My solution is different. A series resistor of 10k from the receiver signal output to the base of 2N2222. Emitter of the 2N2222 connectd to ground. Collector of 2N2222 connected to microcontroller input. Internal pullup resistor of the microcontroller activated in the software. This setup shifts the level and inverts the incoming signal. So I have changed the code to read negative pules instead of positive ones.

3.jpg
 
Top