Hey Adafruit Team,
First, i want to mention, that i love your products and working with them!
Anyway i got stuck with a problem of understanding - i have a project which uses the NFC Shield in combination with the WaveShield and a single Servo. I got it all running except the Servo ( it's a 360 degree hacked servo ) spinning.
I already found out, that the IDE library of Arduino is in conflict with the Waveshield Library concerning the Timer1 issue. I also tried to come up with a simple code for driving the servo, but it did not work out.
So my question: Is there any way to work around this timer issue and get the Servo running? Is there a simple source of information you could suggest? Honestly i don't get the "secrets": http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM - it is just confusing.
Thanks a lot and many greetings!
Tristan
Timer1/Timer2 - Waveshield + Driving a Servo
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 1
- Joined: Tue Jul 17, 2012 8:41 am
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Timer1/Timer2 - Waveshield + Driving a Servo
Well, there are a few different things you could try.
The simplest thing would be to pick one of adafruit's 16-Channel 12-bit PWM/Servo Drivers. It's more than you need for one servo, but the library is simple to use and it should be easy to integrate.
The Arduino Playground offers a Software Servo library. You can use any available output pins, but it does not use hardware PWM. You have to call a refresh function it every 50ms to keep it going. That requirement might easily conflict with other things you're doing. I don't know for sure, but you might possibly be able to set up Timer2 for 50ms interrupts, and call the refresh from the ISR.
There is also an old thread on the Arduino forums in which a user posted a library called servoTimer2. Here's a description and a link he later posted in another thread:
The simplest thing would be to pick one of adafruit's 16-Channel 12-bit PWM/Servo Drivers. It's more than you need for one servo, but the library is simple to use and it should be easy to integrate.
The Arduino Playground offers a Software Servo library. You can use any available output pins, but it does not use hardware PWM. You have to call a refresh function it every 50ms to keep it going. That requirement might easily conflict with other things you're doing. I don't know for sure, but you might possibly be able to set up Timer2 for 50ms interrupts, and call the refresh from the ISR.
There is also an old thread on the Arduino forums in which a user posted a library called servoTimer2. Here's a description and a link he later posted in another thread:
I posted code a while ago for a library that supports up to eight servos driven by timer2. It uses interrupts rather than PWM so it uses a few CPU cycles approximately 8 times a millisecond to service servos in the background. The timer interval is 0.5 microseconds so the precision is pretty good.
The library is called servoTimer2 and the source code is in a few posts starting here: http://www.arduino.cc/cgi-bin/yabb2/YaB ... 4020386/74
The code works by using the timer interrupt to turn on and off each servo in sequence, based on values written to an array of pulse widths. It would have been easier to implement that code using timer1 but in the application in that thread, timer1 was needed to decode the incoming data from a radio control transmitter.
I havent had an opportunity to write up a tutorial on its use but if you want to give it a try I will be happy to help get you going.
Please be positive and constructive with your questions and comments.