PWM Output Causes ADC Spikes

My project uses ADCs at 12bit resolution to sense accels and rate gyros, and also uses hardware PWM to control a motor driver. PWM uses: pins 6 & 7 at 10khz, 16 bit resolution. An optoisolator is put in between the Arduino Due and motor driver.

The problem is that the PWM causes voltage spikes in the ADC readings. At first, I suspected the rate gyros themselves. But it turned out to be the PWM signal. When I comment out the PWM calls, the spikes disappear. What can be done about this? I read about decoupling capacitors, but not sure where they need to be and what values to use.

Optocoupler may take 10-20 mA, post your drawings.

It’s definitely the optoisolator. I put in the PWM calls back in the program, and disconnected the optoisolator, and the ADC spikes disappear.

Shortening the PWM wires from 3 feet to 12 inches did not fix the issue. Adding decoupling capacitors (47 nf per the specs) did not fix the issue.

Putting in a 220 ohm resistor between the PWM pin and the optoisolator input seems to help. I also tried using other Arduino Due ADC pins, and that also seems to help. Unfortunately, my project uses 7 ADCs, so a few a them inherit the spikes.

I use the HCPL9030 optoisolator for it’s speed. I tried another version (HCPL2631), but that makes the problem worse. See attachment.

Has anyone seen similar issues regarding ADC spiking with hardware PWM connected to a load?

optoisolator_fast_expensive_HCPL-9030-000E.pdf (136 KB)

You don't already have a resistor? That could be a problem. Show your schematic. A photo of a hand drawing is OK.