Newsgroups: comp.robotics
Path: brunix!sgiblab!sdd.hp.com!hplabs!unix.sri.com!headwall.Stanford.EDU!nntp.Stanford.EDU!arc
From: arc@leland.Stanford.EDU (Andrew Richard Conway)
Subject: Re: Pulse Width Modulation
Message-ID: <1993Nov4.192305.20229@leland.Stanford.EDU>
Sender: news@leland.Stanford.EDU (Mr News)
Organization: DSG, Stanford University, CA 94305, USA
References: <0gq6zj_00WBMEEbd9K@andrew.cmu.edu>
Date: Thu, 4 Nov 93 19:23:05 GMT
Lines: 47

In article <0gq6zj_00WBMEEbd9K@andrew.cmu.edu> Christopher Kristof <ck3i+@andrew.cmu.edu> writes:
>Excerpts from netnews.comp.robotics: 3-Nov-93 Re: Pulse Width Modulation
>by Andrew R. Conway@leland. 
>>  [ A 68HC11 can do 4 PWM channels itself very easily using its timers. ]
>
>    I knew the HC11 could do some fancy stuff if you're willing to use
>up lots of CPU time, but I'm not sure that I'll have that many cycles to
>kill.  I did get a private reply from Gerard Lacey which sounds to be
>quite good though.
>
>    Use OC1 to turn OC 2-5 on at time 0 and then have each corresponding
>OC 2-5 turn itself off at a specified time to achieve the proper duty
>cycle. I looked at the data book, and this would work.  However, it
>would require at least one interrupt per channel at the frequency of my
>PWM control.  If I ran the motors at 100 Hz, I'd have 400 interrupts per
>second.  With an 8 Mhz clock, you get 2 Mhz internal operation.  Most
>instructions are 2-7 cycles a piece.  If every interrupt took 100
>cycles, I'd have 2,000,000 - 40,000 = 1,960,000 cycles left.  That's
>exactly %2 cpu useage.  Sounds pretty good.
>
>    I've never done anything with an HC11, so if any of this sounds
>incorrect, please throw your 2 cents in.
>

You don't even need to use OC1 to turn OC2-5 on.
I use the four outputs as follows:
	(1) Set to toggle mode
	(2) Initialise 4 timer channels with staged turn ons
	    (to distribute current drain)
	(3) Set up interrupts for each timer.
The interupts for each timer then just reload the counter with one of two
values depending whether it wishes to go high or low next time. From
memory this takes < 50 cycles. And the timing is exact (to within
500 nanoseconds).

I then use the 4 input capture signals to decode PWM inputs in a similar
manner. This is another reason I don't use OC1 to turn OC2-5 on.

The processing overhead of this is quite small.


						Andrew.

-- 
-----------------------------------------------------------------
Andrew Conway    arc@leland.stanford.edu  Phone: USA 415 497 1094

