Looking for simple PIC 1hz to 800 hz square wave generator

Discussion in 'Embedded Systems and Microcontrollers' started by qt4me, Jul 4, 2014.

  1. qt4me

    Thread Starter New Member

    Nov 22, 2012
    Hi All

    I am hoping somebody can help me please.

    Firstly I am not asking anybody to write anything for me, I am just hoping this project is published on the net somewhere already.

    What I am looking for is a simple 1hz to about 800 hz square wave generator .

    All I want to do is read a voltage on a pot from zero to +5v and the pic outputs a square wave tone that changes in frequency from 1hz to about 800 hz as the voltage from the pot varies, not PWM.

    I understand a little bit about what happens.
    The ADC reads the voltage, converts that voltage to a value, and the value is outputed as a tone, and repeats, but I dont have enough education to write what is probably a simple code.

    Does anybody know if a simple project like this that uses preferably a small 8 pin pic chip is on the net somewhere and can point me in the right direction ?, thanks.
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    Here is example of square wave: http://www.micro-examples.com/public/microex-navig/doc/100-led-blinking.html
    Basically the wave is high for 500 ms, low for 500 ms. You basic square wave. The wave period is 1 second (500 ms + 500 ms = 1000 ms = 1 second). 1/period is frequency, so 1/(1 second)= 1 Hz. You can copy that code for 1 Hz square wave.

    The trouble is your other requirement. The 800 Hz. 800 Hz=1/period. Period=1.25 ms. So the square wave at 800 Hz is 0.625 ms high, 0.625 ms low. I am not sure which PIC can switch this fast between high and low of the square wave.
  3. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    I have to ask; why not use a 555 timer? A simple 555 circuit with a pot from pin 3 back to the sense pins 2,6 and cap will make square waves, and a 1Hz to 800Hz range is quite easy.

    If you want to make precise fixed Hz frequencies in decimal Hz (ie exactly 100Hz, 200Hz etc) this project does that (5Hz to 20kHz);
    Using 3 buttons to set an exact frequency.

    Or, if you want PIC source code to make very exact decimal Hz frequencies from 0.00001Hz to 20KHz in 0.00001Hz steps!

    But for a "turn the pot to change the freq" deal I still think a 555 timer might be a great solution!
    atferrari likes this.
  4. qt4me

    Thread Starter New Member

    Nov 22, 2012
    Hi there THE_RB

    I have used 555's but one of the objectives with my project is to reduce the number of components, down to a simple PIC.

    I found a project that comes very close to what I am looking for

    I have made it and it works, it makes a square wave between 20 hz and 3khz,
    but the lowest pulse rate is 20 hz and I need something as low as 1-2 Hz,
    and only as high as about ~800 hz.

    Anybody know of such a project ? thanks.

    Hi shteii01, thanks for link.
  5. atferrari

    AAC Fanatic!

    Jan 6, 2004
    To reuse the code, most probably (and the easiest) would be to slow down the clock setting the pace for that micro.

    I fear you should dig the innards of the design and see how to. Never used that family of micros myself.

    I do not know how familiar you are with micros but that task could be a trivial one.
  6. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    See the second link in my previous post. That code is fully tested and working on PIC 16F628 and should work on any PIC 16F or 18F.

    Freq generated can be ANYWHERE from 0.00001Hz to 20kHz, you just change the value in one variable and it makes the perfect frequency for you.

    You can cut and paste that code directly into your project, that's why I released the code. :)
  7. BobTPH

    Active Member

    Jun 5, 2013
    Any PIC could put out a square wave as high as 1MHz. Some much higher.