Author Topic: Amplify 500mV 0-pk square wave to >2V for PIC MCU  (Read 6087 times)

0 Members and 1 Guest are viewing this topic.

Offline JDWTopic starter

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: jp
Amplify 500mV 0-pk square wave to >2V for PIC MCU
« on: March 27, 2023, 06:38:34 am »
I need to get a PIC16F1503 MCU to read a 500mV 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.
 

Offline nvmR

  • Regular Contributor
  • *
  • Posts: 75
  • Country: il
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #1 on: March 27, 2023, 06:41:18 am »
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.
 

Offline PSR B1257

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #2 on: March 27, 2023, 06:51:41 am »
Quote
What is the easiest and most straight-forward way to amplify the 500mV 0-pk squarewave to at least 2V 0-pk
Why amplify at all?
I would consider the build in ADC or comparator.
« Last Edit: March 27, 2023, 07:17:12 am by PSR B1257 »
In theory, there is no difference between theory and practice. But, in practice, there is.
 
The following users thanked this post: Zero999

Offline redkitedesign

  • Regular Contributor
  • *
  • Posts: 111
  • Country: nl
    • Red Kite Design
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #3 on: March 27, 2023, 07:09:54 am »
The problem is that 500mV voltage level is so low I can't even switch a BJT or MosFET with it.

Of 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.

 
The following users thanked this post: mycroft, JDW

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14203
  • Country: de
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #4 on: March 27, 2023, 07:34:51 am »
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.
 

Offline JDWTopic starter

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: jp
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #5 on: March 27, 2023, 07:35:45 am »
The problem is that 500mV voltage level is so low I can't even switch a BJT or MosFET with it.

Of 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.

I 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.

1748165-0

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.
 

Offline JDWTopic starter

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: jp
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #6 on: March 27, 2023, 08:25:28 am »
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 ]
« Last Edit: March 27, 2023, 08:29:54 am by JDW »
 

Offline PSR B1257

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #7 on: March 27, 2023, 09:06:46 am »
Have you confirmed the pin-out of the transistor?

Quote
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.
That would be a good idea. The output-type is a relevant information.
In theory, there is no difference between theory and practice. But, in practice, there is.
 

Offline JDWTopic starter

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: jp
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #8 on: March 27, 2023, 09:24:33 am »
Have you confirmed the pin-out of the transistor?

Yes, 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.
 

Online tszaboo

  • Super Contributor
  • ***
  • Posts: 7388
  • Country: nl
  • Current job: ATEX product design
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #9 on: March 27, 2023, 10:01:23 am »
Quote
What is the easiest and most straight-forward way to amplify the 500mV 0-pk squarewave to at least 2V 0-pk
Why amplify at all?
I would consider the build in ADC or comparator.
Yeah, 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 datasheet
https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/40001607D.pdf

 

Offline PSR B1257

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #10 on: March 27, 2023, 10:15:04 am »
Quote
output of a Function Generator for this bench test.
Seem'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.
In theory, there is no difference between theory and practice. But, in practice, there is.
 
The following users thanked this post: JDW

Offline bobaruni

  • Regular Contributor
  • *
  • Posts: 156
  • Country: au
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #11 on: March 27, 2023, 02:52:18 pm »
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.
« Last Edit: March 27, 2023, 03:20:29 pm by bobaruni »
 

Offline JDWTopic starter

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: jp
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #12 on: March 28, 2023, 02:16:10 am »
...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 ...

Thank 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.

1748699-0 

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.
 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1926
  • Country: us
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #13 on: March 28, 2023, 02:59:40 am »
The comparator in the MCU is there for a reason. It's the simplest, easiest, cheapest, and most reliable of the options discussed here.
 
The following users thanked this post: Kim Christensen

Offline redkitedesign

  • Regular Contributor
  • *
  • Posts: 111
  • Country: nl
    • Red Kite Design
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #14 on: March 28, 2023, 07:33:33 am »
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. 

You 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.
 

Offline JDWTopic starter

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: jp
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #15 on: March 28, 2023, 08:25:16 am »
You 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.

Adding 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.

The comparator in the MCU is there for a reason. It's the simplest, easiest, cheapest, and most reliable of the options discussed here.

I 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, the TVL1811 (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.

 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1926
  • Country: us
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #16 on: March 28, 2023, 02:23:21 pm »
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?
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14203
  • Country: de
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #17 on: March 28, 2023, 03:28:57 pm »
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.
 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1926
  • Country: us
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #18 on: March 28, 2023, 03:36:20 pm »
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.
 

Offline redkitedesign

  • Regular Contributor
  • *
  • Posts: 111
  • Country: nl
    • Red Kite Design
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #19 on: March 28, 2023, 07:15:29 pm »
Adding a 1kΩ pulldown at the signal source simulates fine, but a bench test shows the exact same scope readings I showed you before.

Well, 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.

Quote
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.

Technically, 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.
 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1926
  • Country: us
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #20 on: March 28, 2023, 07:23:35 pm »
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.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #21 on: March 28, 2023, 07:26:46 pm »
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.
Don'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.

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.
Speed sensors are typically magnetic pickup sensors so the 500mVpp seems fine to me.
« Last Edit: March 28, 2023, 07:30:13 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1926
  • Country: us
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #22 on: March 28, 2023, 07:40:42 pm »
Speed sensors are typically magnetic pickup sensors so the 500mVpp seems fine to me.
True 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 if something changes....
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #23 on: March 28, 2023, 07:53:19 pm »
Speed sensors are typically magnetic pickup sensors so the 500mVpp seems fine to me.
True 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 if something changes....
Yep. We shouldn't rule out the OP has the probe attenuation wrong by a factor of 10. Impossible to tell from behind the screen.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline JDWTopic starter

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: jp
Re: Amplify 500mV 0-pk square wave to >2V for PIC MCU
« Reply #24 on: March 29, 2023, 02:58:19 am »
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



 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf