0
\$\begingroup\$

I am trying to use current sensing functionality of Arduino Motor Shield R3, the shield is based on L289. The values that I read seem to be very noisy. I am using Arduino UNO A0 analogRead() function to sense current. To fix this I have tried to use low pass filter between the motor shield and arduino uno.

schematic

simulate this circuit – Schematic created using CircuitLab

This helped to fix measurement noise however I have several questions about it:

  1. Is the noise in the sensing signal caused more by the motor it self of the fact that the motor is driven by PWM? (Note I have already increased PWM frequency of Arduino Uno to to 32kHz.)
  2. If I would add a low pass filter to the input PWM signal would the current sensing still be noisy? I have tried adding low pass filter to PWM but it did not seem to change current sensing. The low pass filter however affected the motor, it started to run as usual and slowed down almost to stop over time. Maybe I connected the low pass filter for PWM incorrectly.
  3. Is there actually any advantage of adding a low pass filter for an input PWM signal or is 32kHz PWM fast enough and I should just go with the low pass filter for current sensing?
\$\endgroup\$
2
  • \$\begingroup\$ You can't expect us to know what a "Arduino Motor Shield R3" is. I can't even tell from your question whether R3 is some kind of model number, the designator of a resistor, or something else. This is a general electronics site where arduinos are a small subset of what is talked about. A schematic would help explain exactly what is being sensed and how it is being presented to a (presumably?) A/D input of a microcontroller somewhere. \$\endgroup\$ May 25, 2013 at 21:03
  • \$\begingroup\$ You don't want to be low pass filtering PWM signals; the idea is to turn a some transistor on and off, while avoiding placing it into an in between state in which it dissipates heat. \$\endgroup\$
    – Kaz
    May 25, 2013 at 21:51

1 Answer 1

3
\$\begingroup\$

From the block diagram in the datasheet, you can see that the current sensing is influenced by the output stages of the H-bridge. This means that when you use PWM to drive the motor, the Sense voltage will vary with the PWM signal. The voltage across the sense resistor is proportional with the current through it, which in turn depends on the voltage across the motor's induction. During the positive period of the PWM signal, the current will be 'slowly' increasing whereas during the negative period of the PWM signal the current will be 'slowly' decreasing. In practice this will look a bit like a triangular wave and that is the noise you measure.

The solution is to make sure that you synchronize the sense voltage measurement with the PWM signal. For example you can attach an interrupt to the timer that is used for the PWM signal and it requires a fair bit of digging into the microcontroller's datasheet (and some trial-and-error) to figure out how to realize that. Another option is to connect an interrupt pin to the PWM output pin, which may be simpler to start with. It can be done, though you might need to lower the PWM frequency (to fit the ADC conversion within the PWM duty cycle), directly program the hardware registers (Arduino libraries are slow) or use some assembly.

enter image description here

\$\endgroup\$
4
  • \$\begingroup\$ Isn't a low pass filter on sense signal achieving the same effect? Also would this triangular wave be gone if I used direct voltage change instead of PWM? \$\endgroup\$
    – JuliusG
    May 26, 2013 at 14:04
  • \$\begingroup\$ The low pass filter will achieve the same effect, but it requires extra hardware, whereas the synchronous sampling is a software solution. Not sure what you mean by "used direct voltage change instead of PWM" \$\endgroup\$
    – jippie
    May 26, 2013 at 14:18
  • \$\begingroup\$ I prefer hardware solution in this case. By direct voltage change I was thinking of filtering the PWM that goes into the motor shield. Would doing this have any advantage compared to filtering sense function? \$\endgroup\$
    – JuliusG
    May 26, 2013 at 14:26
  • \$\begingroup\$ If you filter the PWM to a analog voltage that enters the motor shield, you will definitely kill the shield. The output stages are not designed for analog voltages, they are either high or low. Coming to think of it and reviewing the circuit diagram in my answer, the driver chip will turn the analog voltage into a logic signal anyway (the AND-gates), so it won't work at all. \$\endgroup\$
    – jippie
    May 26, 2013 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.