# Want to build a square wave generator

#### MattStrike

Joined Jun 12, 2010
14
I would like to build a square wave generator:
50% duty cycle
0v to 5v peak to peak
adjustable frequency from 50Hz to 300Hz by controlling an input voltage from about 0vdc to 5vdc.

The tricky part for me is making the frequency adjustable. The input voltage won't generally go below .05vdc or above 4.95vdc for this control. .05v will ideally generate 50Hz, and 4.95v generate 300Hz, but want to learn enough to be able to tune this as the control voltage may not be perfect in the field.

Edit: I've built a generator using a 555 timer before using a schematic on this forum.

Thanks!

Last edited by a moderator:

#### crutschow

Joined Mar 14, 2008
26,838
Try using a (CD)4046 PLL circuit. It has a linear VCO that should do what you want. That's a lot easier than trying to do it with a 555.

#### wayneh

Joined Sep 9, 2010
17,071
That's a lot easier than trying to do it with a 555.
And just in case anyone thinks about using the control pin 5 - it won't give enough range of adjustment. Maybe 60-240Hz at the max. The duty cycle will change a lot also. If the OP could live with those problems, manipulating pin 5 could become an option.

#### THE_RB

Joined Feb 11, 2008
5,438
An old solution is to use a typical 555 astable with a pot to generate the varying frequency x2, then put the signal through a flip-flop, this gives freq x1 with exactly 50% duty squarewave.

#### thatoneguy

Joined Feb 19, 2009
6,359
An old solution is to use a typical 555 astable with a pot to generate the varying frequency x2, then put the signal through a flip-flop, this gives freq x1 with exactly 50% duty squarewave.
That's a cool trick.

Though I can't think of one to vary the frequency from 40 to 300Hz from an incoming voltage. Digital resistors don't have that sort of range.

I'd have to go with VCO + PLL on this over a 555.

#### hiohsilver

Joined Jul 18, 2011
1
did you consider using a XR2206 IC. Check out the specs on it.

#### THE_RB

Joined Feb 11, 2008
5,438
...
Though I can't think of one to vary the frequency from 40 to 300Hz from an incoming voltage.
...
Thank you Thatoneguy, I missed the requirement for voltage controlled frequency.

The range of 40-300 Hz should be easy enough with a simple comparator VCO and adjusting the threshold voltage, but of course that simple method would not give a linear voltage->freq conversion.

#### MattStrike

Joined Jun 12, 2010
14
I think I will need some help getting started with the PIC. I am familiar with programming, nothing complicated (VB and Java).

How does a PIC work? What supporting circuitry would I need? What kind of costs are involved? The pickaxe seems like it would be a good choice, but do these things have to be connected to a PC all the time to work or something?

I think I'd like to build one with the PIC, and one using component, then compare them side by side.

I couldn't find a datasheet on the 4046 PLL circuit mentioned earlier. Who makes the chip?

#### thatoneguy

Joined Feb 19, 2009
6,359
A PICKit 2 ($35)+ 44 pin Demo board($25) or 28 pin board ($25) BoostC and Mikro C are compilers that have very generous limitations for a beginner, you won't bump into the 2k Word code "wall" anytime soon with small projects. The PICs themselves need 5 wires hooked up (Vpp, V+, GND, PGC, PGD), the PGC and PGD are I/O pins that can be used when not programming. This is for ICSP Programming and In Circuit Debugging, which is straightforward and simple if you don't try to save money by getting a "clone" or DIY programmer. Once programmed, the program is semi-permanent on the IC, so you can plug it in and use it as is, and it starts running the program when power is applied. They have an internal Oscillator, so the support parts are essentially 1 0.1uF cap between Vdd and Vss to keep the power "clean". The PLL Oscillator is internal, so speeds up to 48Mhz can be obtained without a crystal, though I find 8-20Mhz fast enough for most purposes. The PICAXE uses a bootloader system, so you don't need the PICKit 2, when you turn it on, it checks to see if the data cable is attached, and if so, downloads the new program. So there's a short delay on boot with the PICAXE, but only 1/10th of a second maybe. Cable + Instructions + PICAXE kit is about$8 and is programmed in BASIC, which is a free compiler for the PICAXE series.

#### MattStrike

Joined Jun 12, 2010
14
Sorry it's been a while...

The pickaxe kit is now $30 unless I'm looking in the wrong spot. Once I get the PIC, should I start a new thread when I'm ready to begin programming when I have (many) questions? #### thatoneguy Joined Feb 19, 2009 6,359 All you really need is Here I suppose you could get the full starter kit, but I'd just buy a couple 20x2 PICAXE processors and a dowload cable, put it together on a solderless breadboard for around$18 w/the X2, which is a very nice PIC with lots of peripherals.

For \$12 more, having a board that is known to work, the book, and programming cable may be worth it for you if wary.

The site linked above is the "Main" PICAXE distribution site, and they are speedy with shipping.

#### MattStrike

Joined Jun 12, 2010
14
Ok thanks!

Would I need the 20-pin microcontroller for this simpler project? I figured there would only be 1x input and 1x output so the smaller 8-pin chip would work, but I know what happens sometimes when I start thinking.

Whats the difference between the 20X2 and the 20M2?

#### PaulEE

Joined Dec 23, 2011
423
Problem is I don't have any experience with programming a PIC (yet). I am willing to learn though. The simpler/smaller the circuit is the better, but not a requirement. What equipment is needed?
Learning microcontroller programming is one of the most useful things you can learn...the possibilities of what they enable you to do as a student, hobbyist, engineer, etc. are limitless. It also allows you to reconfigure code as necessary, as opposed to rewiring a breadboard, for example.

FPGAs are also very useful but I'd work with microcontrollers first

My personal favorite 8-pin microcontroller is the PIC 12F683. It has on-board ADC and PWM modules, among other goodies.