Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC Low Frequency Generator

Status
Not open for further replies.

bryan

Member
Hi All:

Is it possible to use a PIC to generate low frequency square waves variable between 5 and 50hz with a 50% duty cycle or better off to use a 555 timer.

Thanks
 
at last, i can say it.....
yes it's trivial.
it's very easy to output a square wave from a pic with full control over frequency and duty cycle... you just toggle the pin value when required by a preset delay. i used a spare 16f84 to do just this while debugging a zero cross iinterrupt routine on a 16f876a controlled dimmer.
of course a 555 is easy too, but you have to hang more bits and bobs off it to get the same result [assuming you have a pic programmer].
if you've got a spare low end pic my choice would be to use that.
 
what kind of frequency is possible, 60 Hz, 100 Hz, higher?
 
low end pics will run at 20MHz, ie instructiions are executed at 5MHz. If you simply toggled in an endless loop you could achieve over 1.6MHz [quick reckoning]. you could add controls with interupting inputs and still acheive hundreds of KHz.
 
Perhaps it was low frequency using PWM that was supposedly difficult using a PIC. Would you have any sample code from the 16f84 project you worked on that you could post to get me started? Thanks


monkeybiter said:
at last, i can say it.....
yes it's trivial.
it's very easy to output a square wave from a pic with full control over frequency and duty cycle... you just toggle the pin value when required by a preset delay. i used a spare 16f84 to do just this while debugging a zero cross iinterrupt routine on a 16f876a controlled dimmer.
of course a 555 is easy too, but you have to hang more bits and bobs off it to get the same result [assuming you have a pic programmer].
if you've got a spare low end pic my choice would be to use that.
 
eblc1388 said:
Will you mess up the frequency output by servicing the interrupt request?

if you only interrupt on pin change [input from keypad etc. ] then you should suspend generated output during settings change [inputting frequency value, duty ratio etc.] otherwise generation should be unhindered.
i am talking about generating output dependant on a calculated delay loop based on a pair of variables [eg. on duration, off duration]
a better alternative would be to use Timer to generate a pin toggle interrupt. keypad input could then be monitored in a main loop. this should give a more continuous output.
when i did it i didn't implement any input to vary parameters, i incremented an eight bit port at a fixed rate, giving 50Hz on bit 0, 25Hz on 1, 12.5Hz on 3 etc. and manually selected the pin to suit my needs.
 
bryan said:
Hi All:

Is it possible to use a PIC to generate low frequency square waves variable between 5 and 50hz with a 50% duty cycle or better off to use a 555 timer.

Thanks
What kind of resolution and tolerance do you need? 1.0 Hz ±1.0% or ±2.0% perhaps? And, how do you want to control or select the frequency? Thumbwheel switches? Serial input from a PC? A trim pot'?
 
eblc1388 said:
Will you mess up the frequency output by servicing the interrupt request?

No, as long as you add the time to service a constant interrupt like a counter or timer into the frequency generation. 5 to 100 Hz is so incredibly slow that you can vector off to another subroutine irregularly and have no adverse effect on the frequency. 1% change of 100 Hz is about 100us. Using a 4MHz PIC grants you 100 cycles of error, an 8MHz PIC grants you 200 cycles of error, and a 20MHz PIC which will now require external crystal/resonator grants you 500 unplanned and unforseen cycles of error.
 
I was hoping for a resolution of 0.5 hz and would like to control by the use of two pushbuttons. Up and down.


Mike said:
What kind of resolution and tolerance do you need? 1.0 Hz ±1.0% or ±2.0% perhaps? And, how do you want to control or select the frequency? Thumbwheel switches? Serial input from a PC? A trim pot'?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top