Pages: [1]   Go Down
Author Topic: Help modifying servo.h to give a 400hz signal  (Read 1394 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 3
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First off I am aware of how to modify these lines to change the frequency:

Code:
#define MIN_PULSE_WIDTH       544     // the shortest pulse sent to a servo
#define MAX_PULSE_WIDTH      2400     // the longest pulse sent to a servo
#define DEFAULT_PULSE_WIDTH  1500     // default pulse width when servo is attached
#define REFRESH_INTERVAL    20000     // minumim time to refresh servos in microseconds
#define SERVOS_PER_TIMER       12     // the maximum number of servos controlled by one timer
#define MAX_SERVOS   (_Nbr_16timers  * SERVOS_PER_TIMER)

If the REFRESH_INTERVAL is increased the maximum stable update is at 8000 / 125hz. At 2500 the frequency changes from 125hz at 2000us pulse width to 250hz at 1000us. Is there a way to modify this library to give a nice consistent 400hz update rate? Thanks in advance for the help.
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, probably, but how many servos do you want to drive and what inputs will you be taking ?

Your basically increasing the processing load on the chip by 10 so its likely to have unintended knock on effects.

Duane B

rcarduino.blogspot.com
Logged


Offline Offline
Newbie
*
Karma: 3
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm running quad rotor ESCs. The craft flies fine at 125hz updates. I'm looking to the 400hz update because I have moved from running the control algorithms on the arudino to a more powerful 32bit ARM uC. All the arduino does in that mode is take the data from the transmitter, send that data to the other MCU, and update the ESCs based on the data received from the 32 bit processor. All of that takes place over a SPI link in ~.4ms.
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds viable in principle, the next problem is that servo library is based on a full range pulse length of 1 to 2ms so 4 x 2 ms is 8 ms or 125 hz.

I assume that your escs support some other range ?

The servo library code is very readable so easily modifiable

Duane B

Logged


Offline Offline
Newbie
*
Karma: 3
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That makes sense and I just verified what you said on the scope. When the pulses are at 2ms it takes the entire time. So I guess the question now is how does one generate all of the pulses simultaneously?
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i would not do that, instead i would interlace them with an offset chosen to minimise clashes int the high/low transitions for each channel, but thats just off the top of my head and may not be the best plan. whether it is a good plan or not, its very far from anything the servo library does so your looking at some serious modification or starting from scratch.

its also worth checking the specs of your escs, i dont know anything about quad copters, but i think i have seen reference to some escs having the option to switch to a different resolution to spport higher refresh rates in which case you might still be able to get away with some simple mods to the servo library.

Duane B

rcarduino.blogspot.com
Logged


Offline Offline
Newbie
*
Karma: 3
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the input. I think what I really need to look into is a IC that I can interface with to generate the pulses I want at the frequency I desire.
Logged

Offline Offline
Newbie
*
Karma: 3
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I figured out the solution finally. To update at 400hz the code must be changed to

Code:
#define MIN_PULSE_WIDTH       1000// the shortest pulse sent to a servo
#define MAX_PULSE_WIDTH      2000// the longest pulse sent to a servo
#define DEFAULT_PULSE_WIDTH  1500     // default pulse width when servo is attached
#define REFRESH_INTERVAL    2500// minumim time to refresh servos in microseconds
#define SERVOS_PER_TIMER       1     // the maximum number of servos controlled by one timer
#define MAX_SERVOS   (_Nbr_16timers  * SERVOS_PER_TIMER)

The key is 1 servo per timer. If you want to run 8 ESCs the max rate is 200hz with servos per timer at 2. Hope this helps someone.

Notably this will only work for the MEGA because it has four timers.
« Last Edit: December 08, 2012, 03:15:50 pm by mikesbaker » Logged

Pages: [1]   Go Up
Jump to: