Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 2nd February 2008, 03:09 AM   (permalink)
Default PIC Low Frequency Generator

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
bryan is offline   Reply With Quote
Old 2nd February 2008, 06:37 AM   (permalink)
Default

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.
monkeybiter is offline   Reply With Quote
Old 2nd February 2008, 05:17 PM   (permalink)
Default

what kind of frequency is possible, 60 Hz, 100 Hz, higher?
__________________
Don't touch that wire........Um......are you ok?
hosh is offline   Reply With Quote
Old 2nd February 2008, 06:23 PM   (permalink)
Default

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.
monkeybiter is offline   Reply With Quote
Old 2nd February 2008, 06:31 PM   (permalink)
Default

Will you mess up the frequency output by servicing the interrupt request?
__________________
L.Chung
eblc1388 is offline   Reply With Quote
Old 2nd February 2008, 07:17 PM   (permalink)
Default

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


Quote:
Originally Posted by monkeybiter
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.
bryan is offline   Reply With Quote
Old 3rd February 2008, 08:59 AM   (permalink)
Default

Quote:
Originally Posted by eblc1388
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.
monkeybiter is offline   Reply With Quote
Old 3rd February 2008, 09:25 AM   (permalink)
Default

Quote:
Originally Posted by bryan
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'?
Mike, K8LH is offline   Reply With Quote
Old 3rd February 2008, 05:04 PM   (permalink)
Default

Quote:
Originally Posted by eblc1388
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.
donniedj is offline   Reply With Quote
Old 6th February 2008, 07:18 AM   (permalink)
Default

I was hoping for a resolution of 0.5 hz and would like to control by the use of two pushbuttons. Up and down.


Quote:
Originally Posted by Mike, K8LH
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'?
bryan is offline   Reply With Quote
Old 6th February 2008, 09:19 AM   (permalink)
Default

Quote:
Originally Posted by bryan
I was hoping for a resolution of 0.5 hz and would like to control by the use of two pushbuttons. Up and down.
Just as easy to do, it's really a trivial task for a PIC.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Variable capacitor circuits walters General Electronics Chat 83 11th March 2008 02:58 PM
Frequency Generator ParkingLotLust Electronic Projects Design/Ideas/Reviews 3 6th July 2006 04:09 AM
Low frequency Triangle generator HarveyH42 Electronic Projects Design/Ideas/Reviews 14 12th June 2006 10:17 PM
Simple frequency generator Chazz General Electronics Chat 5 25th July 2005 08:30 AM
frequency generator cool-agent Electronic Projects Design/Ideas/Reviews 1 10th March 2004 12:26 PM



All times are GMT. The time now is 12:49 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.