Transient/intermittent "noise" level shifting 5v -> 3.3v

128 views
Skip to first unread message

Mark Womack

unread,
Apr 17, 2022, 6:22:57 PM4/17/22
to hbrob...@googlegroups.com
I think I already know the answer of what I will need to do, but I'm going to put this out there to see if anyone has experience they can share.

One of the details that I did not mention on my BLDC controller post is that I have the three encoder signals connected to the Teensy 4. I use an attachInterrupt call to attach methods to each signal, and the method has some very simple code to count the 'ticks' as the encoder signals change. In all there are 120 rising and falling signals from the three encoders.

However, the motor uses 5v for the signals and the Teensy 4 is 3.3v only. So, I have to use some logic level shifters so that the signals get translated into 3.3v. It's pretty straightforward, and all well and good.

And then I run the actual circuit. And what I found was that the interrupt handlers were being triggered even though there did not appear to be a change on the encoder signal. I had code in the handlers to print out the current value compared to the previous value, and it was obvious the value had not changed...yet the handler had been triggered. I had to add some code to 'filter' out the transient 'noise', but I still don't understand what is happening with the Teensy 4. I did an experiment where I swapped in a Teensy 3.5, which is 5v logic resilient and doesn't require the level shifters, and none of the noise was reported. The handlers only triggered when there was an actual change in the signal.

So, now we are at the part where I think I know what I need to do next. My only guess is that there is some kind of transient, very short lived voltage drop/spike coming from the encoder signals that is detected/magnified via the level shifter/Teensy 4 combo, and by the time my code gets a chance to look from inside the interrupt handler, it is already gone. And the only way I am going to be able to see and prove this is to get my circuit on an oscilloscope and/or logic analyzer.

But has anyone else encountered something like this?

-Mark

Stephen D. Williams

unread,
Apr 17, 2022, 6:30:29 PM4/17/22
to hbrob...@googlegroups.com

This is the kind of thing that can probably be solved with a capacitor of the right size to absorb the transient, keeping it below the triggering threshold.

sdw

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hbrobotics/CAF-TXgvOTicb7M_pzqdWgcmRUaUH3m2gyjOfbPrTbvvYh3f10g%40mail.gmail.com.
--

Stephen D. Williams
Founder: VolksDroid, Blue Scholar Foundation
sdw.vcf

Alex Sy

unread,
Apr 17, 2022, 8:13:04 PM4/17/22
to hbrob...@googlegroups.com
Noise has been a major problem in building BLDC controllers since in most cases, BLDC motor draw a lot more current than DC motors.  Because BLDC motors and their wires carry a lot of current that induces noise to parallel wires.   Twist the encoder wires and run them away from the three motor winding wires, at 90 degrees if possible.
Another problem is that hall sensor output are mostly open drain, so verify you have a pullup and it is low enough, like 1K or 470 ohm.  Look at them in a scope.  The good thing is that since it is open drain, you may be able to tie the pullup to your 3.3V, to avoid the need for level conversion.  In some cases, the pullup might be in the BLDC controller so it if you are tapping into it to monitor on you microcontroller, then you might still need your own level translator.  Also adding a small capacitor to ground of about 1000pf might be useful. 
If the wires are long, you can also use a schmitt trigger (like 74LS14 or equivalent), or use a comparator with a feedback resistor to act like it.
Alex
--

Chris Albertson

unread,
Apr 17, 2022, 8:59:20 PM4/17/22
to hbrob...@googlegroups.com
What if you power the hall effect sensors with 3.3 volts?  Do they work?

OK, it didn't work...
If you really do need to level shift 5 volts then maybe a shifter with hysteresis?  Like a Schmidt trigger.   These are really simple, the high and low trip points are different.   The high threshold is about 0.5 volts above the low threshold

A comparator or opamp with positive feedback is one example.   They use a resister from output to the + input and create a "dead band".   

In any case the Google search term is "hysteresis".

An RC low pass can work but they mess with the phase so the lag angle will get worse as the motor spins faster.

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hbrobotics/CAF-TXgvOTicb7M_pzqdWgcmRUaUH3m2gyjOfbPrTbvvYh3f10g%40mail.gmail.com.


--

Chris Albertson
Redondo Beach, California

Sergei Grichine

unread,
Apr 18, 2022, 5:22:41 PM4/18/22
to hbrob...@googlegroups.com
Most of us remember times when each microchip had a 10nF cap next to it, and every 5 of them had a tantalum 10uF cap on the group power line. 

A stand-alone shift converter, in this fashion, should be protected from both 5V and 3V sides by a pair of caps as described above. Btw, a microchip based shift converter is preferable opposed to one hacked from discrete components. 

Best Regards, 
-- Sergei Grichine
   

Chris Albertson

unread,
Apr 18, 2022, 5:57:33 PM4/18/22
to hbrob...@googlegroups.com
Yes, it could be a purpose build shifter chip is better.  The one used here that is giving trouble is, "hacked from discrete components" and there is zero filtering  It is just a single transistor switch. 

SparkFun sells a purpose-built level shift chip that uses a "one shot" device  that turns the output pulse on for a minimum time period and avoids stuttering during transitions But they seem to charge a lot for it.

Some people use CMOS "NOT" gates as level shifters, They can tolerate 5V input and send 3.3 out.  They also make cmos Schmidt triggers.  I have used these for home-made disk encoders to clean up the edges from phototransistor.  These are 50 cent parts.   cheaper than the Sparkfun part.

All that said, the "One Shot" is likely the best design.  They do not introduce a phase shift ad solve the stuttering problem by remaining in one state for a fixed minimum time.

Sergei Grichine

unread,
Apr 18, 2022, 6:02:53 PM4/18/22
to hbrob...@googlegroups.com
I don't think that a one-shot LEVEL CONVERTER is a good idea. But having the right gate voltages and proper schematics is a must, and an unlikely happening in a cheap hacked device. And yes, those caps...

Alex Sy

unread,
Apr 18, 2022, 7:10:44 PM4/18/22
to hbrob...@googlegroups.com
If you are level translating I2C or other open collector/open drain bidirectional bus, you cannot use the active level shifter that has the one-shots.   Instead use the ones that use a FET as the level translator.   For single direction signals or push pull driven buses most any translator will work. In general from 5V CMOS to 3.3V CMOS you can use a resistor divider (or even a 10K series resistor) and for 3.3V CMOS to 5V (CMOS or TTL) you can wire it directly.  The tradeoffs are usually due to how long the wires and how much noise sources there are nearby.
Alex 

Sergei Grichine

unread,
Apr 18, 2022, 11:55:22 PM4/18/22
to hbrob...@googlegroups.com
Here's the right level shifter board from SparkFun: https://www.sparkfun.com/products/15439

It uses PCA9306 chip, although a better TCA39306  chip is available. The board has proper resistors, but only one cap on the high side?

The chip's data sheet has wealth of good info. I didn't see any hysteresis (Schottky) behavior though in either chip (Chris - is this what you meant by "one-shot"?).

Chris Albertson

unread,
Apr 19, 2022, 12:28:16 AM4/19/22
to hbrob...@googlegroups.com
Well, that is what Sparkfun offers.  Either you buy a one transistor device or you buy the TI chip they put on a PCB for you.

The one-shot ensure a minimum pulse width. That would work for a motor that never should have short pulses and it does not introduce phase shift.

You can also do this in software.   The algorithm I like is that you sample the pin and when you get three (or maybe five) samples in a row that are the same, then you use that as the current states.   So If I get two highs and then a low, I start the count again and only after N identical samples do I know the switch is stopped bouncing.

To know what would work best we'd need data capture fro ma digital oscilloscope of the raw hall effect sensor output.

We don't know what is going on without a 'scope.   It could be the motor itself is doing this or it could be the level converter.



Ralph Hipps

unread,
Apr 19, 2022, 4:21:34 PM4/19/22
to HomeBrew Robotics Club
Mark,

another idea to try would be to reduce the input/output impedance of the level shifter.

the schematic shows 10k pullups:


given all the motor noise, perhaps try 1k or 470 ohms instead, or even lower. I'm sure the encoder driver has a very low impedance pulling to ground. Just add those externally someplace, obviously, no need to mess around with trying to replace surface mounted resistors.     =)

A small cap was suggested, might help as well.

Chris Albertson

unread,
Apr 19, 2022, 4:28:55 PM4/19/22
to hbrob...@googlegroups.com
Optical isolators make good level shifters.   For this use case, they don't even need to be very fast.

Sergei Grichine

unread,
Apr 19, 2022, 7:13:06 PM4/19/22
to hbrob...@googlegroups.com
For optical isolators, pay attention on their timing characteristics. Some of them are really slow. Some require too much LED current. Datasheet for the rescue.

Reply all
Reply to author
Forward
0 new messages