Free Flight E-motor timer, conundrum

Arduino projects on the go
Post Reply
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Free Flight E-motor timer, conundrum

Post by MaxZ »

Hi all,

I am programming a ProMini to serve as a motor run timer for free flight models. It is not rocket science, still it took me several days to get it to work as I intended.
The sketch contains code for a safety plug to be removed, and after 2 seconds this lets the motor slowly run up to the max. rpm as set by a pot.

Now, "slowly" is the conundrum. I got it to work ok, but I needed much smaller increases per frame in pulse length than I calculated.

This is how I calculate the pulse length and a subsequent time length to get to a frame rate of 50 Hz, Speed varies from 950 to 2050:

Code: Select all

  digitalWrite(ESCout, HIGH); delayMicroseconds(Speed); digitalWrite(ESCout, LOW);
  delayMicroseconds(20000 - Speed ); // interval for 20ms/50Hz frame
My goal is a run up from zero to full in 2 seconds., i.e. pulse lengths from 950 microseconds to 2050 microseconds
I figured 2 seconds @ 50 Hz is 100 frames, and therefore I should increase the pulse length 1100/100 = 11 microseconds per frame.

It turns out I get to the 2 seconds (after the initial 2 seconds rest) using an increase of just 2 microseconds per frame!

Code: Select all

    // start ramping up motor speed after 2 seconds (if not yet in timed run mode)
    if ((millis() - preStart) >= 2000 && Flag == true) Speed += 2;
Why??

For your information: the text printed on the ProMini is not clear about the timing, could be 8 MHz, 16MHz or 29 MHz. So I set the Arduino IDE to 16 MHz and ran a "burn Bootloader" using Usbasp. Uploading is done with Usbasp as well.
The throttle pulses are correct, same motor behaviour as with a regular Tx/Rx. But it seems the frames are much shorter than calculated?

Anybody?

Cheers,
Max.
Last edited by MaxZ on 22 Jul 2022, 21:27, edited 1 time in total.
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Free Flight E-motor timer, conundrum

Post by MaxZ »

Phil_G wrote: 22 Jul 2022, 16:10 Hi Max, you can't do delayMicroseconds(20000).

https://www.arduino.cc/reference/en/lan ... roseconds/

The actual frame rate isnt at all critical, 15 to 25 ms is fine for the usual ESCs

Cheers
Phil
Duh.......

I checked a lot of things in the reference section, about variable types and other stuff. Just not that :roll:
Silly me, especially as I already concluded that the frame length must be too short. Oh well, I will not easily forget it now.

Thanks Phil,
Max.
Post Reply