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

software PWM using PIC16F877A

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



Joined: 24 Mar 2015
Posts: 8
Location: Syria

View user's profile Send private message

software PWM using PIC16F877A
PostPosted: Mon Mar 30, 2015 7:42 am     Reply with quote

hey there :
I need 4 PWM in my project and I've been wondering how can I do this using my PIC16F877A I've read about software PWM & couldn't actually get it
I need an example to show me how to do it
help pls !!
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Mon Mar 30, 2015 7:55 am     Reply with quote

It depends totally on a number of things:

How fast your chip is running.
How fast you need the PWM.
What accuracy you need (number of different pulse widths).

In the code library, there is an example for radio control servos. Low speed, low resolution. If you need a high PWM frequency (>1KHz perhaps), and any sort of reasonable resolution (>16 step sizes perhaps), then unless your PIC is running very fast indeed, you are not going to get good results.

There is also an example doing exactly what you describe:
<http://www.ccsinfo.com/forum/viewtopic.php?t=50069>

However the comments also reflect the problems this has. Four channels, 256 levels each, result potentially flicker on the LED's involved.

Basic approach is to use a fast 'tick' interrupt, and in this decide for each signal when it needs to go on/off.
balboa



Joined: 24 Mar 2015
Posts: 8
Location: Syria

View user's profile Send private message

PostPosted: Tue Mar 31, 2015 9:51 am     Reply with quote

Ttelmah wrote:
It depends totally on a number of things:

How fast your chip is running.
How fast you need the PWM.
What accuracy you need (number of different pulse widths).

my chip is running on 20 MHz
the PWM fast is 50 Hz
the duty cycle varies between 1400 to 2400 us
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 31, 2015 10:23 am     Reply with quote

Your requirements look like it's for RC servos.
Depending on what else the PIC has to do even using delay_us(xxx) might work for you. As others have said there is code available either in this forum or the 'code library' forum as well as a TON of code 'on the Web'.

hth
jay
Mike Walne



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

View user's profile Send private message

PostPosted: Tue Mar 31, 2015 10:28 am     Reply with quote

balboa wrote:
Ttelmah wrote:
It depends totally on a number of things:

How fast your chip is running.
How fast you need the PWM.
What accuracy you need (number of different pulse widths).

my chip is running on 20 MHz
the PWM fast is 50 Hz
the duty cycle varies between 1400 to 2400 us

How many discrete steps do you need between 1400 & 2400us?

Like jay says, it looks like it's been done here before.
Do a search.

Mike
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