Searching \ for '[pic:] Setting up high speed PWM in a 16F877' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=pwm
Search entire site for: 'Setting up high speed PWM in a 16F877'.

Exact match. Not showing close matches.
PICList Thread
'[pic:] Setting up high speed PWM in a 16F877'
2002\03\27@160751 by jamesnewton

face picon face
I'm forwarding this to the list for a friend.

Omar Fathalllah asks:
I'm just starting to experiment with the PIC16F877 using the HITECH C
compiler. I am running the PIC at 10 Mhz and want a 50 MHz PWM period with a
7.5% duty cycle. However this means that I need the PR2 to be 3124 which is
too large (max is 255 right?). Is there a way around this? am I doing
something wrong? or do I have to use a 4MHz clock instead? or maybe create
my own pulse using TIMER0 which would allow a prescalar of 256? Thanks in
advance!

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2002\03\27@165137 by Bob Blick

face picon face
> I'm just starting to experiment with the PIC16F877 using the HITECH C
> compiler. I am running the PIC at 10 Mhz and want a 50 MHz PWM period with a
> 7.5% duty cycle. However this means that I need the PR2 to be 3124 which is
> too large (max is 255 right?). Is there a way around this? am I doing
> something wrong? or do I have to use a 4MHz clock instead? or maybe create
> my own pulse using TIMER0 which would allow a prescalar of 256? Thanks in
> advance!

There is no way the PWM can be higher than the clock frequency - no way
can you get 50MHZ PWM.

-Bob

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2002\03\27@182607 by Mike Mansheim

flavicon
face
> I'm just starting to experiment with the PIC16F877 using the HITECH C
> compiler. I am running the PIC at 10 Mhz and want a 50 MHz PWM period
> with a 7.5% duty cycle. However this means that I need the PR2 to be
> 3124 which is too large (max is 255 right?). Is there a way around
> this? am I doing something wrong? or do I have to use a 4MHz clock
> instead? or maybe create my own pulse using TIMER0 which would allow
> a prescalar of 256? Thanks in advance!

Are you sure you mean 50 MHz??  Running the pic at 10 Mhz, you can only
execute instructions at 10/4 = 2.5 MHz, let alone run the built-in pwm.
The formula for pwm frequency in this case is:
        pwm freq = 2.5E06 / ((PR2 + 1) * pre-scale)
if PR2 = 1 and pre-scale = 1, your pwm freq = 1.25 MHz.
However, you only have 1 bit of resolution!  (off and 50%)
The formula for resolution is:
        bits of resolution = log(2.5E06/pwm freq) / log(2)
which = 1 for pwm freq = 1.25 MHz
This also shows why PR2 = 0 won't work:  pwm freq theoretically
= 2.5 MHz, but the resolution = 0 bits!

If PR2 = 3124 and the pre-scale = 16, the pwm freq = 50 Hz, so I'm
guessing that is actually the speed you're looking for??  One problem
with the built-in pwm is that there is a definite minimum speed.  In
this case, it is with PR2 = 255 (the max as you pointed out) and
pre-scale = 16 (max available):
         pwm freq = 2.5E06 / (256 * 16) = 610 Hz
So you can't get to 50 Hz with this clock speed.
If you switch to a 4 MHz clock, the minimum pwm freq is:
         pwm_freq = 1E06 / (256 * 16) = 244 Hz
So you're still not there!
The max clock you can run = 256 * 16 * 50 * 4 = 819.2 KHz
So the ever popular 32.768 watch crystal would work, although you
wouldn't be able to hit 50 **exactly** - you could get 49.95 Hz.

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2002\03\28@043305 by Kevin Blain

flavicon
face
Sounds like someone is trying to drive servos.

If you are, then there are lots of code examples which don't use the PWM
module, but use interrupts instead.

The reason for this is the range of servo travel is over quite a small
range of duty cycles (about 5 to 10%) and as such using the hardware PWM
would give poor resolution.

Just a thought

If you really did want 50MHz PWM with a 7.5% duty cycle, there will be
some really nice harmonics slap bang in the middle of the UHF TV band
(UK) - 666MHz and you're gonna need one hell of a quick clock rate to
generate this with software!

Regards, Kevin

> {Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...