Shop OBEX P1 Docs P2 Docs Learn Events
BS2x "FREQOUT" To Square Wave Converter — Parallax Forums

BS2x "FREQOUT" To Square Wave Converter

hyperlinearhyperlinear Posts: 4
edited 2013-11-08 09:49 in BASIC Stamp
Having found myself frustrated as many others have over how to use the "FREQOUT" directive as a frequency source, I searched the net, read the Parallax forums and even spoke with Parallax engineers on the subject. The final word at every turn was to NOT use it for anything more than some audio purposes or using it to generate IR signals, although some people have suggested a variety of "it might work if ..." ideas. The common suggestion is to use filtering to remove some of the high frequency components and then run that signal through an inverter or schmidt trigger to "square up the signal". Let's start with what we have here. The image below is indicative of the "frequency soup" that comes out of a BS2x pin (in this example a BS2p40) using the "FREQOUT" directive at approximately 700Hz ...


photo 1.JPG


Notice that while it sort-of looks like a square wave, it is riddled with higher frequency components. Unless you're planning on shoving this to an audio amp or IR modulator, trying to make use of this signal in any timing capacity is pointless. A simple RC circuit comprised of 2 resistors and 2 capacitors in a low-pass configuration will go a long way in making this signal more "sine-centric". Below is the same signal source as above, but this time run through an RC filter ...

photo 2.JPG


Notice that the resulting signal looks like a rather useable sine wave. Also note the position of the negative-going part of the signal as referenced to ground - it is floating ABOVE ground. Because of this, a simple inverter or schmidt trigger will NOT work, since the signal is ALWAYS above ground potential and appears to be always "on". What is needed is a circuit that can resolve this floating level at about 2-2.5VDC. A zero-crossing/comparator circuit is much more suitable for the job. The circuit below detects zero-crossing at a much higher level than ground potential. By referencing the inverting input above ground potential, it is possible to follow the incoming signal and square it up ...

Schematic Design_ freqout_converter.jpg


The actual output of the above circuit with ~700Hz "FREQOUT" directive is shown below ...

photo 3.JPG


What we have now is a fairly nice square wave suitable for providing a stable reference pulse or driving other circuits. Note that the RC values of the filter may need to be adjusted to your particular application, as well as the inverting input voltage-divider values depending on anything other than 5VDC as circuit supply voltage. Also, other op amps will work but some tinkering with values might be needed.

I hope this helps anyone that has found frustration in generating reference frequencies out of the BS2x without going through tons of coding and calculations based on command execution timing.
640 x 336 - 121K
640 x 294 - 105K
640 x 272 - 88K
Sign In or Register to comment.