LD19 returns 503 values and the speed cannot be changed by PWM

Hello, testing this lidar with the software returns 503 points per revolution when in the datasheet it reaches 5000. I can’t change the speed for PWM using an ESP32 either. What am I doing wrong?

Example code (works with LED and other motor):
#define LDS_MOTOR_PWM_PIN 17

void setup() {
ledcAttach(LDS_MOTOR_PWM_PIN, 40000, 8);
}

void loop() {
ledcWrite(LDS_MOTOR_PWM_PIN, 127); // 117 - 138
delay(100);
}

-GND is common.
-5V using USB adapter.
-Wemos ESP32 board.

(Please do not redirect me to the documentation because I have already seen it many times)

Hi, please use this control logic as the radar has been upgraded.
About development PDF

After the lidar is started, the communication system is first initialized and adjusted. This process lasts about 500ms; then the lidar is sent out.

Basic information is obtained, ranging is started, and ranging data is sent out, angle measurement is initialized simultaneously, and the initialization is completed after about 200ms.

Working mechanism initialization, at this time the lidar continues to output valid point cloud data.

The lidar design has three modes, internal closed-loop speed control mode, external speed control mode, and standby mode. Through lidar, PWM Pins can be switched and controlled freely;

Internal closed-loop speed control mode: After the lidar is powered on, it defaults to the internal closed-loop speed control mode and scans at a frequency of 10Hz by default.

If the lidar works in other modes, the user can input the frequency 3KHz~5KHz (recommended 4KHz) and duty cycle through the PWM pin 45%-55% (recommended 50%), the signal duration is greater than 100ms, switch to the internal speed control mode.

External speed control mode: When the PWM pin input frequency is 0.5KHz~1.5KHz (1KHz is recommended), the duty cycle is 45%-55% (50% recommended), after the signal duration is greater than 100ms, the lidar will switch to the external speed control mode. At this time, the lidar continues to
capture external speed control signals (frequency 0.5KHz~1.5KHz, duty cycle 15%~84%), and capture the signal duty cycle information

It is directly output to the motor control terminal, and the external system performs closed-loop control by receiving the speed information feedback in the lidar protocol.

Standby mode: When the PWM pin input frequency is 6KHz~8KHz (7KHz recommended), the duty cycle is 45%-55% (recommended 50%) and the duration is greater than 100ms, the lidar will switch to standby mode. At this time, the lidar will turn off the motor and transmit power.

Wait for power to be restored.

When the lidar is working, it will monitor the external power supply. When an abnormal power supply is detected (such as the voltage is too low or too high), the lidar will start protection, shut down the motor, transmit power, and restart after the power supply returns to normal.

Hi, I have read the datasheet many times, seen several threads and I did not get it to work, so I ask for help in this forum. I want to find out what I’m doing wrong. Thanks

If you need to enter external speed control mode, you need to leave the PWM at 1KHz, 50% duty cycle for 100ms.
Maintain the same frequency and adjust the duty cycle from “15%-85%”, the higher the number, the faster the speed.

You can verify your PWM with a simple test: Put the device into standby mode.

Input 7KHz, 50% duty cycle, duration 100ms.

Also, can you have an oscilloscope showing us your PWM frequency for viewing? This is to confirm that your output meets the device requirements.

The stanby mode works but when I apply 1KHz does not change anything, it keeps the speed at 10Hz. Code:

#define pinSpeed 17
#define pinStandby 16

void setup() {
Serial.begin(230400);
ledcAttach(pinSpeed, 1000, 8);
ledcAttach(pinStandby, 7000, 8);
ledcWrite(pinSpeed, 127);
delay(150);
}

void loop() {
ledcWrite(pinSpeed, 70); // 40 - 210
ledcWrite(pinStandby, 127);
delay(100);
}

Finally I managed to regulate the speed and the solution is very stupid: it is necessary to add at least a delay(2000) in setup() while the lidar is powered. Then you don’t need to add a delay(100) in the loop().

The minimum with a resolution of 8 bits is 40PWM 3.5Hz and the maximum 210PWM 13Hz and it is possible to connect directly to an ESP (ESP32C3 super mini and Wemos D1 tested)

Thank you very much for the detailed documentation and I hope it will serve more developers

Thank you for sharing.