blinking brake lights for RC cars not working in ATtiny45

Hi,

I have made a code for blinking brake lights.

The code works fine with my ATmega1280 as can be seen here:

When I upload the code in an ATtiny45 it doesn't work. When the transmitter is off the led slowly blinks and when I turn the transmitter on the led just fades and does nothing.
When the transmitter is turned on again the led starts blinking slowly again.

Here's the code:

const int ledPin = 0;                      // number of the LED pin

int ledState = LOW;
int t;
int x;
int y;
int z;

long previousMillis = 0;                     // will store last time LED was updated

                                             // the follow variables is a long because the time, measured in miliseconds,
                                             // will quickly become a bigger number than can be stored in an int.
long interval = 100;                         // interval at which to blink (milliseconds)

void setup() {
  pinMode(ledPin, OUTPUT);                   // set the digital pin as output:
  t = 0;
  z = 1400;
}

void loop()
{
  y = pulseIn(1, HIGH);                      // read PPM signal on ch.2 from receiver
    if(y > z){
      x = 1;
    }
    else
    if(y <= z){
      x = 0;
    }

unsigned long currentMillis = millis();
 
 if(x == 0 && t == 0){
   previousMillis = currentMillis;
   ledState = HIGH;
   digitalWrite(ledPin, ledState);
   t = 1;
 }
 
if(x == 0 && t == 1 && currentMillis - previousMillis > interval && ledState == HIGH){
  previousMillis = currentMillis;
  ledState = LOW;
  digitalWrite(ledPin, ledState);
}

if(x == 0 && t == 1 && currentMillis - previousMillis > interval && ledState == LOW){
  previousMillis = currentMillis;
  ledState = HIGH;
  digitalWrite(ledPin, ledState);
}

if(x == 1 && t == 1){
  t = 0;
  if(ledState == HIGH){
    ledState = LOW;
    digitalWrite(ledPin, ledState);
  }
}
}

What am I doing wrong?

Leo

Hi,

First, some general things...

unsigned long previousMillis = 0; // will store last time LED was updated

static const unsigned long interval = 100; // interval at which to blink (milliseconds)

Now to the problem... What is the ATtiny45 processor speed?

Hi,

It should be 8MHz because I "burned" the bootloader.

The most likely culprit is internal oscillator. The ±10% that Atmel guarantees may be too much for your application to function correctly. You can either fiddle with the threshold (z) or tune the oscillator.