So I am having a little problem with a interrupt based timer I am trying to implement. My interrupt vector is:
ISR(TIMER0_COMPA_vect) { milsec++; if(milsec == 1000) { buzz_stim++; milsec = 0; } }
with the code block where this is used:
void buzzer_short() { millis_timer(1); buzz_interval = buzz_stim; sbi(PORTB,7); interval_diff = buzz_interval - buzz_stim; if (interval_diff > 2) { cbi(PORTB,7); } }
buzzer_short() is called out through out my program and I am trying to used it for a piezo buzzer, so when it's time for it to be called the buzzer sounds for a second or two and the turns off. I know the issue with my code is that buzz_interval is basically always equal to buzz_stim so the interval_diff is always zero. Being that I am still honing my coding skills, I'm just not sure how to write where every time this block is called, buzz_interval resets and doesn't reset until it's called next. Thanks!
P.S. This is based off of a millisecond timer
void millis_timer(uint8_t millis) { TCCR0A |= (1<<WGM01); TCCR0B |= (1<<CS02)|(1<<CS00); OCR0A = millis*7.815 - 1; TIMSK0 |= (1<<OCIE0A); sei(); }