Amplify 500mV 0-pk square wave to >2V for PIC MCU - Page 1
Forum section: electronics / general

author: JDW
author_rank: Frequent Contributor
timestamp: March 27, 2023, 06:38:34 am
content: I need to get a PIC16F1503 MCU to read a500mV 0-pk squarewave. (Minimum half cycle pulse-width is 3ms, and longest pulse-width is about 1 second. Rise/Fall times are not critical and are about 20us or less.) The problem is that 500mV voltage level is so low I can't even switch a BJT or MosFET with it.What is the easiest and most straight-forward way to amplify the 500mV 0-pk squarewave to at least 2V 0-pk (preferably 5V), so the PIC can properly read HI/LO? (I have access to 5.0V and 12.0V voltage rails.)Thank you.

author: nvmR
author_rank: Regular Contributor
timestamp: March 27, 2023, 06:41:18 am
content: take a comparator or an op amp with hysteresis (both with rail to rail), create a threshold at 1/2 of 500mV using a resistor divider at one input, and place your signal at the other. The result will be at your desired voltage.Or use a level shifter.

author: PSR B1257
author_rank: Frequent Contributor
timestamp: March 27, 2023, 06:51:41 am
content: QuoteWhy amplify at all?I would consider the build in ADC or comparator.

author: redkitedesign
author_rank: Regular Contributor
timestamp: March 27, 2023, 07:09:54 am
content: Quote from: JDW on March 27, 2023, 06:38:34 amOf course you can switch a BJT with 500mV, how do you think a Rail to Rail opamp works?In your situation, consider using a BJT in a common base configuration:Connect the base to a resistor divider at 1V. Connect the signal to the emitter. Now the BJT will switch on at 0V, and off at 0.5V (0.2V actually).Pull up the collector to the input voltage of your MCU, and pronto!Just remember that the source will have to sink the base and collector current, thus choose the resistors appropriately. Perhaps you need to add a second BJT to get enough speed to drive the MCU input; YMMV.

author: Kleinstein
author_rank: Super Contributor
timestamp: March 27, 2023, 07:34:51 am
content: One can still use a BJT, e.g. in base configuration, if the signal source is low impedance.Most PICs, inluding the PIC16F1503 have an internal comparator that can be use with a 500 mV signal. It would only need a divider for a trigger level if one can not use the internal DAC for this.

author: JDW
author_rank: Frequent Contributor
timestamp: March 27, 2023, 07:35:45 am
content: Quote from: redkitedesign on March 27, 2023, 07:09:54 amI am taking a liking to your recommendation the most because (1) I won't need to mess with ADC on the MCU to read the incoming signal, and (2) your idea simulates, whereas I couldn't quite get a LO-HI Level Shifter circuit to do it.If I use a 10k pull-up on the Collector, I can get 3.5V as the output, which is enough for the PIC MCU to detect, and the benefit is lower current consumption versus a 1k pull-up that will output 4.9V. The Source will need to sink about 650uA, which I will need to test, but it should be fine.

author: JDW
author_rank: Frequent Contributor
timestamp: March 27, 2023, 08:25:28 am
content: Bad news. The recommended circuit I showed in my previous post doesn't work as expected when breadboarded and connected to my PIC MCU's input pin, despite the fact the simulated result is good. Even if I swap out the 10k pull-up for a 1k, it merely adds to the DC offset, and all the while the output is a 500mV pk-pk waveform which is the same as the input. You can see that in the attached scope shot below. BJT is your run-of-the-mill NPN: 2SC1815.Hmmm...By the way, I'm using the 50Ω output of a Function Generator for this bench test. The actual signal is a vehicle's Speed signal pulse train. I've not confirmed what that source impedance is or tested that with this new circuit yet.[ Specified attachment is not available ]

author: PSR B1257
author_rank: Frequent Contributor
timestamp: March 27, 2023, 09:06:46 am
content: Have you confirmed the pin-out of the transistor?QuoteThat would be a good idea. The output-type is a relevant information.

author: JDW
author_rank: Frequent Contributor
timestamp: March 27, 2023, 09:24:33 am
content: Quote from: PSR B1257 on March 27, 2023, 09:06:46 amYes, of course. I was using the same NPN on the bench with success when I original thought the vehicle's speed pulse waveform would be something more sane like 5V pk-pk or even 3.3v pk-pk. When I connected my device to the car it didn't work, and it was then I discovered why -- the car's Speed pulse waveform is only 500mV pk-pk. It was then I set out to find the best way to boost the voltage of the signal so my PIC could read it, which is what this thread is about.The software is mostly finalized, so I really would rather not write ADC code to fiddle with it that way. And external hardware approach is preferred, if I can achieve it. Even so, there would need to be protection circuitry added to the signal input, seeing this is a vehicle install and you never know what someone will feed into the PCB when its out in the wild.

author: tszaboo
author_rank: Super Contributor
timestamp: March 27, 2023, 10:01:23 am
content: Quote from: PSR B1257 on March 27, 2023, 06:51:41 amYeah, that particular PIC has a built-in comparator on four pins. Set the point with the internal DAC, and just connect the signal to one of those pins.See section 17. of the datasheethttps://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/40001607D.pdf

author: PSR B1257
author_rank: Frequent Contributor
timestamp: March 27, 2023, 10:15:04 am
content: QuoteSeem's like this particular unit can not sink current. I threw together the same circuit and it worked as expected (function generator is a Rigol DG4000 Series)Not relevant in this case, but one should also pay attention to the "output-load setting" of the FG. If it is set to 50Ohm, the actual output voltage doubles (output-impedace of the FG and load-impedance form a voltage divider), to achieve the desired voltage at the DUT.In your case, a higher output voltage would not hinder the function of the circuit.

author: bobaruni
author_rank: Regular Contributor
timestamp: March 27, 2023, 02:52:18 pm
content: If you can't use the comparator, you can add some bias to the 500mv signal which means it will no longer go to 0v on the L part of the signal but it will get above 700mV on the H part of the signal so that a BJT can be switched on like below:So the easiest reliable way without using the internal comparator is 1x NPN BJT and 2 x R (R3 is a pull-up inside the PIC, modelled as 40K).Also, if the sensor is a an inductor, then it might not be 500mV p-p reliably at all speeds (frequencies), you could capacitively couple the signal to the base of a common emitter amp and use more of the gain in the BJT to square up the signal.

author: JDW
author_rank: Frequent Contributor
timestamp: March 28, 2023, 02:16:10 am
content: Quote from: bobaruni on March 27, 2023, 02:52:18 pmThank you for the idea. I confirmed it simulates perfectly. HOWEVER, it does NOT work in an actual circuit on the bench because my Function Generator cannot sink current. And even if an in-car test shows that MY CAR can sink current, that doesn't guarantee other car models will. And while vehicle schematics are available, the technical parts of the ECU that pertain to actual circuits for signal generation aren't available, so we can only speculate what is happening on the car side. I therefore need a solution that works without the signal source needed to sink current.As you can see from the attachments, the Function Generator on my bench is outputting on its 50Ω connector, and I had to use that instead of the TTL connector so I could manually set the output voltage to 500mV peak to peak, and add DC offset to ensure the low side rests at 0v (which matches the measured waveform on the car). But as you can see, the output from the Collector of the NPN as measured on the scope shows a massive 700mV DC offset from 0v, and the signal has shrunk to about 50mV pk-pk, which is totally and utterly unusable, and worse that the original waveform.

author: IDEngineer
author_rank: Super Contributor
timestamp: March 28, 2023, 02:59:40 am
content: The comparator in the MCU is there for a reason. It's the simplest, easiest, cheapest, and most reliable of the options discussed here.

author: redkitedesign
author_rank: Regular Contributor
timestamp: March 28, 2023, 07:33:33 am
content: Quote from: JDW on March 28, 2023, 02:16:10 amYou can add a pulldown on the input of the original common-base amplifier to provide the sink, and use the sourcing capability of the sensor to switch.You can add a NFET on the output of the BJT common base amplifier to provide low-impedance output switching, and bias your BJT with >1M resistors to keep the input impedance high.If you have to make something that can work with both no-sink, and no-source sensors, then you need more than one transistor, and you are better of with a comparator or opamp.

author: JDW
author_rank: Frequent Contributor
timestamp: March 28, 2023, 08:25:16 am
content: Quote from: redkitedesign on March 28, 2023, 07:33:33 amAdding a 1kΩ pulldown at the signal source simulates fine, but a bench test shows the exact same scope readings I showed you before.By the way, this isn't a "sensor" I am reading, technically. It's a vehicle's speed pulse output, which tells my PIC how fast the vehicle is moving, and whether it is even moving at all. It is that waveform which I measured in the vehicle to be 500mW pk-pk.Quote from: IDEngineer on March 28, 2023, 02:59:40 amI do appreciate the recommendations for that solution. Right now though, I have my reasons for keeping that a solution of last resort, and I also have reasons to keep such a comparator external too. I am not commenting on Comparators yet because I needed to order parts today to bench test it. Specifically, theTVL1811(with Push-Pull), which is deal for automotive use. Once I can breadboard it and get results, then I will be equipped to report back on how well that works.

author: IDEngineer
author_rank: Super Contributor
timestamp: March 28, 2023, 02:23:21 pm
content: An external comparator is likely to be faster and yield better results, but there's an elegance in a near-zero extra parts solution. I presume the reason you're avoiding the internal comparator is a pin conflict with another peripheral?

author: Kleinstein
author_rank: Super Contributor
timestamp: March 28, 2023, 03:28:57 pm
content: One would normally use the µC internal comparator as the prefered solution and only if this does not work (e.g. pin conflict, to slow - which is not likely here) consider extra hardware as a backup plan / last resort.

author: IDEngineer
author_rank: Super Contributor
timestamp: March 28, 2023, 03:36:20 pm
content: The OP does seem to be playing things a little close to the vest on the whole comparator question. The obvious answers are being ruled out in favor of those involving multiple external discretes. Hmmm.

author: redkitedesign
author_rank: Regular Contributor
timestamp: March 28, 2023, 07:15:29 pm
content: Quote from: JDW on March 28, 2023, 08:25:16 amWell, it's not really clear to me what you are actually measuring in those plots, with which circuit and what the actual zero-level and scope settings are, so I can't really help you with that.QuoteTechnically, that is called a sensor. It senses vehicle speed. It's probably even an analog sensor, since although the signal is discrete in voltage (either 0V or 0.5V), the actual signal is in the timing which can vary continuously over the measurement range.And that is relevant, since some of the solutions listed above do affect the timing of the signal.

author: IDEngineer
author_rank: Super Contributor
timestamp: March 28, 2023, 07:23:35 pm
content: Begs the question of what sort of "sensor" he's accessing, too. In the automotive world 0.0-0.5V is not a traditional dynamic range. I'd expect 0-5V or 0-12V.If there's any chance that conditions could change and that signal could start swinging 0-12V, he'll need a different input scheme.This thread is seriously lacking in important details.

author: nctnico
author_rank: Super Contributor
timestamp: March 28, 2023, 07:26:46 pm
content: Quote from: nvmR on March 27, 2023, 06:41:18 amDon't use an opamp in this situation! Driving an opamp into saturation is asking for trouble (including loading the signal input to much and causing problems for other parts of the car reading this signal). A comparator is the best solution in this case.Quote from: IDEngineer on March 28, 2023, 07:23:35 pmSpeed sensors are typically magnetic pickup sensors so the 500mVpp seems fine to me.

author: IDEngineer
author_rank: Super Contributor
timestamp: March 28, 2023, 07:40:42 pm
content: Quote from: nctnico on March 28, 2023, 07:26:46 pmTrue if he has access to the raw detection circuit. But most automotive sensors have local conditioning and run on 5V or 12V so their outputs are typically related to the supply voltage.Not a hard and fast rule, but it made me worry that his 0.5V max voltage might "jump" to 5V or 12V sometime in the future ifsomething changes....

author: nctnico
author_rank: Super Contributor
timestamp: March 28, 2023, 07:53:19 pm
content: Quote from: IDEngineer on March 28, 2023, 07:40:42 pmYep. We shouldn't rule out the OP has the probe attenuation wrong by a factor of 10. Impossible to tell from behind the screen.

author: JDW
author_rank: Frequent Contributor
timestamp: March 29, 2023, 02:58:19 am
content: There's nothing wrong with my scope probe. It is set to 10x as it should be. See attached photo. I also attached the scope make and model. Nothing wrong going on there.In my last post where I posted pics of the scope display, 0v is the bottom most line on the scope (as you may expect).Yesterday, I acquired a technical document showing a partial schematic of the car's speed pulse circuit, a single page excerpt of which is attached below, which includes my translation into English and my scope measurement in red. (The part I tapped in the car to measure with my scope is colored in yellow.) If anyone wants the full PDF, which is in Japanese, PM me. (You would just need to copy/paste the text into Google translate to read it.)Again, I measured it to be a 500mV 0-pk waveform on two separate Toyota vehicles.The pulse widths show the car's speed in accordance with a fixed Toyota formula, and I have attached a single page excerpt for you below in case you cannot download the entire document (English version) here...https://www.scribd.com/document/386889141/JIS-D5601-1992

author: mikerj
author_rank: Super Contributor
timestamp: March 29, 2023, 12:06:47 pm
content: Quote from: JDW on March 28, 2023, 02:16:10 amEither you are mistaken or your signal generator is broken; a 50 ohm signal output that cannot sink any current would be completely useless for a signal generator. You wouldn't be able to inject an undistorted signal into any circuit that didn't have a DC bias matching or exceeding the peak voltage of your signal (e.g. any circuit with AC coupling).

author: nctnico
author_rank: Super Contributor
timestamp: March 29, 2023, 12:18:58 pm
content: Quote from: JDW on March 29, 2023, 02:58:19 amBut how is the probe attenuation factor setup in your scope? Can you try to measure the speed signal with a multimeter set to DC? That should give an indication of the signal level and whether the amplitude you see on your scope is correct. It makes more sense to me when the speed signal swings between (ballpark) 2V to 10V so there is also a way to detect whether the signal is open or shorted to ground or 12V (as a security measure).

author: SiliconWizard
author_rank: Super Contributor
timestamp: March 29, 2023, 08:59:28 pm
content: Quote from: mikerj on March 29, 2023, 12:06:47 pmA 50 ohm output is typically made to feed a 50 ohm load for impedance matching reasons.What that means is that the load seen by the output amplifier is typically 100 ohm.If your generator has say a max output voltage of +/-10 V, that means it must be able to source/sink at least +/-100 mA.That's certainly some current and most opamps - if say you intended to use an opamp as the output stage - are not able to deliver that.Some specialty high output current ones can, often a tad expensive, otherwise you have to design your own discrete output stage or otherwise use a beefier integrated amp.

author: JDW
author_rank: Frequent Contributor
timestamp: March 30, 2023, 01:08:30 am
content: Quote from: mikerj on March 29, 2023, 12:06:47 pmThen it must be "broken" because I am not mistaken in what I have revealed in this thread thus far. See my previous posts for the scope signals. I don't seek how a "broken" function generator could output any signal though. So I am guessing it is in fact NOT broken at all. The functionality of the circuits proposed to me do not work with that function generator as they do on my computer sim though. That is all I can say right now.

author: JDW
author_rank: Frequent Contributor
timestamp: March 30, 2023, 01:12:09 am
content: Quote from: nctnico on March 29, 2023, 12:18:58 pmIn all the scope photos I've posted to date, and in pretty much all my measurements, I have the scope set to DC coupling. AC coupling merely throws the waveform across 0v and doesn't show me any DC offsets that may be there, which is why I don't use AC coupling much, but I have used both settings and I can tell you it is a 500mV 0v to peak waveform (when set to DC coupling).

author: drvtech
author_rank: Regular Contributor
timestamp: March 30, 2023, 04:51:08 pm
content: Quote from: JDW on March 30, 2023, 01:08:30 amYes it could, easily.The output stage of the function generator will ultimately be a pair of transistors, either discrete or within an op amp chip or similar - one which sources current from the +ve supply rail and another which sinks current down to ground or a -ve supply rail. If one of these is damaged then you'll get an asymmetrical output. Have you looked at the output of your waveform generator when it is driving a simple resistor load?

author: nctnico
author_rank: Super Contributor
timestamp: March 30, 2023, 04:56:53 pm
content: Quote from: JDW on March 30, 2023, 01:12:09 amYes, but your photos don't show how the input scaling factor on your scope is setup. You have a switchable 1:1 / 1:10 probe but when you change the switch, you'll need to configure the input scaling of your oscilloscope as well. This change does not happen automatically in your oscilloscope. You need to check this before continuing.

author: Kim Christensen
author_rank: Super Contributor
timestamp: March 30, 2023, 07:59:18 pm
content: It doesn't surprise me that those transistor circuits don't work in the real world.Bipolar transistors don't turn on at precisely 700mV and then turncompletelyoff with 699mV or even 600mV of base-emitter voltage. So that prebias is going to have to be lower than 1V. Try breadboarding something with a trimmer pot and adjust the pot to get it working:Adjust the pot clockwise until it stops working. Pull the transistor out and measure the DC voltage at the pot's wiper.Put transistor back into the breadboard.Then adjust the pot counter clockwise until it works, and then stops, working. Pull the transistor out and measure the DC voltage at the pot's wiper.Then calculate the midpoint voltage using the above two readings. Design your voltage divider for that voltage.After all that, I'm going to say that this transistor solution isn't that great anyway because the transistor's Vbe turn on/off voltages are going to vary with temperature and different transistors. Maybe even enough it that won't work in all situations even after our little experiment above.Using a comparator as previously suggested is a better and more reliable solution, but this can get you by until your parts come in.

author: peter-h
author_rank: Super Contributor
timestamp: March 30, 2023, 09:10:18 pm
content: What is wrong with this?Of course a real analog guy would form the 1N4148 with another BC847C

author: JDW
author_rank: Frequent Contributor
timestamp: March 30, 2023, 09:12:56 pm
content: Quote from: nctnico on March 30, 2023, 04:56:53 pmNo need for the scope lecture. I know how it works. I assure you, the probe is switched to 10x and the scope is set to 10x as well. It is absolutely, positively NOT a 1x/10x mismatch issue!

author: JDW
author_rank: Frequent Contributor
timestamp: March 30, 2023, 09:23:52 pm
content: Quote from: peter-h on March 30, 2023, 09:10:18 pmIn answer to your question, the output simulates wrong...

author: JDW
author_rank: Frequent Contributor
timestamp: March 30, 2023, 09:26:53 pm
content: Quote from: drvtech on March 30, 2023, 04:51:08 pmTell me the exact size of the resistor load you want me to try in conjunction with my function generator's 50Ω connector, set to output the aforementioned 500mV 0-pk waveform, and I will breadboard test it for you.

author: JDW
author_rank: Frequent Contributor
timestamp: March 30, 2023, 09:29:58 pm
content: Quote from: Kim Christensen on March 30, 2023, 07:59:18 pmI am away from the bench at the moment, but I will try that later today, thanks.

author: peter-h
author_rank: Super Contributor
timestamp: March 30, 2023, 09:33:40 pm
content: 1Hz input... it would do.OK make that cap 10uF.

author: nctnico
author_rank: Super Contributor
timestamp: March 30, 2023, 09:40:01 pm
content: Quote from: peter-h on March 30, 2023, 09:10:18 pmA lot. This circuit is basically loading the signal with the BE diode. If you want this to work, then at least put in a resistor between emitter and ground. Something like 100 Ohm.But the better way is to use a comparator with a resistive divider that produces 3 voltages. One to bias the - input, one to bias the + input (through a high Ohm resistor) and couple the signal through a capacitor into the +. The DC difference between + and - sets the minimum amplitude. Because all DC levels are derived from the same divider, you won't have trouble with the threshold shifting due to part variation. This circuit will work much better and cost the same in parts.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: March 30, 2023, 09:45:12 pm
content: Quote from: JDW on March 30, 2023, 01:12:09 amIt is best to avoid coupling CAPS on low frequency signals, if that is possible.You should also check the source impedance of the signal, and check if your circuit loads it too much.How many of this are you making ?Transistor circuits will load the signal (emitter injection is lower impedance than base injection) and they ideally need a companion diode bias for thermal stability.A purist would use a Dual NPN package part.Simplest and highest load will be a rail-rail comparator with hysteresis and a bias point of 250mV.The TVL1811 you mention looks fine, tho there are also cheaper parts like TLV7011, or TLV7031-Q1 if you need full automotive spec.

author: IDEngineer
author_rank: Super Contributor
timestamp: March 30, 2023, 09:47:32 pm
content: Quote from: nctnico on March 30, 2023, 09:40:01 pmThe OP has an integral comparator in his MCU which, according to this thread, has sufficient specs to do the job.We are, so far, unanswered as to why the OP is intentionally unwilling to take advantage of that superior solution.

author: JDW
author_rank: Frequent Contributor
timestamp: March 30, 2023, 09:59:04 pm
content: Quote from: peter-h on March 30, 2023, 09:33:40 pmOutput still not OK.

author: peter-h
author_rank: Super Contributor
timestamp: March 30, 2023, 10:00:52 pm
content: Of course there is a better way. I use SOT-23 comparators which cost 13p...But the OP didn't specify enough detail.The Vbe loading on the signal doesn't exist because it swings only 250mV above and below, and there is about 0.5V leeway.From the latest sim above, it looks like there is a capacitor across the output.

author: JDW
author_rank: Frequent Contributor
timestamp: March 30, 2023, 10:02:37 pm
content: Quote from: IDEngineer on March 30, 2023, 09:47:32 pmWhen the parts I ordered arrive, I shall implement that "superior solution" and then offer a full report in this thread.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: March 30, 2023, 11:26:46 pm
content: Quote from: JDW on March 30, 2023, 09:59:04 pmIt is hard to get full swing from a NPN design, and a cap is less than ideal, but I can get a workable sim using500mV -- 15k -- 10uF -- Base -- 330k -- Collector -- 4k7 -- +5V, emitter groundedtho that has a lower limit of a bit under 10Hz due to the cap.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: March 30, 2023, 11:30:26 pm
content: The cap was annoying me, so I tried a NPN pair design with a VBE-offset trick, which now responds down to DCSeems ok even down to 150mV drive.A comparator has a higher input impedance, and uses 2 fewer resistors.Addit: Updated with numbers for roughly 250mV thresholdR1 = 3k3 R4=3k3 => Transfer : 51mV = 3V, 75mV = 0.8VR1 = 5k6 R4=3k3 => Transfer : 117mV = 3V, 140mV = 0.8VR1=10k R4=3k3 => Transfer 236mV = 3V 260mV = 0.8VR1=12k R4= 4k7 => Transfer 251mV = 3V 275mV = 0.8V

author: JDW
author_rank: Frequent Contributor
timestamp: March 31, 2023, 01:54:16 am
content: Quote from: PCB.Wiz on March 30, 2023, 11:30:26 pmMy simulations of your circuit don't fare so well.As shown in the sim photos below:1. When I add a 1.5MΩ load resistor to simulate what a PIC MCU input pin will approximate, the output (yellow color) is a constant 0V.2. When I kill the load resistor, the output swings between a fixed -250mV and a voltage value that slowly changes from about -50nV to -1uV after 100 seconds (and keeps changing).As I have said, I am waiting for comparator parts to arrive. I have been convinced that is the best approach. Meanwhile, I am merely doing my own sims of other circuits presented here simply to show what I see on my end, and why those circuits probably will not function correctly even if I spend my time building them on the breadboard.

author: Kim Christensen
author_rank: Super Contributor
timestamp: March 31, 2023, 02:11:31 am
content: Quote from: JDW on March 31, 2023, 01:54:16 amYou've simmed his circuit incorrectly. You've replaced his 5V power source (V2) with a 1.5M resistor and switch...

author: JDW
author_rank: Frequent Contributor
timestamp: March 31, 2023, 02:21:06 am
content: Quote from: Kim Christensen on March 31, 2023, 02:11:31 amThank you. However, that correction only makes the output a constant +5V, with or without a PIC MCU load, as shown below.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: March 31, 2023, 03:02:23 am
content: Quote from: JDW on March 31, 2023, 02:21:06 amThe load connects to theQ1 collectorMost Spice pgms treat 1.5M as milli, try 1.5Meg

author: JDW
author_rank: Frequent Contributor
timestamp: March 31, 2023, 04:45:54 am
content: Quote from: PCB.Wiz on March 31, 2023, 03:02:23 amIn theoriginal postpresenting the circuit to me, Q2 is the label on the NPN at left, and Q1 is the label on the NPN at right. So in my circuit, my 1.5M (which absolutely is Mega-ohm in my sim) load is already connected to the collector of that NPN labeled Q1 (at right).Or do you mean to tell me to connect my 1.5MΩ load resistor to the collector of Q2, which again, is the NPN at left? (It's collector now connects to R1.) Even if I do that, the output across the 1.5MΩ load resistor is a rock solid 5.0v that never budges.

author: Kim Christensen
author_rank: Super Contributor
timestamp: March 31, 2023, 05:00:15 am
content: You need to do this:

author: JDW
author_rank: Frequent Contributor
timestamp: March 31, 2023, 05:25:03 am
content: Quote from: Kim Christensen on March 31, 2023, 05:00:15 amOh my. Well, thank you. I'm one of those massively overtaxed multitaskers who misses the little detail now and then. It simulates! See attachments. Output swings between 61.274mV and 4.68V with a 1.5MΩ load resistor. I will now breadboard this and if it passes the bench test, I will then proceed with an in-vehicle test.I still have my voltage comparator parts in the mail, and that may prove the most reliable solution in the end. But parts count and cost do matter, so we shall see. Because this is for vehicle use, I would need to break up that 3.3kΩ single resistor into two pieces with a BAT54 in the middle (with one diode tied to GND and the other to surge protected protected +12V) to ensure a voltage spike won't kill Q2.Anyway, thank you for the hand-holding and detailed clarification, Kim!BREADBOARD TEST FAILED: The output at the collector of Q1 when using my Function Generator is basically zero. Well, a 50mV 0-pk voltage level, but that's it. No pulsing at all.

author: peter-h
author_rank: Super Contributor
timestamp: March 31, 2023, 07:11:49 am
content: Ntnico is half rightmy circuit needs a resistor in the emitter of the transistor to eliminate the loading on the up-swing.If you want a solution which works down to DC then you basically need to build a comparator with a +250mV threshold, and it would need a PNP transistor.Or use a TL331

author: Damianos
author_rank: Frequent Contributor
timestamp: March 31, 2023, 07:56:04 am
content: Quote from: JDW on March 29, 2023, 02:58:19 amIn the diagram of the first picture it seems that the signal is coming from an open collector source and the voltage is "created" at the measuring instrument by a pull-up resistor; a diode is added to be possible to connect more instruments simultaneously.What was connected there, while you did the measurement?If the diagram shows the reality, do the same thing, that is a pull-up resistor and a diode!

author: JDW
author_rank: Frequent Contributor
timestamp: March 31, 2023, 07:58:00 am
content: Quote from: peter-h on March 31, 2023, 07:11:49 amI'm sorry, but I don't follow how the new circuit matches with the one shown in the attachments in my previous post, which was built using your original circuit. Your new circuit seems to be referring to Q1, but that is an NPN (from your earlier design). The arrow in the transistor in your newest circuit indicates it to be a PNP. This is why I am not following what you mean in that modification.Please see my previous post because I updated it to say that my breadboard test failed, despite the fact that circuit simulated fine. That has been consistent throughout all these tests when it comes to using my Function Generator. But this far, my in-vehicle tests have matched the Function Generator.

author: JDW
author_rank: Frequent Contributor
timestamp: March 31, 2023, 08:08:45 am
content: Quote from: Damianos on March 31, 2023, 07:56:04 amJust to be clear, you are asking a question that pertains tomy earlier post here, and specifically to the partial vehicle schematic in my first attachment named "Toyota_SpeedPulse_Schem.png".Yes, it would appear the signal in the vehicle is coming from an open-collector source, which is what that official document shows.If by "measuring instrument" you mean the vehicle's "Engine Control Computer" and "Radio & Display Receiver ASSY" also shown in that same attachment, then yes, there appears to be a diode's cathode facing the source of the signal, with the anode of the same diode attaching to a pull-up resistor, and then going off to who knows where.While I have not stuck the same diode and pull-up (although pulling up to what voltage, and what value pull-up isn't mentioned) between my scope probe and the signal source, the fact remains I measured the signal source to be a 500mV 0-pk waveform.

author: peter-h
author_rank: Super Contributor
timestamp: March 31, 2023, 08:48:50 am
content: QuoteStrictly on the topic of how to build a +250mV comparator, without a negative rail available, this cannot be done with an NPN transistor if you want a relatively low source loading i.e. you want to drive thebaseof the transistor. Well, it can if you use two more resistors, and rely on the +V rail being stable. IIRC, LT did some op-amps that way, which worked way below the -VE rail.If you don't mind a bit more loading then you can do what used to be called a common-base config, like this. This should swing down to about +0.4V. If you want it to swing lower then you will need more bits.But if your signal is from an O/C source then your 0 to +500mV spec does not make sense; you just need a pullup resistor and you are done

author: Damianos
author_rank: Frequent Contributor
timestamp: March 31, 2023, 10:05:19 am
content: Quote from: JDW on March 31, 2023, 08:08:45 amThe voltage to pull-up depends on your device, whatever it uses (5V or 3V or 12V...). The value of the resistor must be high enough to don't load "hard" the source and low enough to overcome interference and noise in a car environment! A 5kΩ to 10kΩ I think is a good start value to try. It may be needed some protection to the input of your device (at least a diode from ground to the input node, to avoid negative spikes. The diode can be the "usual" 1N4148 or something similar.

author: errorprone
author_rank: Contributor
timestamp: March 31, 2023, 01:04:37 pm
content: Using the transistor in a common emitter configuration may be better than common base since the input impedance is higher but the signal will be inverted. A source degeneration resistor will add feedback and decouple the gain from beta. A coupling capacitor is needed but a electrolytic type can be used. It’s also called a class A amplifier, just set the gain so it saturated.https://www.electronics-tutorials.ws/amplifier/amp_5.html.If ac coupling is not desired then a two transistor amplifier such as a long tail pair would work but at that point it’s just building the input stage of an opamp using discrete parts.https://en.m.wikipedia.org/wiki/Differential_amplifier#Long-tailed_pair

author: PCB.Wiz
author_rank: Super Contributor
timestamp: April 01, 2023, 03:00:45 am
content: Quote from: peter-h on March 31, 2023, 07:11:49 amThat works, but only has a 0.75V logic out swing. Probably not MCU compatible

author: PCB.Wiz
author_rank: Super Contributor
timestamp: April 01, 2023, 03:14:39 am
content: Quote from: JDW on March 31, 2023, 05:25:03 amI updated my earlier post with other R values, that shift the threshold to a more roughly mid-point of your claimed 500mV swing.Addit: Updated with numbers for roughly 250mV thresholdR1 = 3k3 R4=3k3 => Transfer : 51mV = 3V, 75mV = 0.8VR1 = 5k6 R4=3k3 => Transfer : 117mV = 3V, 140mV = 0.8VR1=10k R4=3k3 => Transfer 236mV = 3V 260mV = 0.8VR1=12k R4= 4k7 => Transfer 251mV = 3V 275mV = 0.8VQuote from: JDW on March 31, 2023, 05:25:03 amDoes your function generator have a triangle wave ability ?Attached is the ramp transfer of the last table line values, Vin sweeps 0-500mV and Logic out drops

author: peter-h
author_rank: Super Contributor
timestamp: April 01, 2023, 09:35:12 am
content: QuoteOnly if you are driving quite a load - around 1.5k to GND?Reduce the 10k to 2k2, for example.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: April 01, 2023, 11:08:37 pm
content: Quote from: peter-h on April 01, 2023, 09:35:12 am?You have a single PNP transistor with the emitter clamped at 0.75VIt is impossible for that collector to pull higher than 0.75V-Vcesat.

author: JDW
author_rank: Frequent Contributor
timestamp: April 03, 2023, 01:54:42 am
content: Quote from: PCB.Wiz on April 01, 2023, 03:14:39 amYes. To view all its selectable functions, view photo of function generator below.My attachments below show how your circuit simulates fine, but also show how it fails when breadboarded and tested on the bench — constant 60mV (basically GND) output instead of a waveform. I am using a pair of2SC1815NPN transistors instead of the NPN part number you specified because I don't have your part in my inventory.When viewing the attachment named "ScopeScreen.jpg" you can see that Channel-1 is resting at 60mV, which is basically ground. No pulsing whatsoever there. Channel-1 is measuring the Collector of Q1, which is the Yellow waveform in the simulation attachments. So again, it simulates fine, but it bench tests 0v. Scope Channel-2 is directly measuring the Function Generator output, which matches what the simulation and the car show, swinging between 500mV and GND.You specified a 3.3kΩ resistor between the signal source and the Emitter of Q2, and I basically have that: 1kΩ + 220Ω + 2kΩ. I have it structured that way because the 1kΩ and 220Ω and BAT54 are an existing part of my circuit. I merely added a 2kΩ resistor to basically get the 3.3kΩ resistor your circuit specified.Lastly, instead of the 1.5MΩ resistor shown in the simulator attachments below, I have that point connected to an actual PIC MCU input pin in my bench test. And yes, that PIC pin is indeed configured correctly a digital I/O input, not mistakenly as an output or an ADC input. And I know it works fine too when a proper square wave of 0 to 5v is attached there. The entire problem is that the car outputs a 500mV 0v-pk waveform, and that amplitude is too small, and no circuit I've built thus far has given my MCU a readable squarewave.Comparator parts are still in the mail, so I am just playing the waiting game right now.

author: Kim Christensen
author_rank: Super Contributor
timestamp: April 03, 2023, 02:31:28 am
content: Quote from: JDW on April 03, 2023, 01:54:42 amTry adjusting the offset on the function generator counter-clockwise to shift the DC offset a bit lower to see if it starts working or until the voltage on Channel-1 rises. I know this isn't how you want it to work, but it'll help us figure out what's going wrong.

author: JDW
author_rank: Frequent Contributor
timestamp: April 03, 2023, 02:37:37 am
content: Quote from: Kim Christensen on April 03, 2023, 02:31:28 amThe 60mV DC offset has nothing to do with the function generator and exists even with the function generator completely removed from the circuit. Again, the oscilloscope tap point in my breadboard circuit is the collector of Q1, which leads to (1) an input pin on my PIC MCU, and (2) to a 10kΩ pull-up that goes to a solid 5.0V.The output from the function generator perfectly matches the car, and I can assure you that when the function generator is connected directly to the scope (and not a part of this test circuit I built), it swings between 0.00v and 500mV just fine. There is no DC offset from 0v.

author: Kim Christensen
author_rank: Super Contributor
timestamp: April 03, 2023, 03:50:43 am
content: You've missed my point. Make the function generator output waveform swing from -100mV to +400mV... Or maybe -200mV to +300mv...As an experiment.

author: JDW
author_rank: Frequent Contributor
timestamp: April 03, 2023, 05:39:23 am
content: Quote from: Kim Christensen on April 03, 2023, 03:50:43 amExperiment with DC offset done precisely as you directed.RESULT: Measurements exactly the same as I reported in my previous post.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: April 03, 2023, 07:13:32 am
content: Quote from: JDW on April 03, 2023, 01:54:42 amGreat, then use triangle setting and sweep the voltage from firstly a large range, like -5V to +5V, (10V p-p triangle) and confirm the output does changesomewherein that spanThen, you can 'zoom in' using offset and gain to check the actual switching point.Quote from: JDW on April 03, 2023, 01:54:42 amGood if you have simulate ok, you have a construction problem.I see that has many HFE choiceshFE VCE=6.0V, IC=2.0mA (2SC1815) 70 700hFE VCE=6.0V, IC=2.0mA (2SC1815-O) 70 140hFE VCE=6.0V, IC=2.0mA (2SC1815-Y) 120 240hFE VCE=6.0V, IC=2.0mA (2SC1815-GR) 200 400hFE VCE=6.0V, IC=2.0mA (2SC1815-BL) 350 700BC847B hFE 200 450So the 2SC1815-GR should be very close to BC847B, others less so.If your symptom is 'stuck low' you may have miss matched transistors, here are some more resistor values I tabulated above, that shift the threshold.When you have this HW working with the -5V-+5V triangle signal, you can fine tune the resistor values to get an appx 250mV threshold for your 500mV? actual signal.

author: JDW
author_rank: Frequent Contributor
timestamp: April 03, 2023, 08:21:58 am
content: Quote from: PCB.Wiz on April 03, 2023, 07:13:32 amIf I completely kill the DC offset on my function generator and allow the generated waveform to swing above and below 0 V, which is not what I am seeing on the car side mind you, then I can just start to detect the inverted waveform at the output on my scope, be that a square wave or triangle wave, when the peak to peak amplitude of the function generator is 1.36V. If I then increase the amplitude to 1.5 V, the output amplitude then becomes the same at 1.5 V. Even tiny increases to the function generator’s amplitude above 1.5 V will result in large amplitude increases on the output waveform. But as I start to increase the DC offset on the function generator, so as to match what I see on the car side (a 0v to peak square wave), the output waveform rapidly drops to zero.In other words, the reasons I have not been able to get your circuit to work until now are twofold:1) Until now, I’ve been using a DC offset to make sure the waveform appears with its low side at 0 V, but that results in no output waveform.2) Until now, I’ve been using a 500 mV p-p waveform because that is what the amplitude is on the car side. But even if I kill the DC offset, a 500 mV p-p amplitude will not generate an output.What are your thoughts in light of this?

author: peter-h
author_rank: Super Contributor
timestamp: April 03, 2023, 08:37:35 am
content: No, it is NPN. Maybe wrong post?https://www.eevblog.com/forum/microcontrollers/amplify-500mv-0-pk-square-wave-to-gt2v-for-pic-mcu/msg4788365/#msg4788365

author: JDW
author_rank: Frequent Contributor
timestamp: April 03, 2023, 11:02:48 am
content: Quote from: peter-h on April 03, 2023, 08:37:35 amMyearlier postis perhaps being called into question here. Suffice it to say, what you see in my simulation attachments is what I built, and as you can see, I am using exclusively NPN transistors. I wrote that earlier post because the hand-scratch looked like a PNP to me, but since no specific reply was given to me about that, I ignored that particular hand-scratched schematic and just built what you see in my simulation attachments.I hope that is clear.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: April 03, 2023, 09:15:48 pm
content: Quote from: JDW on April 03, 2023, 08:21:58 amThat's good, so you have gain and a threshold.You can adjust the threshold by the resistor ratios. If you have a meter that can check hFE, try for some in the BC847B region.See the table of resistors / thresholds, in the circuit of #70

author: JDW
author_rank: Frequent Contributor
timestamp: April 03, 2023, 09:28:32 pm
content: Quote from: PCB.Wiz on April 03, 2023, 07:13:32 amWhen you say "mismatched," do you mean two wildly different HFE values?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: April 03, 2023, 09:32:52 pm
content: Quote from: JDW on April 03, 2023, 09:28:32 pmYes, the threshold spice gives assumes roughly matched transistors. With a triangle wave injection your circuit is now working, it then becomes a matter of setting the thresholdIf Vbe or hFE are too different, will move the operating point slightly.Did you try the ~250mV threshold resistor values ?

author: JDW
author_rank: Frequent Contributor
timestamp: April 03, 2023, 09:54:56 pm
content: Quote from: PCB.Wiz on April 03, 2023, 09:32:52 pmI am away from the bench right now, but I will try it later today. Thank you!

author: JDW
author_rank: Frequent Contributor
timestamp: April 04, 2023, 01:46:58 am
content: Quote from: PCB.Wiz on April 03, 2023, 09:32:52 pmI measured the HFE values of both transistors in my breadboard circuit, and both are above 200, as shown in the attachments below. Specifically…Q1 = 222Q2 = 241And while the 2 HFE values are not identical, they are perhaps close enough to where it shouldn’t really matter.I also bench-tested the two resistor values you proposed in your attached schematic inReply #70. Specifically…R1 = 12kR4 = 4.7kBut there’s not really any change at all. As I said in my earlier post, the problem is that when I use the DC offset adjustment of my function generator to make the waveform to be above 0 V, the output of your circuit basically goes to zero. You can see this in two attachments below. With the waveform entirely below 0 V, and the High level right at 0 V, I do get an output of about 2V zero to peak. But when I raise the HI part of the waveform to just a little bit above 0V, using the DC offset adjustment of my function generator, the output all but vanishes.Why am I trying to make the output waveform of my function generator to be above 0 V? Because the car side waveform has its low side at 0 V and it’s high side at +500 mV. As such, it is necessary for me to replicate the car side waveform on my function generator for my bench test to have any meaning.Any further thoughts would be appreciated. Thank you.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: April 04, 2023, 03:32:27 am
content: Quote from: JDW on April 04, 2023, 01:46:58 amThe output should swing to close to 5V, so something is incorrect. Maybe resistor values are incorrect ?With the input simply grounded, (150K 12k 4k7) Spice givesVbb = 680.33099mVVbase = 344.21611mV so that means Q1 is comfortably OFF.When the input lifts to 258mV, the collector has dropped from 5V to ~2.5V

author: Kim Christensen
author_rank: Super Contributor
timestamp: April 04, 2023, 04:35:27 am
content: Quote from: PCB.Wiz on April 04, 2023, 03:32:27 amI suspect that the OP has connected R3 (150K) to the collector of Q2 instead of the base.

author: JDW
author_rank: Frequent Contributor
timestamp: April 04, 2023, 05:56:11 am
content: Quote from: PCB.Wiz on April 04, 2023, 03:32:27 amResistor values are absolutely correct. I don’t rely on color codes. I measure each and every resistor to know absolutely what the resistance value is.Since you made no mention of a load resistor, I tested without a load resistor and with a load resistor that measures 1.6M ohm. The output values I measured we’re very similar, so the numbers I will report below were measured without any load resistor at all.With the input grounded, the output is 5.01 V, as measured on my Fluke 8845A.I put a Kikusui PMC35-3 variable power supply on the input so that I could slowly increase the voltage from 0 V to your recommended 250 mV. Because this is an analog power supply, I cannot get exactly 0.25000 V. However, I was able to increase it to 0.252 V, and with that voltage on the input, the output falls only slightly to 4.851 V.However, if I continue to increase the input voltage to 326.3 mV, the output will drop to 2.553 V. In other words…Input=0v, Output=5.0VInput=252mV, Output=4.851VInput=326.3mV, Output=2.553VWhen I simulate that same circuit, I get this…Input=0v, Output=5.0vInput=252mV, Output=3.25vInput=326.3mV, Output=90.94mVAt this point, I'm not sure we are really making progress. The only thing I can suggest is that I purchase adual BC847Bto ensure the hFE of both NPNs is the same and then I can breadboard that.I found8 part numbers in stock at DigiKeyfrom reputable vendors.Please let me knowwhich part number I should buy, and I will go proceed with that. Of course, I will also be testing the comparators when they arrive as well.

author: JDW
author_rank: Frequent Contributor
timestamp: April 04, 2023, 06:06:07 am
content: Quote from: Kim Christensen on April 04, 2023, 04:35:27 amYour suspicion is wrong. R3 is correctly breadboarded between Q2 Base and +5V as shown in the attachment below. (2SC1815 is ECB.)

author: PCB.Wiz
author_rank: Super Contributor
timestamp: April 04, 2023, 07:41:48 am
content: Quote from: JDW on April 04, 2023, 05:56:11 amThat's good, you have found a 50% threshold point.It's about 66mV higher than my sim, which is not massive.Increase that Biased DC Vin slightly more, and it should give you the 0.5V point - useful spec points are 50% and the 10%/90% points.Quote from: JDW on April 04, 2023, 05:56:11 amYou could get BC846B / BC847B for lowest cost and the BCM846B / BCM847B are the Nexperia / Diodes matched pair specs.I'm not sure you really need the tight matching those give (2mV on Vbe) but you could try some of each.Single package give you same-vendor/batch/date code and same temperature, which is a good improvement over separate packages.Addit: I skewed the gain in spice, by selecting a badly-wrong-suffix part and it moves the threshold roughly +/- 25mVSkew Q2=BC847A, Q1=BC847C = 233.33334mV @ 50%Match Q2=BC847B, Q1=BC847B = 258.26559mV @ 50%Skew Q2=BC847C, Q1=BC847A = 284.01084mV @ 50%

author: JDW
author_rank: Frequent Contributor
timestamp: April 04, 2023, 08:27:16 am
content: Quote from: PCB.Wiz on April 04, 2023, 07:41:48 amI will buy a few of these two part numbers...BC847BS,135BC847BS,135 (matched pair)

author: Kim Christensen
author_rank: Super Contributor
timestamp: April 04, 2023, 03:15:42 pm
content: Quote from: JDW on April 04, 2023, 01:46:58 amQuote from: JDW on April 04, 2023, 05:56:11 amThose two tests have contradictory results.So if you also connect the scope, while doing the static DC test with the power supply and voltmeter, do the readings on the scope and voltmeter agree when measuring both the input and output?If you used your signal generator as the input source at a really slow frequency (0.2Hz), what does the DC voltmeter show vs the scope?

author: JDW
author_rank: Frequent Contributor
timestamp: April 05, 2023, 04:11:49 am
content: Quote from: Kim Christensen on April 04, 2023, 03:15:42 pmI am away from the bench today, will spend the day at the hospital tomorrow to deal with my health, and then I am still playing the waiting game with parts. When I am back at the bench with parts in hand, I shall reconfirm all connections with my scope and multiple meters attached.My humble thanks to all of you who have kindly provided input thus far. It has been a helpful, learning experience.