esp32 4-channel ledswrite (PWM) problem

Issue #322 resolved
C WEIB created an issue

Hi,John

I recently found in the process of testing the esp32 development board after setting two servos and then set two pins analog signal (0 ~ 1024) will appear in one of the two servos pwm output abnormalities, after doing a lot of firmware testing found that as long as the two servos are set to 1 and 4 channels or 2 and 3 channels will not appear servo pwm signal abnormalities, other cases will have problems, for example: 1 and 2 channels, 3 and 4 channels will have problems, the following is the waveform graph I measured with an oscilloscope

Comments (15)

  1. C WEIB reporter

    This is the specific code diagram
    First click on the first step
    Then click on the second step
    It will reproduce the problem I described

  2. John Maloney repo owner

    Thanks for the careful testing and the test case.

    It sounds as though the PWM system and servo system are both trying to use the same hardware resources. I will investigate.

  3. John Maloney repo owner

    I found the problem. In some cases a servo and a PWM output were using the same LEDC timer and attempting to set it to different frequencies. A simple fix is to use the same 50Hz frequency for both PWM and servos.

    Fx will be in the next Pilot release.

  4. John Maloney repo owner

    Note that the firmware fix won't be out until the next Pilot release, probably next week.

    However, if you don't mind building and installing the firmware youself, you clone this repository check out the dev branch, and then use platform IO to build and install the firmware:

    pio run -e esp32 -t upload
    
  5. C WEIB reporter

    I just compiled the code of the dev branch, the control of the servo now has no problem, but the control of the motor has a problem, the following is my block code, click in the order of 1-4, to step 4 there will be two motors only one can control the other does not respond, I tried to modify the firmware code of these two places, revert to the code before no changes, it works very well.

  6. C WEIB reporter

    According to your modification yesterday, I only need to modify on my side

    #define MAX_ESP32_CHANNELS 16

    ledcSetup(esp32Channel, 50, 10);

    With these two codes, I was able to use it properly

  7. John Maloney repo owner

    Thank for the careful testing. You found a bug when it tries to use a sixth channel. I just pushed a fix. If you pull the latest changes from the dev branch and rebuild the firmware, you should be able to use a total of 12 pins for either analog output (PWM) or servos.

    The MicroBlocks Tone library (used for music) uses ledc timer 0, so that timer cannot be used for servos/PWM. You would not have noticed that problem since you are not playing Tones in your testing.

  8. John Maloney repo owner

    If you have time, it would be great to test this with 12 simultaneous output channels.

    It might be easiest to test with an oscilloscope, unless you happen to have 12 servos or motors and enough power to drive them all. Also good to test with the Tone library playing a tone.

  9. John Maloney repo owner

    This change is in the latest pilot release 1.2.1. Thank you for reporting this problem.

  10. Log in to comment