[Teensy 3.1] PWM noise on Photodiode

Status
Not open for further replies.

p.lerolland

New member
Hi everyone,

First, thank you for this Teensy, it's a remarkable board that I really love using!
This forum also is an amazing resource when I have a problem. So for all of this, thank you!

I am posting today because I have a problem when I use both the PWM and the ADC on my Teensy 3.1. Even if I use the analog ground to connect the ground of my analog source, the PWM spreads noise on the analog signal.

It was not to much of a big deal until I started using a photodiode and an opamp. During the high period of the PWM, the noise is so important that it maxes out the value of the photodiode.

I need to be able to adjust the LED intensity (from 0 to 30mA). For now I just connected the LED to a resistor then directly to the PWM pin.

- Do you have an advice that could help prevent that noise with the current system?
- Would using a mosfet to drive the LEDs instead of driving them directly from the PWM pin reduce the noise on the Teensy?
- What do you think about digital potentiometer and a simple voltage divider instead of using the PWM? Very few people use them to control LEDs, is there a good reason for that?

Any input is very welcome!

Thanks you!

Paul
 
First off you should not be supplying anything from the Teensy 3.1 IO that needs more then 9mA ever....

So the first answer is stop torturing the Teensy 3.1 with that LED PWM. That should help the noise.
Second yes, a FET is usually a much better way to run a load, just make sure to have a limiting resistor between the Teensy and the FET and do your homework on connecting it. Test the circuit without the Teensy first, FETs and LED's are cheaper then Teensy's.
Third, many people use PWM for LED control. Not sure who told you otherwise.


Edit.
Note To Paul.
The current limits should really be on the Technical Specs list for the Teensy 3/3.1 so people can plainly see them.
 
Hi Donziboy2,

Thank you for your answer, I will try connecting it through a FET.
About driving the LEDs using a PWM, I know that it is the most common method. I was asking about driving them using a digital potentiometer and a voltage divider. I have not seen that many threads about it online. It does not seem like a bad idea, does it?
 
The digital pots I have seen are not really capable of putting out much current, I have looked at using them in conjunction with Op Amps for a future project.
 
IIRC, none of the digital pots I've looked at in the past were happy about high currents.

There are specific driver chips just for LEDs that will take care of the current and so on. I'd consider those instead. For example, I ran across one in a washer that ran a whole bunch of LEDs without the need for current limiting resistors. Even better, it could reverse current, allowing the manufacturer to install bi-color LEDs that only featured two contacts yet which could produce three sets of colors via PWM and the direction of the voltage (one way was red, the other was green), producing anything from red to yellow to green. Very cool
 
@ Donziboy2:
The datasheet of the MK20DX256VLH7 states the following:
1. Id, Maximum current single pin limit (applies to all digital pins), –25, 25 mA.
2. Ioht, Output high current total for all ports, 100 mA.

So 9mA is perhaps too conservative, but I would not recommend above 20mA.

Paul
 
@ Donziboy2:
The datasheet of the MK20DX256VLH7 states the following:
1. Id, Maximum current single pin limit (applies to all digital pins), –25, 25 mA.
2. Ioht, Output high current total for all ports, 100 mA.

So 9mA is perhaps too conservative, but I would not recommend above 20mA.

Paul

I sourced it from PaulStoffregen
 
The issue may be semantics, i.e. the maximum that the MK20 processor can sustain without permanent damage (for however short a period, however!)

I don't put more than 5mA through any line, but that's because I don't want to keep track of every connection and the current it sources or sinks. That way, I can have 20+ active connections and still be in the clear.

Paul has previously commented re: the need of applying deprecators to data sheet statements. For example, the folk at freescale claim that this chip can, under the right circumstances, achieve 16 bit operation. Then you read a little closer and realize that 16 bits may be on tap only for one differential channel (the other one is not claimed to do better than 13 bits) and that all other analog channels are only good for 12 bits.

The 16 bit operation of the ADC likely required herculean restrictions, i.e. a sophisticated front-end (with components likely as expensive as the MK20 itself), a MK20 whose other tasks were turned off (i.e. just leaving the ADC running while the CPU sleeps), and a separate external power supply for both the MK20 digital as well as the analog circuits. In other words, they perhaps are not lying but in reality, the best you'll ever do is 13 bits and what you should plan for is 12 bits. That's not to say that you can't use decimation and similar tactics to achieve a net higher resolution, but that requires a slow moving signal (relative to sampling speed).

I would apply deprecators accordingly re: all other statements by Freescale re: this chip and instead follow Paul Stoffregens guidance since he's done a lot of testing.
 
Last edited:
I went with Paul's 9 mA limit since in the 4 minutes I skimmed the electrical specs I could not find a continuous current rating for the IOs.
 
Switching current in LEDs is always going to increase noise on sensitive analog measurements, but there are many things you can do to lessen the impact.

The most common problems are related to "ground loops". How you connect all the ground wires is very important. If you post photos of how you've really wired things, it'd be easier to give helpful advise. But without photos or detailed diagrams, the basic idea is to use completely separate connections for analog and digital grounds. All you analog measurement stuff should connect to AGND, and all the digital stuff to regular GND. You want to avoid that LED current flowing through any of the wires for the analog signals.

There may be ways to make your measurements less sensitive to the LED noise. Maybe? Analog circuit design is always tricky and full of small but critically important details. If you post detailed info about your circuits, maybe someone could see ways they could be improved.

Another trick, if you can accept the timing issues, involves making your measurements during a time when the LED is off. This can be done by simply turning the LED off occasionally, or by making your code aware of when the PWM is not driving the LED.
 
Status
Not open for further replies.
Back
Top