ATTINY13A vs ATTINY45-20SU same program diffrent result?

Hi there, I'm having some trouble with my project here. I have two diffrent IC's ATTINY13A and ATTINY45-20SU.

When i load the code "program" listed in the bottom of this post... I get a diffrent outcome of the two IC's Using Arduino 1.0.6 and the correct librarys of both IC's

When i use the ATTINY13A @9.6Mhz i get a simple PIN0=PIN2 effect. When i use the ATTINY45-20SU @8Mhz i get the desired hold on PIN2 until state change on PIN0...

Anybody that can help?

int inputPin = 0;
int outputPin = 2;

int inputState = 0;
int lastinputState = 0;
int outputState = 0;

void setup()
{
  pinMode(inputPin, INPUT);
  pinMode(outputPin, OUTPUT);
}

void loop()
{
  inputState = digitalRead(inputPin);
  if (inputState != lastinputState) {
    if (inputState == 1 ) {
      if (outputState==1) outputState=0;
      else             outputState=1;
    }
    lastinputState = inputState;
  }
digitalWrite(outputPin, outputState);
delay(20);
}
int inputPin = 0;
int outputPin = 2;

int inputState = 0;
int lastinputState = 0;
int outputState = 0;

void setup()
{
  pinMode(inputPin, INPUT);
  pinMode(outputPin, OUTPUT);
}

void loop()
{
  inputState = digitalRead(inputPin);   
  if (inputState != lastinputState) {    
    if (inputState == 1 ) {
      if (outputState==1) {
          outputState=0;
      } else {
          outputState=1;
      }
    }
    lastinputState = inputState;
  }
digitalWrite(outputPin, outputState);
delay(20);
}

digitalRead() is always either 0 or 1.

I would expect this to set outputPin to whatever inputPin is set to, as long as input pin is set to something. When the input pin is allowed to float, things will become unpredictable.

I suspect that that's what was happening, and why it had an anomalous "hold" effect on the '45. Frequently in the case of a floating pin, the pin will stay at it's old value for a while; you were relying on the capacitance of a floating input. Differences in process between the two parts could explain the difference.

In a well designed circuit, unless it's an antenna, you shouldn't have inputs floating - you either pull them up to Vcc or down to Gnd with a small resistor, so when nothing is touching them, they're in a known state.

If you need an output pin to follow an input pin that can be either high, low, or "don't do anything", you could put that pin at the middle of a resistor divider between Vcc and Gnd (ie, a 10k resistor from ground to input pin, and from Vcc to input pin), and use analog read.

Well that was the point on the 45, it's supposed to hold and change state if there is a state change on PIN0.

But on the 13A i don't get that, it's like I've jumpered PIN0 and PIN2 together...

There is a 1k pulldown on PIN0, PIN2 is "floating" or rather connected directly to a MMBT2222...

And yes, it's a 1 or a 0 I'm after :)

Then it's not floating, it's connected to something...

Draw out the schematic and post it please, for both the 13 and the 4...

General schematic of what i got, it's just the same for bot the 13 and 45...

|500x358

Videos of them in action...

ATTINY13: HERE

ATTINY45: HERE

Upper LED: +5v Middle LED: Output "PIN2" Lower LED: Input "PIN0"

As stated earlier, the 45 is working as expected but not the 13. The code and schematic is the same for both.

Don't know if this will help your problem, but you need a resistor between PB2 and base of the transistor. 150 Ohms ore more. Otherwise PB2 will be shorted (almost).