wiki-documents icon indicating copy to clipboard operation
wiki-documents copied to clipboard

ESP32C3 - Any PWM output creates serial port interference.

Open andrewpriddis opened this issue 1 year ago • 5 comments

I have a simple piece of code that reads a pin and writes the state to a serial port (USB) every 500 milliseconds. If the pin is HIGH then a pwm signal is wrttien to the tonePin with a duty cycle of 128. Either 00 or FF should be written out the port. This works great unless I add the analogWirte function to the code. If I do then that serial data becomes garbage. See code below and then serial output examples below that.

    if ((millis() - writePauseTimer) > 500)
    {
        if (digitalRead(inputPin))
        {
            pauseState = 0xff;
            analogWrite(tonePin, 128);
        }
        else
        {
            pauseState = 0;
        }
        Serial.write(pauseState);
        writePauseTimer = millis();
    }

This is the garbage written out the serial port when the button is pushed. It appears that the PWM timer is messing with the serial port. image

andrewpriddis avatar Feb 25 '24 06:02 andrewpriddis

Thanks for the information here! I really appreciated!

MatthewJeffson avatar Feb 25 '24 10:02 MatthewJeffson

@MatthewJeffson - Any ideas on how I can handle this?

andrewpriddis avatar Feb 26 '24 05:02 andrewpriddis

@MatthewJeffson - Any help on this?

andrewpriddis avatar Feb 29 '24 00:02 andrewpriddis

Hi andrewpriddis I've tried adding the serial print code to our PWM demo, and the serial monitor is outputting the print information correctly. Perhaps you could double-check the rest of your code to see if something is causing the confusion?

image

image

grilliiiii avatar Mar 01 '24 08:03 grilliiiii

Ok, I put the serial monitor into text mode and now I see what all the garbage is.... all the extra text coming over the port. How do I shut that off? I was viewing as Hex expecting to only see 1s and 0s like your example... image

andrewpriddis avatar Mar 01 '24 16:03 andrewpriddis