1. 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.
    Dismiss Notice

How to keep ATTINY85 digital pins at start LOW?

Discussion in 'AVR' started by ozgur84, Feb 8, 2014.

  1. ozgur84

    ozgur84 Member

    Joined:
    Feb 8, 2013
    Messages:
    72
    Likes:
    5
    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
     
  2. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,964
    Likes:
    1,099
    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.
     
    • Like Like x 1
  3. ozgur84

    ozgur84 Member

    Joined:
    Feb 8, 2013
    Messages:
    72
    Likes:
    5
    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?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland

    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.
     
    • Like Like x 1
  6. ozgur84

    ozgur84 Member

    Joined:
    Feb 8, 2013
    Messages:
    72
    Likes:
    5
    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
     
  7. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,964
    Likes:
    1,099
    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,
     
  8. ozgur84

    ozgur84 Member

    Joined:
    Feb 8, 2013
    Messages:
    72
    Likes:
    5
    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 http://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 :)
     

Share This Page