Go Down

Topic: ATTINY44 RGB flashing really fast instead of fading [Solved] (Read 122 times) previous topic - next topic

samlf3rd

Jan 23, 2015, 06:21 pm Last Edit: Jan 23, 2015, 07:09 pm by samlf3rd Reason: Solved
Hello,
I just got an ATTINY44 chip (556-ATTINY44-20PU 20Mhz) and I programmed it with a simple RGB fade rainbow effect. When I hook it up (after uploading the code through Arduino as isp) the RGB bulb flashes really fast and doesn't fade at all.
I selected the board "ATTINY44 20Mhz". Used Arduino as ISP. I did not burn bootloader... Do I need to? I have read a few things that I need to make it run at 8Mhz-is this relevant to me?
Can this be due to the 20mhz not matching up with my code? I am really new to this. Please don't tell me I can't use this chip to do a simple led rainbow fade through PWM...
The code works perfect on my Arduino just not when uploaded into the chip.

Code: [Select]
int pin1 = 5;
int pin2 = 6;
int pin3 = 7;

long value3;
long value2;
long value1;

long current_value3;
long current_value2;
long current_value1;
int x;
void setup(){

 randomSeed(analogRead(0));

value1 = random(255);
current_value1 = value1;
value2 = random(255);
current_value2 = value2;
value3 = random(255);
current_value3 = value3;

analogWrite(pin1, current_value1);
analogWrite(pin2, current_value2);
analogWrite(pin3, current_value3);

value1 = random(255);
value2 = random(255);
value3 = random(255);
}

void loop(){
x = random(5, 7);
 
if (value1 > current_value1){
 
 current_value1++;
 analogWrite(pin1, current_value1);
 delay(x);
}
 
if (value1 < current_value1){

current_value1--;
analogWrite(pin1, current_value1);
delay(x);
 
}

if (value1 == current_value1){

analogWrite(pin1, current_value1);
value1 = random(255);
 
}
 
 
 
 //////////////////////////
 
 if (value2 > current_value2){
 
 current_value2++;
 analogWrite(pin2, current_value2);
 delay(x);
}
 
if (value2 < current_value2){

current_value2--;
analogWrite(pin2, current_value2);
delay(x);
 
}

if (value2 == current_value2){

analogWrite(pin2, current_value2);
value2 = random(255);
 
}




///////////////////////////////



if (value3 > current_value3){
 
 current_value3++;
 analogWrite(pin3, current_value3);
 delay(x);
}
 
if (value3 < current_value3){

current_value3--;
analogWrite(pin3, current_value3);
delay(x);
 
}

if (value3 == current_value3){

analogWrite(pin3, current_value3);
value3 = random(255);
 
}
}

samlf3rd

#1
Jan 23, 2015, 07:08 pm Last Edit: Jan 23, 2015, 07:17 pm by samlf3rd
Okay I got it! I had the board set to 20Mhz, so I tried 8Mhz and the pulsing seemed slower, so then I figured if PWM works by pulsing at a rate that the human eye cannot see I will go to 1Mhz and Viola! Yeah!
Solved!!!

What I don't get is how it runs at 1Mhz if my chip is a 20Mhz?

Tom Carpenter

Why? because if you didn't use the 'Burn Bootloader' (which in the case of ATTiny's is badly named, it should be 'Set Fuses'), the chip will default to 'Internal Oscillator @ 1MHz'. So if you select 20MHz without setting the fuses then all of your delays will be 1/20th of what they should be - so your fade will happen 20x faster, so fast that you probably can't see it fading.

Do you have a 20MHz crystal attached to the chip? The 20MHz in the part number simply says that it is capable of running that fast, you need to attach a 20MHz clock source and set the correct fuses in order to get it to run that fast.
~Tom~

DrAzzy

Yeah - you can run it at 8 mhz without a crystal, and that's what most people do to save on parts, because faster speeds require external crystal (or external clock source), and for what most of us do with Tiny's, that's plenty. Hell, 1mhz (the default - 8mhz internal RC oscillator divided by 8 with CKDIV fuse) is often enough :-P

Don't do "burn bootloader" with something other than 8mhz or 1mhz selected, unless you've connected an external crystal. If you 'burn bootloader' with the higher speed selected, it will set the fuses to use an external crystal - and if you don't have one, you can't do anything to the chip until you connect one (chip will not respond to ICSP).
Tiny841 Core: http://drazzy.com/e/tiny851.shtml
Please don't PM me questions or responses to my posts. I am unlikely to see or read them.

Coding Badly

Quote
...and if you don't have one, you can't do anything to the chip until you connect one (chip will not respond to ICSP).
Any reasonable clock signal on XTAL1 will get the processor to respond to serial programming.


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy