Searching \ for 'Interupt Based PWM' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/io/pwm/index.htm?key=pwm
Search entire site for: 'Interupt Based PWM'.

Truncated match.
PICList Thread
'Interupt Based PWM'
1997\03\05@004756 by Ben Wirz

flavicon
face
Hello Everyone,


       I need to produce a variable PWM output based on a 8 bit hex number
that corresponds to the percentage duty cycle of the PWM.  My basic idea was
use the interupt on overflow feature of timer0.

       So the waveform would look like this:

                 --------------------
       |         |                   |
       |         |                   |
       ----------                    ---------------

         $FF-PWM      PWM

       The pseudo code would look something like this:

Interupt_Service_Routine

       If the output was low last time
               {
               set the output high
               set timer0 to $FF - PWM
               //Set Timer to Over Flow PWM latter
               }
       else
               {
               set the output low
               set timer0 to PWM
               //Set Timer to Over Flow $FF-PWM latter
               }

End_Service_Routine


       Ok, well that seems simple enough to implement to me but what I
would really like to do is try this with one of the cheaper noninterupt
based PICs.   The problem is that the PIC will also be doing serial comms so
it can't be totally tied up with making the PWM signal although there isn't
alot else going on.

       I would appreciate comment and suggestions on both the interupt and
noninterupt based methods.

Thanks Guys,

Ben


Ben Wirz                For Microchip PIC Products including the Simm Stick
                       development system and Easy PIC'n Book, as well
Wirz Electronics        as Motor Control, Polaroid Sonar Units, and more
spam_OUTbenTakeThisOuTspamwirz.com            Hobbyist Robotic & Electronic Supplies, visit:
                       http://www.wirz.com/

1997\03\05@040517 by efoc

flavicon
face
Ben Wirz wrote:
{Quote hidden}

OK Ben,
       I have done a lot of work in PWM for controling R/C servos In my
requirement there is a 15-20 mSec refresh of a 1-2 mSec pulse.

       My code generates the Pulse output based on the clock speed and I use
the fact that I have a 5 mSec window to do other things.

       I calculated the fastest ans slowest time through the rest of my code
and ensured that it was less than 5 Msecs. this then alowed me to
calculate a constant time to get the 20Msec Duty cycle.

       If you are interested in the code i can send it to you. BTW I control 2
O/Ps for two servos but the timings will allow up to 7 Servos
       IE 7*2 Msecs = 14 Msecs giving me a fixed time of 1 Msec and a variable
time of 5 Msec to do my other stuff.

--

Cheers Peter ..........

==================================
New Ideas come from those who
didn't know it wasn't possible
==================================

1997\03\05@091838 by Andy Kunz

flavicon
face
Ben,

I've been doing a lot with the PWM hardware of late, always at interrupt
level.  I'll drop you some code soon.  Holler if I forget.

Handle the PWM interrupt before the serial, unless you're doing a really
high bps.

Andy
======================================================================
Andy Kunz - Montana Design - 409 S 6th St - Phillipsburg, NJ 08865 USA
             Electronics for Industry & R/C Hobbyists
        "Go fast, turn right, and keep the wet side down!"
======================================================================

1997\03\05@113637 by David W. Duley

picon face
In a message dated 97-03-05 01:20:26 EST, you write:

<<
Hello Everyone,


        I need to produce a variable PWM output based on a 8 bit hex number
that corresponds to the percentage duty cycle of the PWM.  My basic idea was
use the interupt on overflow feature of timer0.

        So the waveform would look like this:

                  --------------------
        |         |                   |
        |         |                   |
        ----------                    ---------------

          $FF-PWM      PWM

        The pseudo code would look something like this:

Interupt_Service_Routine

        If the output was low last time
                {
                set the output high
                set timer0 to $FF - PWM
                //Set Timer to Over Flow PWM latter
                }
        else
                {
                set the output low
                set timer0 to PWM
                //Set Timer to Over Flow $FF-PWM latter
                }

End_Service_Routine


        Ok, well that seems simple enough to implement to me but what I
would really like to do is try this with one of the cheaper noninterupt
based PICs.   The problem is that the PIC will also be doing serial comms so
it can't be totally tied up with making the PWM signal although there isn't
alot else going on.

        I would appreciate comment and suggestions on both the interupt and
noninterupt based methods.

Thanks Guys,

Ben

 >>
Ben,
I have done just this.  Our machine uses many 16F84s to control speed of fan
motors, pumps, dynamic particle brakes etc.  It works well.  I chose to use
the 1684 because of the interupt capability.  My machine has 14 pics all
speaking through what I call a speak-when-spoken-to rs232 protocol.
Interupts simplify the code dramatically.  1684s are only $5.00 in onsy
quantity from Digikey.
I found it pretty much imposible to preform error free serial and perform
un-interupted PWM.  In areas where it didn't matter if I lost control for a
few milliseconds, such as the fan speed control,  I turn off the output while
I service the RS232 routines.  When recieving data you hear a little change
in pitch of the fan for a split second.  But in areas where I needed better
control (such as the particle brake used for web tensioning.  If I used the
same tecnique as the fan the web would vibrate or pulse. I need absoulute
precise tension control)  I went to two pics.  The first one does nothing but
watch the RS232 and parse the command strings.  It takes the data and
presents it on port B (The only 8 bit port in the part).  The second pic does
nothing but PWM.  It reads its portB and uses the number presented on the
port as the PWM value.
If you are bent on using one pic then you better pick a pic with onboard
USART.

Hope this helps
Dave Duley
V.P. DreiTek Inc.

1997\03\05@125758 by Anil Patel

flavicon
face
At 09:02 AM 3/5/97 +0000, you wrote:
>OK Ben,
>        I have done a lot of work in PWM for controling R/C servos In my
>requirement there is a 15-20 mSec refresh of a 1-2 mSec pulse.
>

I'm interested in driving R/C servos as well.  I've managed to use the 16C84
to generate a 1-2ms pulse width by using an excellent suggestion from Steve
Hardy on this list.  He suggested using the TMR0 and the prescaler together
as a 16-bit counter running with a resolution of 500ns (8Mhz CPU clock).

This works very well, but there is some work involved in reading the
prescaler value since it isn't directly accessible.  It basically involves
switching TMR0 clock from the CLKOUT to the T0CKI/PA4 pin and manually
clocking the PA4 pin to read out the count.

>        My code generates the Pulse output based on the clock speed and I use
>the fact that I have a 5 mSec window to do other things.
>

Do you use TMR0 or depend on a fixed instruction timing loop to generate the
pulse?

>        I calculated the fastest ans slowest time through the rest of my code
>and ensured that it was less than 5 Msecs. this then alowed me to
>calculate a constant time to get the 20Msec Duty cycle.
>

Just to make sure I understand you, do you mean the fastest and slowest time
through the code that doesn't generate the servo pulse?

>        If you are interested in the code i can send it to you. BTW I control 2
>O/Ps for two servos but the timings will allow up to 7 Servos
>        IE 7*2 Msecs = 14 Msecs giving me a fixed time of 1 Msec and a variable
>time of 5 Msec to do my other stuff.
>

I'd be interested to see your code as well.  BTW, do you have any
suggestions on reading servo pulse widths asynchronously?  I'd like to be
able to read two PWMs coming from a R/C receiver and drive one servo
simultaneously.

Thanks,
--Anil

1997\03\05@210059 by Andy Kunz

flavicon
face
>I'd be interested to see your code as well.  BTW, do you have any
>suggestions on reading servo pulse widths asynchronously?  I'd like to be
>able to read two PWMs coming from a R/C receiver and drive one servo
>simultaneously.

Been there, done that.

If you need real accurate (1uS or so) resolution of the input R/C pulse, I
recommend using a 4 MHz 16C73 or 6x with the 2 h/w capture registers.  This
will give you the two pulse widths coming in very accurately.

Use TMR0 to get the output width you need.  You can also get 1uS resolution
on this with some slick coding by making the output synchronous with the
inputs, though slightly out of phase.  "The implementation is left as an
exercise for the student" <G>

Andy

==================================================================
Andy Kunz - Montana Design - 409 S 6th St - Phillipsburg, NJ 08865
         Hardware & Software for Industry & R/C Hobbies
       "Go fast, turn right, and keep the wet side down!"
==================================================================

1997\03\05@212003 by Anil Patel

flavicon
face
At 08:56 PM 3/5/97 -0500, Andy Kunz wrote:
>Been there, done that.
>
>If you need real accurate (1uS or so) resolution of the input R/C pulse, I
>recommend using a 4 MHz 16C73 or 6x with the 2 h/w capture registers.  This
>will give you the two pulse widths coming in very accurately.
>
Yes, thats pretty much the conclusion I came to.  I just received my 16c73JW
yesterday.  I already coded up a 68HC11 to do the same thing with a trivial
amount of code since it has 4 input compares on-board.

>Use TMR0 to get the output width you need.  You can also get 1uS resolution
>on this with some slick coding by making the output synchronous with the
>inputs, though slightly out of phase.  "The implementation is left as an
>exercise for the student" <G>
>

Thanks for the suggestion.  Using Steve Hardy's approach I can get the
accuracy I need on the output side.

--Anil

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