Allow Alternative Timer

Issue #29 resolved
LemonPi created an issue

I'm using a motor shield that uses pins 10-13. I can't change these pins. NewPing uses Timer2, which uses pin 11.

I'm currently modifying the source to allow ifdef to switch to Timer4 (as if I have AVR_ATmega32U4 defined). I propose for there to be a more semantic way of switching between timers, such as a NEWPING_USE_TIMER_4 define.

Comments (6)

  1. Tim Eckel repo owner

    NewPing already uses timer 4 with the ATmega32U4. There's no reason to change anything. Also, NewPing only uses a timer if you're using the ping_timer() method, the standard ping methods don't use timers at all.

    Tim

  2. LemonPi reporter

    It uses timer 4 with ATmega32, but there's no option to use Timer4 for the 2560. It's non-trivial because timer 2 is 8 bits wide while timer 4 is 16 bits wide for the 2560.

    I'm suggesting to allow users to select which timer to use regardless of platform.

    I need to use ping_timer to prevent blocking in my main loop for calculation and other sensor data acquisition.

  3. Tim Eckel repo owner

    Timer 4 is not available on all ATmega microcontrollers. A better solution is to use a motor controller that uses an I2C interface as there's so few timers available on some ATmega microcontrollers.

  4. LemonPi reporter

    Yes that'd be the ideal case. I ended up ditching the motor shield for an H-bridge breakout board.

  5. Log in to comment