Arduino Nano project that convert analog signal or PWM signal to PPM signal for ESC or servo control.
This program can be used on an Arduino Nano to convert an analog or PWM signal to a PPM signal to control an ESC or a servo.
The main intent for this project is to be able to use a brushless motor + ESC with a 8 bit GRBL board (atmel 328P). 8 bit GRBL boards are not capable to generate a proper PPM signal to control an ESC or servo but they can generate a proper PWM signal.
So the point of this project is to convert the PWM signal into a PPM signal that the ESC (or servo) can understand.
A manual mode (as opposed to PWM mode) is also possible by adding a rocker switch and a potentiometer to adjust the PPM signal and thus the motor speed (or servo position) manually.
PPM stands for Pulse Position Modulation, it is a signal with a pulse that can range typically from 1 to 2 milliseconds (can be shortened/extended) and a period of 20 milliseconds. the PPM signal is quite similar to a PWM signal where the period would be 20 milliseconds but the duty cycle would be limited between 5% and 10% (1ms and 2ms).
the PWM signal on GRBL is generated by a 8bit timer because the 16bit timer is already used for other operations, this creates 2 problems:
- The minimum period this timer can generate is approx. 16ms instead of 20ms. That might still work for some servos and ESC though
- The duty cycle can take 256 (8 bit) differente values from 0 to 100%, with the 16ms period, the PPM range is now 6.25% to 12.5% (1ms to 2ms) which translate into 256 * 6.25% = 16 and 256 * 12.5% = 32. So the PPM that can be generated with this timer as only a range of 16 (32 - 16) steps. A standard remote controller has at least 1024 steps. Also generally ESC have a smaller range than 1-2 ms which reduce even more the available steps.
This project uses the same MCU has GRBL (Atmel 328P) but the program uses the 16bits timer1 instead to generate the PPM signal which give a quite precise 20ms period and 2000 steps of precision. However the PWM from the GRBL board is limited to 256 steps but is still better than 16 steps anyway!
- Arduino Nano (or Uno but bulky)
- Potentiometer (10Kohm f.ex)
- 2 position rocker switch
Signal | From/To | Direction | Default pins | User Config pins |
---|---|---|---|---|
PWM | From GRBL board | Input | D5 | D2 - D7 |
PPM | To ESC/Servo | Output | D9 | - |
Analog | From potentiometer | Input | A0 | A0 - A7 |
Mode | From rocker switch | Input | D2 | D2 - A7 |
italic signals are optional and can be left unconnected if unused.
It is possible for some signals to change their connection pin by changing the user configuration at the top of the program.
The PPM output signal must be on D9 because it is the timer1 compare A output pin and cannot be changed.
D13 should not be used because it is connected to the LED built-in that is used to indicate the mode.
The Arduino can be powered by one of the following:
- The GRBL board 12V or 5V power output
- The ESC Bec (if the ESC is not an octo)
- a DC-DC converter (preferable for use with a servo)
- USB
!! ONLY ONE OF THESE POWER SOURCES CAN BE USED AT A TIME - EXCEPT USB THAT CAN STILL BE CONNECTED !!
If the power source is >6V it has to be connected to VIN (pin 30 on Nano).
If the power source is <6V, it has to be connected to 5V (pin 27 on Nano).
!! 6V is the absolute maximum voltage to power the Atmega 328P !!
The ground needs to be connected from the Nano to both the GRBL board and the ESC or Servo (and external power source if present).
There is at the top of the program a section called USER CONFIG where you can configure some parameters.
The pin mapping can be modified there as explained here.
2 other parameters that can be ajusted are the PPM range and the analog signal scale.
To modify the PPM range you can change the value of the minimum pulse length and maximum pulse length to fit your ESC PPM ramge.
These values are reprensented as microsecond, 1 millisecond is equal to 1000 microsecond.
You can shorten or expend the range.
These are the values you can change in the program for PPM range:
#define PPM_MIN_TIMING 1000
#define PPM_MAX_TIMING 2000
To modify the analog signal scale you can modify the following values in the program:
#define ADC_SCALE_FACTOR 1.0
#define ADC_OFFSET 0
If you're planning on replacing the brushed spindle motor on your CNC by a brushless motor with an ESC here are some recommandation:
- If you're using a plane/Helicopter/boat ESC make sure to cool it down, these ESC are made to be cooled when the model is in motion (air/water). If you do not cool them down they can either reduce their power to protect themselves or get damaged if they have no autoprotection.
- If you're using a car ESC:
- They already have a significant radiator + usually a fan on top which help them cool down.
- On some ESC, the PPM range is divided in 2, the lower half is for braking/reverse and upper half for forward rotation, you can uncomment the
#define CAR_ESC
line to convert the PWM signal to only the upper half part of the PPM range.
- Remember to calibrate your ESC with the PPM signal the first time you use it.
- Based on the Motor + ESC you are going to use, you might need a more powerful power source than the one you have for your brushed motor.
- If you see a sudden power reduction of your motor it might be because of ESC low voltage protection, if you're powering your ESC from a power supply, you should try to deactivate this protection (possible on some ESC) or put a bigger capacitor on the ESC power line to avoid voltage fluctuation.