0
\$\begingroup\$

There are signals like below picture inputted to MCU STM32f103: (Offset DC about 800mV, Vmax = 2.4V, f = 66 Hz)

enter image description here

I want to change it to a squar wave from 0V to 3.3V being accepted voltage range for my MCU. How I can implement it? Using a schmitt trigger implemented by an op amp? Can you please provide me a schematic?

EDIT:
Based on ChrisStratton`s comment:
Cost and power do not matter. I am going to obtain frequency of signal by MCU Timer/Counter. In fact my ultimate goal is to have the frequency to calculate speed. One hertz could be an accepted precision and the frequency is less than 1 KHz. Actually the first thing I tried was AC coupling being able to remove DC offset. However, the amplitude was not what I want. To sum up, I need to have a square wave with the same frequency and 0 V to 3.3 V amplitude.

\$\endgroup\$
3
  • \$\begingroup\$ What properties of the signal do you need to recover? If timing, with how much precision? Do you need to sleep to save power? If the requirement is lenient using the adc and software hysteresis could be an option. If the leading edge is reliably sharp AC coupling and a blanking time on retrigger could work. A meaningful answer would require details and goals not presented - do you want universal reliability? Minimum cost? Minimum.power? \$\endgroup\$ Aug 24, 2019 at 15:18
  • \$\begingroup\$ @ChrisStratton Cost and power do not matter. I am going to obtain frequency of signal by MCU Timer/Counter. In fact my ultimate goal is to have the frequency to calculate speed. One hertz could be an accepted precision. Actually the first thing I tried was AC coupling being able to remove DC offset. However the amplitude was not what I want. To sum up, I need to have a square wave with the same frequency and 0 V to 3.3 V amplitude. \$\endgroup\$
    – Pana
    Aug 24, 2019 at 16:16
  • \$\begingroup\$ No, your application does not require a square wave, it requires recovering timing. You could do that with the ADC without further conditioning the signal electrically. You could for example look for a positive change of a certain amount within a small number of samples. You could then use that to adjust a software PLL. \$\endgroup\$ Aug 24, 2019 at 18:31

3 Answers 3

4
\$\begingroup\$

For standard IO the STM32F103 datasheet section 5.3.13 says:

  • \$ V_{IL(max)} = 0.28 (V_{DD} -2 \ \text V) + 0.8 \ \text V \$. For a 3.3 V supply this is 1.16 V.

  • \$ V_{IH(min)} = 0.41 (V_{DD} -2 \ \text V) + 1.3 \ \text V \$. For a 3.3 V supply this is 1.83 V.

Offset DC about 800mV, Vmax = 2.4V.

        0         1         2         3  3.3 V
        |    .    |    .    |    .    |  |     
GPIO:   |           ===.===              |
Signal: |       =================        |

Since your signal low < GPIO VIL min and your signal high > GPIO VIH max I think you can feed your signal straight in.

Additional component count: 0.


schematic

simulate this circuit – Schematic created using CircuitLab

Figure 2. A comparator with auto-reference adjust.

The idea here is that C1 will charge to a reference voltage a little higher than the low signal due to the duty-cycle of the signal. R3 helps pull it a little higher but may not be required.

Most comparators have open collector outputs so R1 has been added but the GPIO internal pull-up may suffice.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Yes, you are right. However, in my circuit there are some conditions that do not conform to MCU logical range and I need to reassure myself. So please consider that I want to convert it to a square wave. \$\endgroup\$
    – Pana
    Aug 24, 2019 at 11:40
  • 3
    \$\begingroup\$ You need to make that clear in your question to avoid wasting folks' time. \$\endgroup\$
    – Transistor
    Aug 24, 2019 at 11:43
  • 2
    \$\begingroup\$ This is a relatively bad idea unless the behavior of the input is known to be reliably consistent. Without a solid explanation of the source of the offset it's level cannot be relied upon to stay safely low. \$\endgroup\$ Aug 24, 2019 at 15:04
  • 1
    \$\begingroup\$ Sure, but there was nothing in the question to indicate that a stable source was not the case. A comparator will suffer the same problem is the \$ V_{IL(max)} > V_{IH(min)} \$. One could try using a very low-pass filter for the signal and use that as the reference. \$\endgroup\$
    – Transistor
    Aug 24, 2019 at 15:16
2
\$\begingroup\$

a much easier way would be a simple schmitt trigger like you first suggest, you can use an op amp to do it, it just changes in name to a comparator with hysteresis,

schematic

simulate this circuit – Schematic created using CircuitLab

Edit: supply voltage would be 0 and 3.3V, the 100K controls the amount of hysteresis, right now its quite low, but should be suitable

Edit2: Changed to non inverting, circuit also simulated here with falstads,

Falstads Circuit Link

\$\endgroup\$
8
  • 2
    \$\begingroup\$ The TL081 requires a minimum supply of 10V. Also, opamps can be slow when used as comparators. Better to use an actual comparator instead. Many operate at 3.3V, and some of them have built-in hysteresis. And your circuit inverts the signal, which may or may not matter to the OP. \$\endgroup\$
    – Dave Tweed
    Aug 24, 2019 at 11:15
  • \$\begingroup\$ @Reroute I simulated your schematic by means of Multisim but i get only a constant DC voltage in output. \$\endgroup\$
    – Pana
    Aug 24, 2019 at 11:15
  • \$\begingroup\$ @DaveTweed can you please explain your idea? \$\endgroup\$
    – Pana
    Aug 24, 2019 at 11:17
  • \$\begingroup\$ @Pana: What do you mean? You can buy ICs called "opamps" and you can buy ICs called "comparators" -- I'm saying you want the latter, not the former. But the point is moot, given @Transistor's analysis. \$\endgroup\$
    – Dave Tweed
    Aug 24, 2019 at 11:18
  • \$\begingroup\$ I was not successful in simulating it again. Is it because I use OP07CD instead of OA1 TL081 in my simulation? \$\endgroup\$
    – Pana
    Aug 24, 2019 at 11:56
1
\$\begingroup\$

According to the valuable answers and comments, including Transistor's ones, I achieved to figure out my issue by means of LM2903P comparator. This is the schematic having enabled me to tackle it:

enter image description here

and this is the output I got:

enter image description here

Hoping help somebody!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.