How can I use a Raspberry Pi 4B to send a PWM signal to an ESC to control an underwater thruster?

Posted by Fengyukun on

Use of ESC: APISQUEEN 24V 100A ESC

100A ESC Instruction Manual:https://cdn.shopify.com/s/files/1/0621/5493/2452/files/100A.pdf?v=1700410535

1:Unlock ESC

The neutral stop signal is its unlocking signal
Using a 50Hz signal, the signal period is 20ms.
The percentage in the instructions refers to the percentage of the PWM control pulse width, not the actual duty cycle of the PWM signal (it is easy to misunderstand here).
Then the neutral stop signal is:
75% duty cycle, 7.5% actual duty cycle : 1.5ms (between 1.475ms and 1.525ms);

import pigpio
import time

pi = pigpio.pi() #create pigpio object
LED_PIN = 18 #define the GPIO port to which the LED is connected
PWM_FREQUENCY = 50 #define the PWM frequency in Hz
PWM_range = 1000
PWM_DUTYCYCLE = 0 # Define PWM duty cycle, value range 0 (2) 55,
pi.set_mode(LED_PIN, pigpio.OUTPUT) #Set the GPIO port to output mode
pi.set_PWM_frequency(LED_PIN, PWM_FREQUENCY) #set PWM frequency
pi.set_PWM_range(LED_PIN, PWM_range) # set range 1000

pi.set_PWM_dutycycle(LED_PIN, 75) # set PWM duty cycle 75/1000=7.5 per cent
time.sleep(3) # delay 3s unlock successful

2. Control ESC

Duty cycle 75%:Actual duty cycle 7.5%-1.5ms (between 1.475ms and 1.525ms) Stopping;
Duty cycle 50%-75%: actual duty cycle 5%-7.5%, 1ms-1.5ms reverse;
Duty cycle 100%: actual duty cycle 7.5%-10% 1.5 ms -2ms forward

pi.set_PWM_dutycycle(LED_PIN, 100)
# Forward :7.5%-10% The higher the duty cycle, the faster the forward speed.
time.sleep(15)

pi.set_PWM_dutycycle(LED_PIN, 60)
# Reverse: the closer the duty cycle is to 5%, the faster the reverse speed is
time.sleep(5)

pi.set_PWM_dutycycle(LED_PIN, 75)
# Duty cycle
time.sleep(5)

3. Debugging


During the debugging process you can use an oscilloscope to see if the waveform is correct:
For example, the following figure is the PWM stop signal I started to send.
The voltage amplitude is 3.3V, the period is 20ms, and the actual duty cycle is 7.5%, which are all correct.
But I still can't unlock the ESC because there is too much noise and clutter in the waveform.

At first I used the RPi.GPIO library, then I replaced it with the pigpio library to send hardware pwm signals to solve the problem.

4. Example code:


import pigpio
import time

pi = pigpio.pi() #create pigpio object
LED_PIN = 18 # Define the GPIO port to which the LED is connected.
PWM_FREQUENCY = 50 #define the PWM frequency in Hz
PWM_range = 1000
PWM_DUTYCYCLE = 0 # Define PWM duty cycle, value range 0 (2) 55,
pi.set_mode(LED_PIN, pigpio.OUTPUT) #Set the GPIO port to output mode
pi.set_PWM_frequency(LED_PIN, PWM_FREQUENCY) #set PWM frequency
pi.set_PWM_range(LED_PIN, PWM_range) # set range 1000

pi.set_PWM_dutycycle(LED_PIN, 75) # set PWM duty cycle 75/1000=7.5 per cent
time.sleep(3) # delay 3s unlock successful

pi.set_PWM_dutycycle(LED_PIN, 100)
# Positive rotation 7.5%-10% duty cycle, the larger the duty cycle, the faster the positive rotation speed
time.sleep(15)

pi.set_PWM_dutycycle(LED_PIN, 60)
# Reverse The closer the duty cycle is to 5%, the faster the reversal speed is
time.sleep(5)

pi.set_PWM_dutycycle(LED_PIN, 75)
# Duty cycle
time.sleep(5)


Share this post



← Older Post Newer Post →


0 comments

Leave a comment