Third PWM channel on ATTINY85

I am having an odd problem with an ATTINY85…I looked online and the ATTINY85 can do 3 PWM channels so I wired up a nightlight with this code:

// color swirl! connect an RGB LED to the PWM pins as indicated
// in the #defines
// public domain, enjoy!

#define REDPIN 0
#define GREENPIN 1
#define BLUEPIN 4
#define PIR A3


boolean human_detected = false;
unsigned long timer;
int r, g, b;

#define FADESPEED 5     // make this higher to slow down

void setup() {
  pinMode(PIR, INPUT);
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  analogWrite(REDPIN, 0);
  analogWrite(GREENPIN, 0);
  analogWrite(BLUEPIN, 0);
  //Serial.begin(9600);
  timer = millis();
}


void loop() {
  //Serial.print("Human detected: ");
  //Serial.println(human_detected);
  //We check the PIR sensor to see if it's on then call the 
  int sensor_status = digitalRead(PIR);
  //Serial.print("PIR Reading: ");
  //Serial.println(sensor_status);
  if (sensor_status == 1) {
    human_detected = true;
    timer = millis();
  }

  if (human_detected) {
    //Fade red
    for (r = 0; r < 256; r++) { 
      analogWrite(REDPIN, r);
      delay(FADESPEED);
    }
    for (r = 256; r > 0; r--) {
      analogWrite(REDPIN, r);
      delay(FADESPEED);
    }
    analogWrite(GREENPIN, 0);
    analogWrite(BLUEPIN,0);
    analogWrite(REDPIN,0);
    
    //Fade green
    for (g = 0; g < 256; g++) { 
      analogWrite(GREENPIN, g);
      delay(FADESPEED);
    }
    for (g = 256; g > 0; g--) {
      analogWrite(GREENPIN, g);
      delay(FADESPEED);
    }
    analogWrite(GREENPIN, 0);
    analogWrite(BLUEPIN,0);
    analogWrite(REDPIN,0);

    //Fade blue
    for (b = 0; b < 256; b++) { 
      analogWrite(BLUEPIN, b);
      delay(FADESPEED);
    }
    for (b = 256; b > 0; b--) {
      analogWrite(BLUEPIN, b);
      delay(FADESPEED);
    }
    analogWrite(GREENPIN, 0);
    analogWrite(BLUEPIN,0);
    analogWrite(REDPIN,0);
  }

  if (millis() - timer > 5000){
    human_detected = false;
    analogWrite(GREENPIN, 0);
    analogWrite(BLUEPIN,0);
    analogWrite(REDPIN,0);

  } 
}

The issue I am having is that the blue channel doesn’t PWM at all. After everything goes dark after the green fade, there’s a split second pause and then blue turns on for a short period and goes off…It doesn’t alter the brightness at all. Can someone point me in the right direction?

Sounds like a problem with your Tiny85 core files or something like that.

Write a minimal program to just fade the blue pin, see if that works. If it doesn't, reinstall your Tiny85 files.

did you set the fuse for the 3rd channel ?

it defaults to the reset.

once you change the fuse setting you can only re-program with a high voltage programmer.

Since I don't have a high voltage programmer and for my practical purposes it's a one way operation I have not changed any fuses, not until I get my nightlight working the way I want. I'll keep reading my MAKE book until I learn more. I was hoping it would not have to make a permanent change like that yet

The Digispark tiny85 uses the Bluebie boot loader and is designed to be programmed without the need of reset. Therefore, you can get 3 PWM and reprogram too.

Ray

Build your own: http://www.hackster.io/rayburne/trinket-firmware-exorcism

dave-in-nj:
did you set the fuse for the 3rd channel ?
it defaults to the reset.
once you change the fuse setting you can only re-program with a high voltage programmer.

Wow. You are seriously full of shit. A quick check of the datasheet reveals the RESET pin is marked with…

PCINT5 - Pin Change Interrupt #5
RESET - obvious
ADC0 - Analog-to-Digital Converter channel #0
dW - Debug Wire
PB5 - pin designation

No Output Compare mark which means the RESET pin cannot possibly support hardware driven pulse width modulation no matter what is done with the fuses.

psychephylax: The issue I am having is that the blue channel doesn't PWM at all. After everything goes dark after the green fade, there's a split second pause and then blue turns on for a short period and goes off...It doesn't alter the brightness at all. Can someone point me in the right direction?

Use this core... http://code.google.com/p/arduino-tiny/

PWM is supported on digital pins 0, 1, and 4.

Wow. You are seriously full of...

OMG! I really must stop drinking coffee and reading these posts :D Another coffee spew ... coffee does seem to clean the keyboard fairly well / Hopefully the moisture seal in the keyboard is working ! No matter though, I can buy another PC, but this humor is priceless!

Ray

[quote author=Coding Badly link=topic=234848.msg1692240#msg1692240 date=1398232446]

psychephylax: The issue I am having is that the blue channel doesn't PWM at all. After everything goes dark after the green fade, there's a split second pause and then blue turns on for a short period and goes off...It doesn't alter the brightness at all. Can someone point me in the right direction?

Use this core... http://code.google.com/p/arduino-tiny/

PWM is supported on digital pins 0, 1, and 4.

[/quote]

Thank you for the link, I actually installed this core on my laptop and tried flashing the ATTINY85 with my code but it didn't even light up the LED strip. There are a few options in the board menu for ATTINY85 and I'm not quite sure which one to go with. The one thing I did was change the internal clock to 8 MHz so I went with the 8MHz option with internal oscillator and BOD disabled. I will try again and report back

psychephylax: There are a few options in the board menu for ATTINY85 and I'm not quite sure which one to go with.

Probably won't make much difference other than do not use the "external crystal" option.

The one thing I did was change the internal clock to 8 MHz so I went with the 8MHz option with internal oscillator and BOD disabled.

Did you execute Tools / Burn Bootloader after changing the board selection?

I used a different core available from the MIT website http://highlowtech.org/?p=1695

I followed their instructions for toggling the clock and did burn the bootloader....Does this process have to be followed for a different core?

Does this process have to be followed for a different core?

Wouldn't hurt.

Thanks! I was able to get it to mostly work (At least the PWM functionality)
I had to strip almost all the PIR and other code out to be able to test 3 channel PWM

#define REDPIN 0
#define GREENPIN 1
#define BLUEPIN 4
#define PIR 3


boolean human_detected = false;
unsigned long timer;
int r, g, b;

#define FADESPEED 10     // make this higher to slow down

void setup() {
  pinMode(PIR, INPUT);
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  analogWrite(REDPIN, 0);
  analogWrite(GREENPIN, 0);
  analogWrite(BLUEPIN, 0);
}


void loop() {

    for (r = 0; r < 255; r++) { 
      analogWrite(REDPIN, r);
      analogWrite(GREENPIN, r);
      analogWrite(BLUEPIN, r);
      delay(FADESPEED);
    }
}