3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

arduinoでtimer5

Posted at

概要

arduino megaでtimer5をctcモードで使って見た。
クロック16MHzなので、プリスケーラ1024、15625カウントで1秒。

写真

ctc.JPG

サンプルコード

volatile int sec1 = 0;
volatile int sec2 = 0;
volatile int sec3 = 0;
ISR(TIMER5_COMPA_vect)
{
	sec1++;
}
ISR(TIMER5_COMPB_vect)
{
	sec2++;
}
ISR(TIMER5_COMPC_vect)
{
	sec3++;
}
void setup()
{
	Serial.begin(115200);
	TCCR5A = 0;
	TCCR5B = 0;
	TCCR5B |= (1 << WGM52);
	TCCR5B |= (1 << CS52) | (1 << CS50);
	TCNT5 = 0;
	OCR5A = 15624;
	OCR5B = 15624;
	OCR5C = 15624;
	TIMSK5 = 0;
	TIMSK5 |= (1 << OCIE5A);
	TIMSK5 |= (1 << OCIE5B);
	TIMSK5 |= (1 << OCIE5C);
}
void loop()
{
	int a1;
	int a2;
	int a3;
	long b;
	a1 = sec1;
	a2 = sec2;
	a3 = sec3;
	b = millis();
	Serial.print(a1);
	Serial.print("\t");
	Serial.print(a2);
	Serial.print("\t");
	Serial.print(a3);
	Serial.print("\t");
	Serial.println(b);
	delay(1000);
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?