Strange Behavior Regarding PWM/possible noise

Hello, I have been designing a circuit for a stationary bicycle accessory that we are building, meant to control a virtual bike in a virtual reality game. We are using an Arduino for sensing different aspects such as speed of pedaling, turning, braking, etc. We are also using the Arduino to give a PWM signal to modulate a retarding force on the bicycle's flywheel, done through the activation of an electromagnet. This is done through the changing of the PWM frequency on digital pin 3, which is set as an output.

However, we find that when the PWM frequency is anything but 0, slight jumps in the analogread values appear at the pins which sense turning, braking, and temperature. I am wondering whether this is noise, and what can be done about this, as it is very important that the values sensed are accurate and do not jump around even a little. Again, we don't have this issue when digital pin 3's PWM frequency is set to 0. Would it be beneficial to completely separate the PWM part of the circuit from the sensing part of the circuit?

A schematic of the circuit is attached, thank you for your help in advance! :slight_smile:

New Circuit.pdf (339 KB)

The schematic doesn't show the Arduino and more importantly, how it is powered. Any variation in the Arduino Vcc will show up as noise in the ADC results, unless you are using a stable external ADC reference.

The schematic also does not show the required capacitors on the 7805 regulators. There is no need to use more than one 7805 to power the sensors.

Note that if the 24V supply drops significantly, so will the individual 7805 outputs (by up to 100 mV), and that also shows up as noise in the ADC. See the 7805 data sheet for the details. You would be better off not using the 24V supply for either the Arduino or the sensor power.

Do you really mean PWM frequency, or do you mean the duty cycle, as set by analogWrite()?

jremington:
The schematic doesn't show the Arduino and more importantly, how it is powered. Any variation in the Arduino Vcc will show up as noise in the ADC results, unless you are using a stable external ADC reference.

The schematic also does not show the required capacitors on the 7805 regulators. There is no need to use more than one 7805 to power the sensors.

Note that if the 24V supply drops significantly, so will the individual 7805 outputs (by up to 100 mV), and that also shows up as noise in the ADC. See the 7805 data sheet for the details. You would be better off not using the 24V supply for either the Arduino or the sensor power.

The Arduino is powered just through a power adaptor. I agree that I didn't need to use so many 7805s and realized that after building it. I'll use only one when i update it. I completely forgot about the capacitors required on the 7805. What you say about the noise makes sense. Would you recommend me just using the Arduino's 5V Vout for the sensor power and keeping the 24V power supply for the electromagnet? Or using a 7805 to power the sensors from the 24V power supply? Also, if they are separate, should the sensors and electromagnet share the same ground? Thanks so much!

ChrisTenone:
Do you really mean PWM frequency, or do you mean the duty cycle, as set by analogWrite()?

Sorry, yes, I meant duty cycle.

The 7805 is gonna get hot taking 24V down to 5. Using a separate 5 volt supply for the logic circutry would be the least prone to issues, but bucking it down (with something like this) would be preferable to the linear device.

A pot MUST be powered from Arduino's 5volt supply to keep it's ratiometric behaviour.
The voltage output of a TMP36 should NOT be measured with Arduino's potentially unstable default Aref.
A 47ohm gate resistor could cause dips in the Arduino supply (~ 75mA gate charge/discharge spikes).
Depending on the gate charge of the mosfet.
Leo..

Bump, can someone please advise me how I should connect the grounds? By separating the sensors' power from the electromagnet, I see that the readings are much more stable if only the sensors are connected, and I believe that the problem lies in how I connect the grounds of the two parts of the circuit.

Wawa:
A pot MUST be powered from Arduino's 5volt supply to keep it's ratiometric behaviour.
The voltage output of a TMP36 should NOT be measured with Arduino's potentially unstable default Aref.
A 47ohm gate resistor could cause dips in the Arduino supply (~ 75mA gate charge/discharge spikes).
Depending on the gate charge of the mosfet.
Leo..

What is an acceptable tolerance for a potentiometer (the ratiometric behavior you mention)?

I don't understand what you mean by "how to connect the grounds". They must be connected by wire, to establish a zero voltage reference.

If you are contemplating alternative circuits, post them so we understand the question.

Make sure that the high current to the electromagnet does not flow along the same wires as the sensor's grounds. This is usually called a 'star' grounding layout where each device is wired back to a common point - they don't share any length of wire.

jremington:
I don't understand what you mean by "how to connect the grounds". They must be connected by wire, to establish a zero voltage reference.

If you are contemplating alternative circuits, post them so we understand the question.

I believe he is saying that the electromagnet and sensors are powered by 2 different power supplies. Should the negative rails for both supplies be connected and a single wire routed from that connection point to the ground pin on the Arduino? Or should a wire run from each negative rail to a separate ground pin on the Arduino?

MorganS:
Make sure that the high current to the electromagnet does not flow along the same wires as the sensor's grounds. This is usually called a 'star' grounding layout where each device is wired back to a common point - they don't share any length of wire.

In order to achieve this, there has to be some some common point at which the ground wires connect so that one wire can be routed to the ground pin of the Arduino. Are you saying to do this as close to the ground pin as possible?

Treat each supply and load as separate. Imagine changing the labels on that diagram so it says "Arduino" instead of "sensor1" and "power supply" instead of "sensor2". That doesn't change the wires going to the ground point.

It doesn't really matter how 'close' the supplies are. The power's really coming from a hydroelectric dam hundreds of km away, isn't it? What does matter is having a single point that every component can agree upon to measure "ground" from. One supply or one sensor may have a long wire going to that point.

unforseen:
In order to achieve this, there has to be some some common point at which the ground wires connect so that one wire can be routed to the ground pin of the Arduino. Are you saying to do this as close to the ground pin as possible?

Yes

MorganS:
Make sure that the high current to the electromagnet does not flow along the same wires as the sensor's grounds. This is usually called a 'star' grounding layout where each device is wired back to a common point - they don't share any length of wire.

Thank you, this answered my question.

I changed the grounding and unfortunately I'm still getting noisy analog readings from the sensors when the PWM duty cycle is greater than 0. They start out consistent, but then they get noisier over time.

Wawa:
A pot MUST be powered from Arduino's 5volt supply to keep it's ratiometric behaviour.
The voltage output of a TMP36 should NOT be measured with Arduino's potentially unstable default Aref.
A 47ohm gate resistor could cause dips in the Arduino supply (~ 75mA gate charge/discharge spikes).
Depending on the gate charge of the mosfet.
Leo..

What would you recommend regarding the 47o resistor? Should I remove it entirely or replace it with another resistor with a different resistance value? Thanks!

If you had read the "how to use this forum" rules, then we would have had more information to help you.

Let's start from the beginning.

  1. speed sensing.
    Use the opto transistor between pin and ground. NO resistor.
    Use pinMode(speedPin, INPUT_PULLUP); in setup(), to enable internal pull up.
    Replace the two 100ohm resistors with one 1k resistor. 3.5-4mA is more than enough opto LED current.

  2. electromagnet.
    Use 10k from pin to ground, and 220ohm from pin to gate.
    Use a logic level mosfet and a schottky diode across the (still unknown) inductor.
    Connect the 24volt supply directly to the coil and the source of the fet. Same for the buffer caps.

  3. braking pot.
    Use a 10k linear pot, directly powered from Arduino's 5volt pin and ground.
    Add a 100n capacitor from pin to ground, since wiring to the bike could be long (hum/hash pickup).
    Same for the flex sensor.

Dump the TMP36. It doesn't play well with the default Aref used for the pot.
A DS18B20 is much better.

Power the (still unknown) Arduino with a cellphone charger, connected to the USB socket.
Use a separate 24volt supply for the electromagnet.
Leo..

Wawa:
If you had read the "how to use this forum" rules, then we would have had more information to help you.

Let's start from the beginning.

  1. speed sensing.
    Use the opto transistor between pin and ground. NO resistor.
    Use pinMode(speedPin, INPUT_PULLUP); in setup(), to enable internal pull up.
    Replace the two 100ohm resistors with one 1k resistor. 3.5-4mA is more than enough opto LED current.

  2. electromagnet.
    Use 10k from pin to ground, and 220ohm from pin to gate.
    Use a logic level mosfet and a schottky diode across the (still unknown) inductor.
    Connect the 24volt supply directly to the coil and the source of the fet. Same for the buffer caps.

  3. braking pot.
    Use a 10k linear pot, directly powered from Arduino's 5volt pin and ground.
    Add a 100n capacitor from pin to ground, since wiring to the bike could be long (hum/hash pickup).
    Same for the flex sensor.

Dump the TMP36. It doesn't play well with the default Aref used for the pot.
A DS18B20 is much better.

Power the (still unknown) Arduino with a cellphone charger, connected to the USB socket.
Use a separate 24volt supply for the electromagnet.
Leo..

Okay thank you very much. This is detailed, and I appreciate it. Sorry, it's my first post on the forums, it's an Uno, and the inductor/electromagnet is unknown to us as well, it's pulled from an old exercise bike.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a complete copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a picture of your project, so we can see your component layout?

Thanks.. Tom... :slight_smile: