CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Inbuilt PWM for 100Hz

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Prashant Patel



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

Inbuilt PWM for 100Hz
PostPosted: Mon Sep 13, 2004 5:03 pm     Reply with quote

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: 1912
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Sep 13, 2004 5:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 13, 2004 6:09 pm     Reply with quote

And tell us your oscillator frequency.
Prashant Patel



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

Details
PostPosted: Mon Sep 13, 2004 6:56 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 13, 2004 7:09 pm     Reply with quote

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

View user's profile Send private message

Thanks..
PostPosted: Mon Sep 13, 2004 7:18 pm     Reply with quote

Thanks..Ali...

Regards
Prashant
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Sep 13, 2004 9:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 14, 2004 3:55 pm     Reply with quote

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

View user's profile Send private message

Excellent
PostPosted: Tue Sep 14, 2004 6:00 pm     Reply with quote

Excellent, 97.66Hz frequency would be fine.

Let me try....Thanks...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group