![]() External clock source on T4 pin (D47). TIMSK5 = _BV (TOIE1) // interrupt on Timer 5 overflow So this works: // Timer and Counter example for Mega2560 OK, Timer 5 is connected to an external pin (D47 at the end). ![]() ![]() I've marked important pin names like OC1A, RX, MISO etc ARDUINO MEGA:Ģ6 B7 OC0A,OC1C X 13 Arduino code ignorant of OC1CĤ0 L5 OC5C X 44 note OC5C not supported by analogWrite. For some crazy reason the code tagged text isn't coming out in a fixed-width font alas. Note that "pack" means the package pin numbers, not Arduino pin numbers which are in the final column. My shorthand list of pin outs (which may have mistakes, note) is given below. The pin assignments for the Mega are given in the relevant datasheet. adjust counts by counting interval to give frequency in Hzįloat frq = (timerCounts * 1000.0) / timerPeriod StartCounting (500) // how many mS to count for TimerCounts = (overflowCount << 16) + timer1CounterValue // each overflow is 65536 moreĬounterReady = true // set global flag for end count period Timer1CounterValue = TCNT1 // see datasheet, page 117 (accessing 16-bit registers) grab counter value before it changes any more Timer2 Interrupt Service is invoked by hardware Timer 2 every 1ms = 1000 Hz ++overflowCount // count number of Counter1 overflows GTCCR = _BV (PSRASY) // reset prescaler now TIMSK2 = _BV (OCIE2A) // enable Timer2 Interrupt OCR2A = 124 // count up to 125 (zero relative!!!!) So we count 125 of them, giving exactly 1000 uS (1 mS) 16 MHz clock (62.5 nS per tick) - prescaled by 128 Timer 2 - gives us our 1 mS counting interval TIMSK1 = _BV (TOIE1) // interrupt on Timer 1 overflow TimerTicks = 0 // reset interrupt counter TimerPeriod = ms // how many 1 mS counts to do these are checked for in the main program PS: This might help: // Timer and Counter example This is the sketch I am talking ying to decipher the pins for the compiles on the mega with no errors.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |