I know several topics already talks about this but I didn't find my answer yet. Is it possible to convert a sine wave to a square wave only with a MCU ? Both wave are only a matter of changing frequency. Is the MCU capable of flag the top and bottom wave for example ? In my case I would like to use a STM32. My goal is quite straiht forward, when the sine wave is at top, I want a top square, and when at bottom, at bottom on the square.

  • \$\begingroup\$ What do you mean by "convert"? \$\endgroup\$
    – Eugene Sh.
    Feb 27, 2018 at 16:47
  • \$\begingroup\$ My tool generate a sine wave and I want to read this sine wave with the MCU in order to generate a square wave \$\endgroup\$
    – vib
    Feb 27, 2018 at 16:48
  • 1
    \$\begingroup\$ UM.. "Is the MCU capable of flag the top and bottom wave for example ?".... Yes! ... Next! \$\endgroup\$
    – Trevor_G
    Feb 27, 2018 at 16:53
  • 4
    \$\begingroup\$ An analog coparator would be much more appropriate, I think. \$\endgroup\$ Feb 27, 2018 at 17:21
  • 3
    \$\begingroup\$ There are plenty of MCUs that have on-board analog comparators. As to your particular one, you can read the datasheet to find out if it has such a function. Otherwise add an external one and, in any case, bias it appropriately so that the sine wave stays within the input range (usually less than or equal to the power supply rails). \$\endgroup\$ Feb 27, 2018 at 18:02

1 Answer 1


Well, your question is pretty vague so this may not be a good answer. You can run it into a digital input and program the MCU to have an output go high when the input is high and go low when the input is low. This solution assumes that:

  • The sine wave meets the VIH and VIL requirements of the MCU inputs.
  • The sine wave frequency is << than the MCU clock.
  • Your application can handle the clock being delayed.
  • Your application can handle a slightly off duty cycle.

From the information given, I don't know if these requirements are met.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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