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

Status
Not open for further replies.

Thread Starter

qt4me

Joined Nov 22, 2012
2
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.
 

shteii01

Joined Feb 19, 2010
4,644
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.
 

THE_RB

Joined Feb 11, 2008
5,438
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);
http://www.romanblack.com/onesec/SineDDS.htm
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!
http://www.romanblack.com/onesec/High_Acc_Timing.htm#decfreq

But for a "turn the pot to change the freq" deal I still think a 555 timer might be a great solution!
 

Thread Starter

qt4me

Joined Nov 22, 2012
2
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
http://www.cuteminds.com/index.php/en/pulsegenerator

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.
 

atferrari

Joined Jan 6, 2004
4,771
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
http://www.cuteminds.com/index.php/en/pulsegenerator

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.
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.
 

THE_RB

Joined Feb 11, 2008
5,438
...
... 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.
...
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. :)
 

click_here

Joined Sep 22, 2020
548
Easy with a PIC - Find one with a CCP module (PWM) and set the duty cycle to 50%.

That would be my go to, as it is really easy to update. i.e. If you wanted to extend it to 1kHz, you wouldn't have to change any hardware.

>"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"

Don't forget that you'll need 5V or 3.3V, so that usually means a voltage reg, but that not always a deal breaker, because you can use it for other things.

I usually use a 555 if 5V is not available and I only need a square wave that is "good enough for Australia"
 
Status
Not open for further replies.
Top