View previous topic :: View next topic |
Author |
Message |
balboa
Joined: 24 Mar 2015 Posts: 8 Location: Syria
|
software PWM using PIC16F877A |
Posted: Mon Mar 30, 2015 7:42 am |
|
|
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
|
|
Posted: Mon Mar 30, 2015 7:55 am |
|
|
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
|
|
Posted: Tue Mar 31, 2015 9:51 am |
|
|
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
|
|
Posted: Tue Mar 31, 2015 10:23 am |
|
|
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
|
|
Posted: Tue Mar 31, 2015 10:28 am |
|
|
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 |
|
|
|