Questions about the ESP32 DAC pin function

Issue #293 resolved
C WEIB created an issue

Hi John,

In the use of the ESP32 development board, the motor pin interface of the board is 12 and 26 (M+,M-), pin 12 is working properly, but in pin 26 seems to be only output voltage can not output PWM, after I look through the firmware code found in [here] seems to be the default use of pins 25 and 26 is the default output specified voltage (I do not know if the understanding is right), so I tried to cancel the above code in the DAC function of pin 26, it can be normal output PWM, that is, the motor can operate normally, so I would like to ask if there is any solution to this problem, or I have to replace the pins to control the motor. My idea is whether it is possible to specify that the DAC function is enabled only under certain conditions (this is just my idea). Finally, thank you very much John and MicroBlocks for this project, it is a great work and I like it very much!

The image below shows the building block code used

Comments (4)

  1. John Maloney repo owner

    MicroBlocks uses ESP32 pins 25 and 26, which support digital-to-analog converters -- as true analog outputs. The easiest thing to do is just to use a different pin for your motor PWM, if possible.

    However, pins 25 and 26 can be used as digital outputs, so another option would be write a loop in MicroBlocks to turn pin 26 on and off with the desired duty cycle. For a duty cycle of N% you could turn the pin on for (100 * N) microseconds and off for (100 * (100 - N)) microseconds. That would give you a period of 10 msecs, which should give smooth motor operation.

    Good luck!

  2. Log in to comment