I'm working on a prototype device that moves two servos approx 500 times per minute (8 times per sec = 125ms per 60° movement.)
The cheap servos are approx 160ms, helicopter tail servos are 60-80ms. Allowing 15-20ms for processing time, sometimes more, the device can be unreliable, especially when the 6V (4xAA) battery flattens to 5V and the servo response increases to 80-100ms.
To get the device to run, I'm using an arduino mega (I have approx 20 outputs - was using all digital pins and all analog pins on a nano, as well as A6 for an analog input, for the proof of concept, but need about 3 or 4 more outputs.
To improve cycle time for the critical movements, I've set up the mega that sends a pulse to a separate nano (acting as a coprocessor, for want of a better description.) The nano handles the non-critical functions such as display, background calcs, overload calculation, etc... The pulse from the mega triggers an interrupt on the nano to initiate calculations.
Question:
In your experience, is there a way that I can pass information from the mega to the nano in a way that won't drastically affect the processing speed of the mega (the nano's not time critical). Ideally, not in setup (easy - Connecting two arduino boards by SPI) but in operation?
Hi, this feels like a classic X-Y problem. You had problems getting your Arduino to do something (problem Y), and you have decided that the only way to solve this is to add a second Arduino to the circuit. Now you have a problem getting the two Arduinos to communicate (problem X) and you are asking for help with that.
Can you share details of problem Y? If that could be solved, wouldn't that be a better solution?
The issue is clock speed on an arduino - I've got 20-40ms to perform all calcs. Hence why I thought coprocessor, and leave the mega only driving servos.
Make sense? Happy to be corrected.
hmeijdam - yes, thought shift registers too.
Ideally, if I could pass a target time interval across to the nano, it would help as I could pass the last piece of info over and take load off the mega.
(The cycles per min varies from 30 to 500, time interval 2000ms - 120ms)
So, the coprocessor- can passing a time interval across be done with shift registers somehow? Unsure.
I doubt that. 40ms is a huge amount of time for calculations on a 16MHz controller.
When you setup a communication to a second controller you will loose communication time. Why spend time on communication, when you are out for a fast processing?
As @PaulRB already pointed out, describe your current project, post a schematic, post the code and all dependencies (links to external libraries) and formulate, what should get faster. I bet there are people here, which can help you with that.
When you say the servos "are" 160ms, what do you mean? That's the time they take to respond and move to a new given position? What is the Mega doing during that time? delay(160)? If so, that's wasted time that could be used for the calcs.
The cheap Towerpro 9g servos take 160ms to rotate 60 degrees, helicopter tail rotor servos take 70ms for the same distance.
The arduino just sends a pulse between 500 and 2500 microseconds then continues on its merry way. The cheap servos bog down and are still rotating when the next pulse hits.
Helicopter servos work at 333Hz - signal updates every 3ms if I understand correctly.
Give me until after the new year please - I'll put together a schematic and code.
If you are using the standard Servo library then the signal to the Servo runs at 50Hz no matter what type of servo it is
Faster servos are just that, ie they move faster. Digital servos may use brushless motors to achieve the faster speed and they may run at a higher frequency internally but the Arduino has no influence or knowledge of that
It doesn't have to be your full sketch. Something akin to the Servo Sweep example, or even a one time servo movement between two fixed angles in setup() would show the technique being used,
The reality of that design is your mega will have to be programmed to wait for the answer return so it can be stored in a variable. All mega processing must be done before the coprocessor completes the calculation. Can you ensure that?
Coprocessor might have been the wrong term. perhaps slave may be more accurate?
At the moment, the mega sends a pulse to the nano that initiates a loop through an interrupt which increments a counter on the nano (slave,) splits the value of the counter into digits and then drives a 4 digit, 7 segment LED display to show the value.