I am working on a regulator for a bench grinder. I have made all the hardware, sensors, etc...
And have even put together a working prototype using Arduino Duemillanove clone:
I am using a homemade optointerrupter (IR phototransistor/diode couple with LM358 as a comparator with hysteresis) to read the speed of the wheel optically. SO! I need a frequency measurment.
BUT! Now I am trying to make it standalone. I wanted to just throw in this neat little Attiny85 board I found in my drawer, since using pro mini seems like an overkill.
This meant rewriting my code to use different timers. But I can't get the timers to work at all!
I have since reduced my code to an absolute minimum, and it still isn't really working.
What it should do: BLINK THE DARN LED
What it does: THE LED DOESN'T TURN ON
What it drives me: CRAZY
Aaaand by the time I have finished this post, I managed to debug it; bug noted in code:
#include <util/delay.h>
volatile unsigned int lastPeriod = 0;
volatile byte slepice=false;
void setup() {
// put your setup code here, to run once:
//reset our counter
// resetCounter();
TCCR0A = 0;//No pwm, no port manipulation, no nothing
TCCR0B=0; //THIS IS THE LINE I NEEDED TO ADD TO FIX EVERYTHING! Apparently, CS01 bit of TCCR0B was set. Make sure to always check the status of your registers, kids!
TCCR0B |= (1 << CS02);
TCCR0B |= (1 << CS00); //system clock, 1024 prescaler
pinMode(1, OUTPUT);
TIMSK |= (1 << TOIE0); //enable Timer0 overflow interrupt
sei();
}
void loop() {
}
ISR(TIMER0_OVF_vect)
{
slepice=!slepice;
digitalWrite(1, slepice);
}