![]() ![]() When I compile, it gives me an error saying that amp was not declared. Empty, but needed to avoid linker errors */ * Write to a digital pin so that we can confirm our timer */ĭigitalWrite(2, toggle = 0 ? HIGH : LOW) * interrupt vector table but conveniently done by using ISR() */ * This is normally done by writing the address of the ISR in the * Install the Interrupt Service Routine (ISR) for Timer2 overflow. * Save value globally for later reload in ISR */ * (CPU frequency) / (prescaler value) = 125000 Hz = 8us. * The following loads the value 131 into the Timer 2 counter register * We need to calculate a proper value to load the timer counter. * Now configure the prescaler to CPU clock divided by 128 */ * Disable Compare Match A interrupt enable (only want overflow) */ * Select clock source: internal I/O clock */ * Configure timer2 in normal mode (pure counting, no PWM etc.) */ * First disable the timer overflow interrupt while we're configuring */ * Setup phase: configure and enable timer2 overflow interrupt */ * Timer2 reload value, globally available */ * For detailed information on Timer2 configuration see chapter 17 in * example will run the function every 1ms. * defined function (Interrupt service routine) using Timer2. * Example on how to configure the periodical execution of a user I know I could just use an external interrupt controlled by a comparator but I would like to avoid electrical components if possible, plus, this way I can have a calibration period so that the threshold doesn't need to be manually set by a potentiometer. I have a robot that drives pretty fast but also needs to sense objects and control a servo if a threshold is met. I am trying to get an interrupt timer to work so that I can multitask. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |