Arduino-Timer-Conflicts-Considerations
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:
- JOIN the WIKI and edit, or
- Email stuff to terry@yourduino.com
ARDUINO RESOURCES THAT NEED TO BE MANAGED
- Hardware Timers (0,1,2 on Arduino UNO, Duemilanove, etc)
- SKETCH Memory:
- FLASH (Sketch code space)
- RAM (Sketch variable space, stack etc)
- EPROM (NonVolatile Memory)
- I/O Pins
- PROTOCOL-SPECIFIC:
- SPI CS pin
- SPI Mode
- I2C Device Addresses
- I2C (?Speed?)
- INTERRUPT DISABLE DURATION
- ?
- ?
- ?
QUESTIONS TO ASK OF LIBRARY CONTRIBUTORS??
- What Timer(s) Does the library use?
- Does it change the Timer Mode or Frequency?
- If it uses SPI:
- What pin is used for CS?
- Can the CS pin be changed? How?
- If it uses I2C
- What device addresses are used?
- Are there I2C Speed considerations?
- ?
- ?
- ?
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
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