Changing the Interval between pulses with writeMicroseconds command?

Hey guys. I've been trying to control a BLDC motor, and from what I've been told I have to start with a certain number of repetitions of 1.5 millisecond pulses, with a delay of 8.5 milliseconds between them. I'm using the writeMicroseconds(#) command from the servo library, and it only allows you to insert one parameter, which is the pulse width in microseconds. From what I've read, if you were to code:

myServo.writeMicroseconds(1500)

pulses of 1500 Microsecond width would be sent out from a designated pin with a flat 20 millisecond interval in between pulses, and it will do this over and over again until the input value for pulsewidth is changed or the program is stopped. (Source: Robin2: "When you issue the command servo.writeMicroseconds(1300) the Arduino produces a pulse that is 1300 micros wide every 20 millisecs indefinitely. If you don't need to change the speed there is no need to repeat the command.").

So how exactly would I go about modifying the delay in between pulses? I've used both delay and delayMicroseconds, but because writeMicroseconds acts indefinitely until stopped, it doesn't matter if the code is stopped for a few seconds, because that won't affect it. Is there a hidden parameter in writeMicroseconds that allows you to change this? If not, is there any way to go about doing it?

What motor do you have?

If you want to experiment in Servo.h in your library you have that line

#define REFRESH_INTERVAL    20000     // minumim time to refresh servos in microseconds

You could play with that. But be sure it's necessary.

Also re-read what robin said, it's not a flat 20ms interval between the pulses, it is the pulse duration + the interval that totals 20ms

Please post a link to the datasheet for the ESC you are trying to control so that we can see how the requirement is specified.

...R
PS. when quoting sources it is more helpful to include a link to the source. I don't deny that I wrote what you say but I have no idea where or when I wrote it and I would like to read it in context

@J-M-L Right, yes. Based on the oscilloscope readings that is correct. I'll try that command, thanks!
@Robin2 Apologies for not linking the source, here it is: http://forum.arduino.cc/index.php?topic=290369.0. I'm not sure if we have the specs, since my grandfather (who gave it to me) got it from a friend. The specs aren't really the question at the moment though. My grandfather emailed whoever the producer of the motor was and was told that to start the motor you need to send it 1.5 ms pulses with 8.5 ms in between them for multiple repetitions to get it running, and then change to 1 ms pulses with 9 ms in between them to keep it running. So that's what I'm trying to simulate, and the issue was that I couldn't change the separation between the pulses since the writeMicroseconds() only takes pulsewidth as it's one parameter.

If you really want to try this just put multiple HIGH LOW transitions with fixed delays in the set up and the 1/9 ms thing in the loop - at least you will know if that gets the motor to spin

The only issue with the 1/9 ms thing is that I can't do a 9 ms delay with the delay command, because from what I've read, the command "writeMicroseconds(x)" will produce signals of x pulsewidth every 20 - pulsewidth milliseconds, so I can't seem to make it pulse every 9 milliseconds. I've tried using delay and delayMicroseconds, but since writeMicroseconds will produce pulses indefinitely until changed, it will continue to produce pulses regardless of whether there is a delay in the code or not. This has been checked and confirmed with an oscilloscope. I've tried putting "#define REFRESH_INTERVAL 10000" at the start of my code, but based on my oscilloscope readings it has no affect. Am I supposed to edit it somewhere else? Apologies if I am, as I'm quite new to Arduino.

If all you have to do is generate a one-off arming sequence, can’t you just write a function (using delay()/delayMicroseconds to keep things simple), that generates the correct arming sequence, called before you do the Servo attach?

I’ve tried putting “#define REFRESH_INTERVAL 10000” at the start of my code,

You would need to modify actually the library file directly (or bring the code of the library in your sketch as additional tabs and modify it there and instead of using angle <#include > to import the library juste use quotes "#include "

I understand your code ultimately will need to do other stuff and thus you can’t use delays. I’m just suggesting that to double check you have the right information about your motor and thus that you create a little sketch with

// use delay in microsecond for this To get the necessary precision 
While true
   Set motor pin HIGH
    Wait for 1 ms
   Set motor pin LOW
   Wait for 9 ms 
End while

In your loop()

And in the setup()

...

Repeat 10 times  // 10 being arbitrary here may be a couple time is fine
    Set motor pin HIGH
    Wait for 1.5 ms 
    Set motor pin LOW
    Wait for 8.5 ms 
End repeat

If that works then you can try to mess around with the timers and interrupt and the library to get that working for you. The code in the setup could stay, and you can try to modify the library for later on using the writeMicrosec thingy for the loop and stick to the new time interval only there

Elivaras:
and was told that to start the motor you need to send it 1.5 ms pulses with 8.5 ms in between them for multiple repetitions to get it running, and then change to 1 ms pulses with 9 ms in between them to keep it running.

I am very doubtful about that. It seems unnecessarily complex. How could you do that with a regular Radio Control TX?

The arming sequence for an ESC may be something like move the control stick all the way to full power followed by all the way to zero power - perhaps holding it in either or both positions for a set time. None of that involves strange millisecond variations.

The point about this is that if you are wrong (even by a little bit) you will never get it working and you will be no wiser. It is like trying to break a code. Either get the user manual or get a manual for a different ESC by the same maker - it may use the same arming sequence. Or get another ESC that does come with a use manual.

...R

@AWOL What's the benefit of doing the arming sequence before attaching? Don't you need it attached to send the signals at all?
@J-M-L Wow, I've coded that and checked the oscilloscope, and it works! Thanks a ton! Although the motor is just beeping instead of running, so I'm going to try and put some more research into it.
@Robin2 I'm not exactly sure of the reasoning behind the variation, but the 1.5 ms with 8.5 ms delay is (I think) to get it started, since you're only doing it for a few repetitions, and then once the motor is up and running you can switching to shorter pulsewidths with a greater delay in between. But I mean, normally you wouldn't manually arm an ESC when using a control stick for a model plane. I would imagine the system would be programmed to do that itself when started, would it not? Apologies if this is not the case, as I hardly know anything about motors, and don't fool around with RC planes/cars (this is just for the motor itself, it's not a motor inside a model of any sort) :stuck_out_tongue:

@AWOL What's the benefit of doing the arming sequence before attaching? Don't you need it attached to send the signals at all?
@J-M-L Wow, I've coded that and checked the oscilloscope, and it works! Thanks a ton! Although the motor is just beeping instead of running, so I'm going to try and put some more research into it.

If you followed J-M-L instructions, it seems to me you have performed arming without attaching so I'm a little puzzled by your comment.

Well, rather than using the attach function I have the pin set as an output to send signals (via pinMode). Is there a big difference between attach and pinMode?

Elivaras:
But I mean, normally you wouldn't manually arm an ESC when using a control stick for a model plane.

AFAIK you do need to arm them. The motors with propellers attached are very dangerous if the motor was to start unexpectedly.

...R

@Robin2 I see, that make sense. But the user wouldn't manually control the pulsewidth in order to arm them, would they? I would think that would be done automatically upon initiating a start-up sequence, but again I don't know much about them so I'm probably wrong.

Elivaras:
@Robin2 I see, that make sense. But the user wouldn't manually control the pulsewidth in order to arm them, would they?

Of course not. So what would the user do? When you know that you can get the Arduino to mimic it. The ESC won't know that there is an Arduino involved.

...R

So you're basically saying that the start up sequence and running sequence we were told seems too complicated (due to the pulsewidth and difference between pulses varying in weird millisecond increments), and is most likely wrong?

Elivaras:
So you're basically saying that the start up sequence and running sequence we were told seems too complicated (due to the pulsewidth and difference between pulses varying in weird millisecond increments), and is most likely wrong?

That is indeed what I suspect.

...R

@J-M-L Wow, I've coded that and checked the oscilloscope, and it works! Thanks a ton! Although the motor is just beeping instead of running, so I'm going to try and put some more research into it.

I'd suggest to play with the timing but I now have a doubt because of the beeping... How do you power your motor? Can you post a wiring diagram?

@J-M-L Here's a bunch of screenshots about how it's all hooked up.

Overview: http://imgur.com/NbjzZTZ
BEC Connected to ESC Hookup: http://imgur.com/hVQ9bCc
Arduino Hookup: http://imgur.com/cghaGz5

The long green wire is connected to pin 9 on the Arduino, and is the signal wire that sends a signal through the BEC to the ESC, and then to the motor. The long white wire is connected to ground. The short green wire strictly on the Arduino is connecting the 5V pin to A0. I was watching a few videos, reading some things, and getting some info from my grandfather about how to hook this all up. From a video I watched, they basically had the exact same hookup, except they had a potentiometer to control the speed. They said in the video that if you don't have a potentiometer, you should connect 5V to A0 directly, since the potentiometer would be hooked up to 5V, GND, and A0. I'm not sure if it's 100% necessary, tbh though.

Is that a real commercial ESC or something custom made? With the capacitor sticking looks like either a BEC or indeed a Brushless Speed Controller ESC Built in BEC

Is 8v enough or too much for your motor? what's the amp settings on you lab supply?