View previous topic :: View next topic |
Author |
Message |
Prashant Patel
Joined: 19 Jul 2004 Posts: 33
|
Inbuilt PWM for 100Hz |
Posted: Mon Sep 13, 2004 5:03 pm |
|
|
Hi..
We want PWM on 100Hz frequency. Is it possible to have with inbuilt PWM?
If not, which can be the other better way for that..??
Any help appriciated...
Thanks...
Regards
Prashant |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Mon Sep 13, 2004 5:07 pm |
|
|
Prashant,
It would be nice if you would tell us the version of PIC you have in mind to use.... Are you wanting to use hardware PWM? |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Sep 13, 2004 6:09 pm |
|
|
And tell us your oscillator frequency. |
|
|
Prashant Patel
Joined: 19 Jul 2004 Posts: 33
|
Details |
Posted: Mon Sep 13, 2004 6:56 pm |
|
|
Hi..
We are using 16F877 and 20MHz Oscillator.
And want PWM of 100Hz frequency. It would be better, if I can use inbuilt PWM.
Thanks.
Regards
Prashant |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Sep 13, 2004 7:09 pm |
|
|
I don't think you can use a 20MHz crystal to create a 100Hz hardware PWM. The lowest you can go is around 1.2KHz I think.
A setup_timer_2(T2_DIV_BY_16,98,16); will give you Timer2 with overflow interrupt every 5ms. Just toggle your output line on every interrupt. |
|
|
Prashant Patel
Joined: 19 Jul 2004 Posts: 33
|
Thanks.. |
Posted: Mon Sep 13, 2004 7:18 pm |
|
|
Thanks..Ali...
Regards
Prashant |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 13, 2004 9:37 pm |
|
|
Quote: |
Just toggle your output line on every interrupt.
|
That works well for a 50% duty cycle but not much else.
I would look and the ccp module. Much easier to do with it. |
|
|
J_Purbrick
Joined: 16 Sep 2003 Posts: 9
|
|
Posted: Tue Sep 14, 2004 3:55 pm |
|
|
Yes, the minimum frequency available with a 20MHz crystal seems to be 1.22 KHz (per Microchip manual).
You didn't say what resolution you need for this PWM output. If it were, say, 1% then you could run a timer to give you 10000 interrupts a second, and do it in software quite easily. With a little extra finesse, you could interrupt only twice in the 1/100 second period, once to turn the output on and once to turn it off again. It looks like doing that means you need prescaler and postscaler both equal to 16, and your on and off times (as loaded into the PR2 register) have to add up to 195. So 1/195 would be your lowest duty cycle. Is that 100Hz an unchangeable requirement, or could you make it 97.66Hz? If so, you could count to 200 and have a nice even 0.5% resolution. |
|
|
Prashant Patel
Joined: 19 Jul 2004 Posts: 33
|
Excellent |
Posted: Tue Sep 14, 2004 6:00 pm |
|
|
Excellent, 97.66Hz frequency would be fine.
Let me try....Thanks... |
|
|
|