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 CCS Technical Support

How to setup timers to get 3 PWM-channels with 18F452?

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



Joined: 05 Jan 2011
Posts: 8

View user's profile Send private message

How to setup timers to get 3 PWM-channels with 18F452?
PostPosted: Fri May 24, 2013 3:32 am     Reply with quote

I have used 2 PWM-channels earlier but cant figure how to use three PWM:s simultaneously?

This is what I have used:

setup_timer_0(T0_EXT_H_TO_L|T0_DIV_1);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DIV_BY_4,199,1); //1kHz 100=50%
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);

Now I need 3 PWM-channels with 1kHz duty and 10 i/o-channels. Any other chip?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

Re: How to setup timers to get 3 PWM-channels with 18F452?
PostPosted: Fri May 24, 2013 4:02 am     Reply with quote

petu65 wrote:

Now I need 3 PWM-channels with 1kHz duty and 10 i/o-channels. Any other chip?


Can we assume you mean 1kHz frequency?

Mike

PS Try microchip website for chips with more than 2 PWMs.
petu65



Joined: 05 Jan 2011
Posts: 8

View user's profile Send private message

Re: How to setup timers to get 3 PWM-channels with 18F452?
PostPosted: Fri May 24, 2013 4:11 am     Reply with quote

Mike Walne wrote:
petu65 wrote:

Now I need 3 PWM-channels with 1kHz duty and 10 i/o-channels. Any other chip?


Can we assume you mean 1kHz frequency?

Mike

PS Try microchip website for chips with more than 2 PWMs.


Sorry I write wrong, PWM output frequency should be about 1kHz.
Dutycycle to be adjusted 0-100%. 8-bit is enough.

Petu
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 24, 2013 10:41 am     Reply with quote

Quote:

Now I need 3 PWM-channels with 1kHz duty and 10 i/o-channels.
Any other chip?

See this thread and the links in it:
http://www.ccsinfo.com/forum/viewtopic.php?t=48137
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Sat May 25, 2013 9:24 pm     Reply with quote

You should be able to do this with a chip that has 2 hardware PWMs. Then you write software to create the third one, using timer interrupts. But I can see a fine challenge coming up, where you need to have some PWM duty cycles which are so short that you must use just a single interrupt and a delay to create the pulse, and others which are longer and need an interrupt to start the pulse, and another interrupt to end it. But I don't see any reason why this absolutely wouldn't work.

And as always with something that needs to have precise timing, if there are other elements which conflict with your interrupts, the scheme may not be workable.
petu65



Joined: 05 Jan 2011
Posts: 8

View user's profile Send private message

PostPosted: Tue May 28, 2013 2:02 am     Reply with quote

I ordered few 16F737 chips. They have three hardware PWM outputs, I think it's easiest way to do it Smile

Petu
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