Skip to content

Instantly share code, notes, and snippets.

@joaoantoniocardoso
Last active August 22, 2018 00:23
Show Gist options
  • Save joaoantoniocardoso/6b85148e8a03cdec7e4e58aeb7a65b1e to your computer and use it in GitHub Desktop.
Save joaoantoniocardoso/6b85148e8a03cdec7e4e58aeb7a65b1e to your computer and use it in GitHub Desktop.
uint8_t machine_clk = 0;
void machine_init(void)
{
TCCR2A = (1 << WGM21) | (0 << WGM20) // Timer 2 in Mode 2 = CTC (clear on compar e)
| (0 << COM2A1) | (0 << COM2A0) // do nothing with OC2A
| (0 << COM2B1) | (0 << COM2B0); // do nothing with OC2B
TCCR2B = (0 << WGM22) // Timer 0 in Mode 2 = CTC (clear on compar e)
| (0 << FOC0A) | (0 << FOC0B) // dont force outputs
| (1 << CS22) // clock enabled, prescaller = 1024
| (1 << CS21)
| (1 << CS20);
OCR2A = 240; // Comrapre A value for 150hz?
TIMSK2 |= (1 << OCIE2A); // Activates TIMER2_COMPA_vect ISR
}
ISR(TIMER2_COMPA_vect)
{
machine_clk = 1;
}
void main(void)
{
machine_init();
sei();
for(;;){
if(machine_clk){
machine_clk = 0;
// CODE HERE
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment