blh64
4
volatile uint32_t ul_contador = 0;
#define pulsador 5
void setup()
{
pinMode(pulsador, INPUT);
DDRB |= (1 << DDB2);
InitPWM1();
}
void loop() {
}
void InitPWM1() {
cli();
OCR1A = 2500; //64 Preescaler
OCR1B = 250;
TCCR1B |= (1 << WGM12) | (1 << WGM13);
TCCR1A |= (1 << WGM10) | (1 << WGM11);
//Timer 1 Preescaler 1
TCCR1B &= ~(1 << CS12);
TCCR1B |= (1 << CS11);
TCCR1B |= (1 << CS10);
TCCR1A |= (1 << COM1B1);
TCCR1A &= ~ (1 << COM1B0);
TIMSK1 |= (1 << OCIE1A);
sei();
}
ISR(TIMER1_COMPA_vect) {
static byte step = 1;
ul_contador++;
if (ul_contador >= 400) {
step++;
OCR1B += 250;
ul_contador = 0;
if ( step >= 10 ) {
step = 1;
OCR1B = 250;
}
TCNT1 = 0;
}
}