Help with LM339 Comparator - Page 1
Forum section: electronics / beginners

author: trilerian
author_rank: Regular Contributor
timestamp: June 29, 2023, 05:34:00 pm
content: I am trying to take the bemf of a bldc motor and covert it to a digital signal. I am using an lm339 comparator to do this. But I need help getting it right. I am attaching a schematic of the setup. But for right now I am only reading off of phase C on the motor. I am attaching a pic of the scope output as well. Waveform 2, which is the bottom wave is the wave I am using to trigger on since the bemf is difficult to use. That wave is the hall effect sensor. The middle wave is the bemf of phase C. The goal here is to measure the difference between the hall effect sensor and the bemf to determine the "can timing" of the motor. Also the output of the comparator is inversed, I have tried switching the inputs, but it gets worse. I want to eventually use an arduino to calculate.The virtual ground is being created using 1k 5 watt resistors connected to each phase and then tied together.

author: liaifat85
author_rank: Regular Contributor
timestamp: July 01, 2023, 05:51:08 pm
content: As far as I can see here, the basic comparator operation has a 15K pull-up resistor.https://www.theengineeringprojects.com/2017/06/introduction-to-lm339.htmlHere is the datasheet too:https://www.onsemi.com/pdf/datasheet/lm339-d.pdfYou can check all the configurations.

author: Terry Bites
author_rank: Super Contributor
timestamp: July 01, 2023, 08:29:49 pm
content: A classic comparator problem and easy to fix. Well, usually.The LM339 comparator has little or no built in hysteresis, meaning that the input threshold for the hi state is the same as the input threshold for the lo state. Any tiny amount of noise in your input signal will cause the output state to flip.Check for dirt on your virtual ground reference as well as Ph.In general, it’s a bad idea to compare a signal against a circuit ground- grounds are often noisy, especially in power control circuits.see attached. I think you may recognise some of the offending waveforms.www.daycounter.com/Calculators/Comparator-Hysteresis-Calculator.phtml

author: trilerian
author_rank: Regular Contributor
timestamp: July 02, 2023, 10:58:51 pm
content: Thanks for the reply. I will look back into this, but for now I have gone back to the internal comparator in the arduino and using a debounce for hysteresis.

author: Terry Bites
author_rank: Super Contributor
timestamp: July 03, 2023, 05:50:04 am
content: Filtering out a propblem won't fix unrelaible detection and jitter. Not a good solution

author: trilerian
author_rank: Regular Contributor
timestamp: July 03, 2023, 01:41:52 pm
content: Quote from: Terry Bites on July 03, 2023, 05:50:04 amProbably not, but using the internal comparator of the arduino seems to be the choice for this type of project. I had issues with that at first as well, but I have now got my code to output something resembling what I am looking for. Scope pic attached, bottom waveform is a sensor.I still plan on making the 339 work, but I need to order some more parts.

author: trilerian
author_rank: Regular Contributor
timestamp: July 14, 2023, 11:12:18 pm
content: So I am really beside myself with this. I have look through the data sheets and tried multiple configurations with the comparator. I have tried different value resistors for pullups, for the resistor between the + input and the output, for the voltage divider on the input that creates the voltage window. The only thing that sort of works in putting a low pass filter on the output, because I think this is caused by the pwm drive frequency. The low pass helps, but then the square wave turns into something more resembling a saw tooth wave, and there are still ripples at low duty cycle. Also it doesn't trigger an interrupt in the same spot every time.At 100% throttle, when pwm doesn't matter the output gets pretty close, there ends up being one spike I can't get rid of that causes issues.

author: Andy Watson
author_rank: Super Contributor
timestamp: July 15, 2023, 12:33:24 am
content: What is the relationship between the input voltage(s) to the comparator and its power supply voltage (VCC) ? Also, what value of "bemf" are you expecting?QuoteIt would be useful if you could provide more details on your schematic - like the connection of the comparators inputs.

author: trilerian
author_rank: Regular Contributor
timestamp: July 15, 2023, 02:42:42 am
content: I am using a 2s lipo for input, so it will stay above 7.0v, the output is pulled up to 5v ran off an l7805. The bemf is being divided by a voltage divider, and should never be above 5v. I can work on the schematic again, but like I said, I have changed a lot of things experimenting.