Arduino-Timer-Conflicts-Considerations

From ArduinoInfo
Jump to: navigation, search

Arduino-Timer-Conflicts-Considerations


NOTES for Dr. Bear:

https://code.google.com/p/arduino/wiki/HardwareResourceMap (From Arduino)
http://forum.arduino.cc/index.php/topic,21975.0.html (Possible alternate servo library)
http://forum.arduino.cc/index.php/topic,21975.0.html (ServoTimer2 Inf)
http://letsmakerobots.com/node/35314 (discussion of Ultrasonic conflicts)
http://forum.arduino.cc/index.php?topic=106043.msg1312639#msg1312639 (Fix for NewPing?)


This is the Very Beginning of documenting the Arduino Timers, Timer Conflicts, solutions and other considerations. Several people on the Arduino forums are contributing to this (Discussion HERE).

Anyone who has something to contribute or correct:


ARDUINO RESOURCES THAT NEED TO BE MANAGED

  1. Hardware Timers (0,1,2 on Arduino UNO, Duemilanove, etc)
  2. SKETCH Memory:
    1. FLASH (Sketch code space)
    2. RAM (Sketch variable space, stack etc)
    3. EPROM (NonVolatile Memory)
  3. I/O Pins
  4. PROTOCOL-SPECIFIC:
    1. SPI CS pin
    2. SPI Mode
    3. I2C Device Addresses
    4. I2C (?Speed?)
  5. INTERRUPT DISABLE DURATION
  6.  ?
  7.  ?
  8.  ?


QUESTIONS TO ASK OF LIBRARY CONTRIBUTORS??

  1. What Timer(s) Does the library use?
    1. Does it change the Timer Mode or Frequency?
  2. If it uses SPI:
    1. What pin is used for CS?
    2. Can the CS pin be changed? How?
  3. If it uses I2C
    1. What device addresses are used?
    2. Are there I2C Speed considerations?
  4.  ?
  5.  ?
  6.  ?

STANDARD ARDUINO LIBRARIES

LIBRARY NAME
LIBRARY FUNCTION
TIMER(S) USED













EEPROM
reading and writing to"permanent" storage










Ethernet
for connecting to the internet using the
Arduino Ethernet Shield








Firmata
for communicating with applications on the
computer using a standard serial protocol.






GSM
for connecting to a GSM/GRPS network
with the GSM shield.









LiquidCrystal
for controlling liquid crystal displays (LCDs)










SD
for reading and writing SD cards











Servo
for controlling servo motors












SPI
for communicating with devices using the
Serial Peripheral Interface (SPI) Bus







SoftwareSerial
for serial communication on any digital pins.
Version 1.0 and later of Arduino incorporate
Mikal Hart's NewSoftSerial library
as SoftwareSerial.




Stepper
for controlling stepper motors











TFT
for drawing text , images,
and shapes on the Arduino TFT screen








WiFi
for connecting to the internet
using the Arduino WiFi shield









Wire
Two Wire Interface (TWI/I2C)
for sending and receiving data over
a net of devices or sensors.








TABLE of Arduino Supplied Libraries use of Timers:

Arduino Library

Timer Used

/*---( Comments )---*/

Alternatives


delay,millis, micros
0



PWM Pins 5, 6
0



Servo
1



PWM Pins 9,10
1



PWM Pins 3,11
2



Tone
 ?









































FROM  https://code.google.com/p/arduino/wiki/HardwareResourceMap</span>

Global timer settings

  • TIMER0, TIMER1, TIMER2: prescale factor = 64
  • On all chips other than ATMEGA8: TIMER0 in fast PWM mode
  • TIMER1, TIMER2 in 8-bit phase correct PWM mode
  • On ATMEGA1280:
    • TIMER3, TIMER4, TIMER5 prescale factor = 64
    • TIMER3, TIMER4, TIMER5 in 8-bit phase correct PWM mode

analogWrite();

  • Pins 5, 6 uses TIMER0
  • Pins 9, 10: uses TIMER1
  • Pins 3, 11 uses TIMER2

millis();

  • TIMER0_OVF_vect

micros();

  • TIMER0_OVF_vect

delay();

  • TIMER0_OVF_vect (via millis())

delayMicroseconds();

  • Turns off all interrupts while it's running

ARDUINO LIBRARY RESOURCES:
Liquid Crystal:
  • Uses delayMicroseconds() in most functions, so will disable interrupts frequently

Servo:

  • ATMEGA8, 168, 328:
    • Uses TIMER1_COMPA_vect
    • Sets the prescale factor = 8 (normally = 64)
    • Uses OCR1A

Software Serial:

  • Uses delayMicroseconds() in most functions, so will disable interrupts frequent

Stepper:

  • uses TIMER0_OVF_vect via millis() function

CONTRIBUTED LIBRARY RESOURCES:



zz