This is my first post on this forum but reading this whole post I think you could help me with a problem I have found with attiny85.
I have finished a project with Arduino UNO that involves ac light dimming at 220v. Using the atmega328 is a good option if we want to handle several light points but for smaller projects I tought it ould be ideal to use attiny85.
However the code doesn´t seem to run with attiny85. The program should gradually dim the light in a from lowest to high brightness and redo the cyle in a loop. This is what it succesfully does using the code in Arduino; with attiny85 the code just gets to dim the light slightly while flashing (seems out of sync).
The code is using external interrupt in order to find the zero cross of the Ac wave. I am using attachInterrupt and I am wondering whether the problem is that interrupts(with delay as in my case to achieve the dimming) cannot be used with attiny85 without altering the register. I have got to this thought because I have already finished a dimmer with attiny but this one is with PWM control to dim one LED using, for which we do not use interrupts and I thought the interrupts an be the source of the problem in my new project.
Maybe an internal timer needs to be set up to get it in sync? I have read in your posts that this shouldn´t be necessary and that attachInterrupt can be used on exactly the same way as for Arduino but I don´t seem to manage it.
I will appreciate any help you can give me. I am quite new to Arduino and attiny and I have searched for Ac dimmer tuttorials but I can´t find any answers to this topic.
Thanks!!
This is the code I am using:
int t; //tiempo de dimmer
int i;
int AC_LOAD = 1; // Output to Opto Triac pin
int dimming = 128; // Dimming level (2-128) 2= ON, 128 = OFF
void setup()
{
t=200;
pinMode(AC_LOAD, OUTPUT); // Set the AC Load as output
attachInterrupt(0, zero_crosss_int, RISING); // Choose the zero cross interrupt # from the table above
}
void zero_crosss_int() // function to be fired at the zero crossing to dim the light
{
// Firing angle calculation :: 50Hz-> 10ms (1/2 Cycle)
// (10000us - 10us) / 128 = 75 (Approx)
int dimtime = (75*dimming);
delayMicroseconds(dimtime); // Off cycle
digitalWrite(AC_LOAD, HIGH); // triac firing
delayMicroseconds(10); // triac On propogation delay
digitalWrite(AC_LOAD, LOW); // triac Off
}
void loop()
{
for (int i=95; i>=2; i--)
{
dimming = i;
delay (t);
}
for (int i=2; i<=95; i++) //donde 2 es el valor alto
{
dimming = i;
delay (t);
}
}
You implied that running similar code on your Uno worked. A good first step would be to change the t85 so it runs closer to the same speed as your Uno. I suggest you change the t85 to run at 8 MHz or 16 MHz.
That's correct. The code works on Arduino. I have already tried running it on attiny85 at 8MHz and still doesn't work. Trying with 16mhz would not be possible because the board doesn't allow a 16MHz crystal. I would need to use a 20MHz crystal and I am reluctant to do this. I am trying to avoid crystals to save in consumption. Any ideas? Thanks for your help so far!
Sorry, I didn´t explain myself clearly on my last post. I have uploaded the Attiny boards into the Arduino environment but the only internal clocks I have avilable are 1 and 8 MHz. From there we move to 20MHz external. Am I missing the internal 16MHz clock board?
I did some research after your answers and I did find the core you just suggested! I was about to write that I had found it and was going to try with it; so, that´s what I am about to do. I will let you know how it goes!
Loaded the Arduino ISP sketch into Arduino UNO board
Swapped to Attiny 85 @ 16MHZ (Internal PLL 4.3 V BOD), which now does appear in my board list and did all required wire connections.
Set Programmer to 'Arduino as ISP'
Ran my Light dimming code but it didn´t work. Still the dimming was very poor as the light flashed at low speed.
At this point I was a bit dissapointed and too tired to continue.So, I left for work this morning and my boyfriend couldn't wait for me getting back home and did the following:
Realized we hadn´t burnt the bootloader so he did that.
Ran our Light dimming code ---> Success!!! Now it works exactly the same as the code did on Arduino Uno Board!
Thank you so much for your replies, support and help. We will be recording a tutorial of the whole project and I will post the link shortly as we think it may be something interesting for other.
Again thanks and speak to you soon! I love happy endings