Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to keep ATTINY85 digital pins at start LOW?

Status
Not open for further replies.

ozgur84

Member
Hello all,

I have a question about ATTINY85 also related to the Arduino. I have a circuit which keeps all the pins at start HIGH for about a second, even though I wrote in the sketch, in void_loop part, that to write the output pins low. Is this a normal behavior of all atmel microcontrollers? and is there a way to prevent it to turn the pins high at the start?

Regards,
Oz
 
Specifically, I won;t comment directly on your problem, but the convention was to configure "CPU Pins" as inputs on power up.

It does cause grief sometimes. The ULN200x drivers eliminated the problem because at high Z, the driver was off, at low it was OFF and at high it was ON. Tack on a conventional TTL gate and it the input floats high, so very strange behavior on power up. Look at the the enabled pull-ups and pull downs at power up, Having a pin power up as an input is usually safer.

What it's actually doing may surprise you.
 
Specifically, I won;t comment directly on your problem, but the convention was to configure "CPU Pins" as inputs on power up.

It does cause grief sometimes. The ULN200x drivers eliminated the problem because at high Z, the driver was off, at low it was OFF and at high it was ON. Tack on a conventional TTL gate and it the input floats high, so very strange behavior on power up. Look at the the enabled pull-ups and pull downs at power up, Having a pin power up as an input is usually safer.

What it's actually doing may surprise you.

Even though some parts of your answer exceed my knowledge, thanks :) my best bet is: the problem might be about the bootloader of arduino and consequently ATTINY, because I use the ardunio as the programmer for ATTINY. I suppose, in this case there is no option for me to write a bootloader or change it. I will keep looking for the answer...

For the pull-up part: if I sink all the digital pins with resistors to the ground, wouldn't they be going on drawing some extra current from the microcontroller?
 
and is there a way to prevent it to turn the pins high at the start?

AVR I/O pins are input by default. If the pins go high on reset then there is something external driving them high. Or, you have code that is setting them high.
 
AVR I/O pins are input by default. If the pins go high on reset then there is something external driving them high. Or, you have code that is setting them high.

Thanks, I might have solved the issue by mistake :) I somehow skipped the "one change at a time" rule and after I uploaded the code to the ATTINY, I have seen that, it no longer set the pins high at the boot! :)

Regards,
Oz
 
ozgur24 said:
For the pull-up part: if I sink all the digital pins with resistors to the ground, wouldn't they be going on drawing some extra current from the microcontroller?

That's an important part to remember, but it only gets you sometimes. Any CMOS gate, you have to look at it to figure out what results in the lowest power dissipation if power dissipation matters, sometimes Vcc, sometimes ground and sometimes through a resistor.

It's good that you realize this,
 
That's an important part to remember, but it only gets you sometimes. Any CMOS gate, you have to look at it to figure out what results in the lowest power dissipation if power dissipation matters, sometimes Vcc, sometimes ground and sometimes through a resistor.

It's good that you realize this,

Luckily, I did not need the resistors because I found the source of the problem. As a simple description (the initial code is in the link)

At first, I had three function voids which turns on and off some pins to control LEDs and Fan in every individual function, and I used to recalls the functions in setup void of Arduino sketch. What I mean

void_setup
some pinMode() stuff here
function 1
function 2 ....

then comes the void loop
and finaly the

void_function x

I realized that, as soon as I deleted the function names from the void_setup part, the code started working not perfectly but close to what I expected. Finaly, I removed the function voids and merged the digitalWrite syntaxes into the if structures. After some fine tuning and addition of a capacitor parallel to the fan, it works flawlessly :)

the initial code and the circuit can be seen here https://www.electro-tech-online.com...ure-controller-with-attiny85-and-lm35.139997/

and the final code is

#define analogPin 3 // Data cable connected to the analog pin
#define YelPin 1 // yellow LED pin for Temp>33
#define RedPin 0 //red LED pin for Temp>42
#define FanPin 2 //Fan connected to the MOSFET will be high Temp>37
float val=0; // variable to store the value read

void setup(){
pinMode(YelPin, OUTPUT);
pinMode(RedPin, OUTPUT);
pinMode(FanPin, OUTPUT);
}

void loop(){
float val=0;
val = analogRead(analogPin)*0.48828125;

if(val<33){
digitalWrite(YelPin, LOW);
digitalWrite(FanPin,LOW);
digitalWrite(RedPin, LOW);
delay(500);}

if(val>=33 && val<42){
digitalWrite(YelPin, HIGH);
digitalWrite(FanPin,HIGH);
digitalWrite(RedPin, LOW);
delay(500); }

if(val>=42 && val<=70){
digitalWrite(YelPin, LOW);
digitalWrite(FanPin,HIGH);
digitalWrite(RedPin, HIGH);
delay(500);}

}


As a result, as your nickname, I kept the code stupidly simple instead of adventuring with function loops :)
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top