Searching \ for '[PIC]: Newbie - RC receiver to 2xPWM outputs with' 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/begin.htm?key=pwm
Search entire site for: 'Newbie - RC receiver to 2xPWM outputs with'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Newbie - RC receiver to 2xPWM outputs with '
2001\04\20@190834 by Mike Evans

picon face
This is my first ever post the list, I've been sitting listen for a few months now.... You all seem like a helpful lot.

I'm trying to write some code that takes two radio control servo inputs (forward/reverse on one channel, left/right on the other) and mixes them together to provide two PWM outputs suitable for driving FET H-bridges for a small radio-controlled robot.

I've got as far as measuring the pulse length of one servo input and using an ISR I can generate a PWM signal from this, my problem is adding the second channel - the timing goes to pot! (My ISR generates the PWM to give a fixed-frequency, but this means my main loop that measures the servo input gets interrupted a hell of a lot - am I doing this the right way round?)

I feel like I'm almost there, but I'm also convinced that someone _must_ have done this before. I've checked the archives and found nothing.

I suppose my question is: Is generating two PWMs whilst reading two inputs too much for one 16F84 to cope with or am I looking in the wrong place for the solution?
Any help appreciated. Mike.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2001\04\21@082132 by Drew Vassallo

picon face
>I'm trying to write some code that takes two radio control servo inputs
>(forward/reverse on one channel, left/right on the other) and mixes them
>together to provide two PWM outputs suitable for driving FET H-bridges for
>a small radio-controlled robot.

Why not just use a commercial electronic mixer?  They're cheap, they're
small, and they'd probably drive an H-bridge.  Unless you aren't really
looking for that type of a mixer.  I'm not sure what you're trying to do...
you want to mix two channels together, yet still want "two PWM outputs."

>I feel like I'm almost there, but I'm also convinced that someone _must_
>have done this before. I've checked the archives and found nothing.

There is tons of stuff in the archives, as well as on the internet.  Have
you used the search engine on the PICLIST site?  It works rather well.

>I suppose my question is: Is generating two PWMs whilst reading two inputs
>too much for one 16F84 to cope with or am I looking in the wrong place for
>the solution?

This isn't at all too much for one chip to cope with; people have done up to
8 servos from one 16F84.  This stuff is on the PICLIST site, I've seen it
before.

--Andrew

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

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


2001\04\21@114325 by Dale Botkin

flavicon
face
[Caution: Researched but untested ideas below]

On Fri, 20 Apr 2001, Mike Evans wrote:

{Quote hidden}

Hmm.  Using interrupts to do this would be tough.  You've got to capture
the pulse length from two inputs, do the mixing, and generate two outputs.
None of these are particularly difficult until you try to do them all with
interrupts occurring all over the place.

Bear in mind that you don't need to see *every* input pulse from both
inputs, just get them whenever it's convenient -- say a few times a second
or so.  I do't think you need a pulse train to keep them going.  If you
position a normal, unmodified R/C servo at 45 degrees and remove the pulse
train, it won't move from that position by itself.  The servo will remain
at the last position is was sent to.  You're using servos modified for
continuous rotation, with the feedback loop broken.  If you send the servo
a pulse to get it going, it's going to run the motor until it "sees" the
right feedback pot resistance.  Since it will never see that at anything
other than the neutral (1ms pulse) position, it will keep on turning
forever, or until you send it a new position that agrees with your fixed
feedback resistance (the center position,or a 1ms pulse.)

So you only need to send the pulse to the servos when you want to change
their speed.  The only real reason to keep sending the servo pulses every
20ms or so is to *hold* the position you've sent it to.  Since you're not
using them to move things and hold positions, you have considerably more
freedom to play.  See how much easier the picture looks now?

> I feel like I'm almost there, but I'm also convinced that someone
> _must_ have done this before. I've checked the archives and found
> nothing.
>
> I suppose my question is: Is generating two PWMs whilst reading two
> inputs too much for one 16F84 to cope with or am I looking in the
> wrong place for the solution?

I don't think so, but you might want to re-think your approach with less
regard to what you've read about R/C servo control.  8-)  You're using the
servos in a manner inconsistent with a lot of the information you've been
reading, so do some experimentation and see how much less complicated it
can be.

Dale
---
The most exciting phrase to hear in science, the one that heralds new
discoveries, is not "Eureka!" (I found it!) but "That's funny ..."
               -- Isaac Asimov

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


2001\04\21@132744 by Bob Blick

face
flavicon
face
>I'm trying to write some code that takes two radio control servo inputs
(forward/reverse on one channel, left/right on the other) and mixes them
together to provide two PWM outputs suitable for driving FET H-bridges for
a small radio-controlled robot.

>I suppose my question is: Is generating two PWMs whilst reading two inputs
too much for one 16F84 to cope with or am I looking in the wrong place for
the solution?

It would require some clever coding to do it glitchlessly. Also adding
other features(like dealing with out-of-range pulses when the transmitter
is off) gets even trickier.

Do you need to use a 16F84? I've done exactly what you want in a 16F876 and
it also has current limiting to protect your h bridge, and am just now
adding temperature sensing for two motors and two h bridges.

-Bob

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


2001\04\21@164921 by Scott Dattalo

face
flavicon
face
On Sat, 21 Apr 2001, Bob Blick wrote:

> >I'm trying to write some code that takes two radio control servo inputs
> (forward/reverse on one channel, left/right on the other) and mixes them
> together to provide two PWM outputs suitable for driving FET H-bridges for
> a small radio-controlled robot.
>
> >I suppose my question is: Is generating two PWMs whilst reading two inputs
> too much for one 16F84 to cope with or am I looking in the wrong place for
> the solution?
>
> It would require some clever coding to do it glitchlessly. Also adding
> other features(like dealing with out-of-range pulses when the transmitter
> is off) gets even trickier.

Come on Bob, it's trivial :) - well the PWM of it is:

http://www.dattalo.com/technical/software/pic/pwm8.asm

That'll get you 8 simultaneous PWMs. Two PWMs can be handled with the same code
(at that URL). I'd suggest looking at the code just to read the comments, but
here's a portion of it pruned for two inputs:

pwm_multiple

       CLRW                    ;Build the bit mask for turning
                               ;off the PWM outputs. Assume that
                               ;all of the outputs will be turned
                               ;off.
                               ;
       DECFSZ  pwm0,F          ;If the first counter has not reached 0
        IORLW  00000001b       ;then we don't want to turn it off.
                               ;
       DECFSZ  pwm1,F          ;Same for the second one
        IORLW  00000010b       ;
                               ;
...
       ANDWF   pwm_state,W     ; Clear all of those pwm outputs
                               ;that have reached zero.
                               ;
       XORLW   11111111b       ;Toggle the current state.
       INCFSZ  rising_edge,F   ;If the rising edge counter has not
        XORLW  11111111b       ;rolled over then toggle them again.
                               ;Double toggle == no effect. However,
                               ;if the rising edge counter does roll
                               ;over then a single toggle will turn
                               ;the pwm bits on, unless of course the
                               ;pwm counter has just rolled over too.
                               ;
       MOVWF   pwm_state       ;Save the state
       MOVWF   PWM_PORT        ;update the outputs

If you're driving an H-Bridge (and it's NOT Bob Blick's design) then you may
want to have two outputs for each PWM; one for each leg of the bridge. A subtle
modification of the constants in the above snippet can achieve that.

Now, the hard part is calling this at a repeatable rate. You can write an
isochronous loop or trigger on TMR0 overflow - it's your choice of the lesser of
two evils.

If you don't care if the PWM's run at constant frequency, then you can use phase
accumulators. This is faster than the above code:

    movf   PWM_duty_0,w
    addwf  PWM_phase_0,f
    rlf    pwm_state,f

    movf   PWM_duty_1,w
    addwf  PWM_phase_1,f
    rlf    pwm_state,w

    andlw  00000011b
    movwf  PWM_PORT

This has the same requirement that it must be called at a constant rate.

>
> Do you need to use a 16F84? I've done exactly what you want in a 16F876 and
> it also has current limiting to protect your h bridge, and am just now
> adding temperature sensing for two motors and two h bridges.


An '876 is definitely a better processor for this application.


Scott

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


2001\04\21@205542 by Bob Blick

face
flavicon
face
>(at that URL). I'd suggest looking at the code just to read the comments, but
>here's a portion of it pruned for two inputs:
>
>If you're driving an H-Bridge (and it's NOT Bob Blick's design) then you may
>want to have two outputs for each PWM; one for each leg of the bridge. A
subtle
>modification of the constants in the above snippet can achieve that.

You do need 2 pwm outputs for each H bridge, both are not running at the
same time though :-)
>An '876 is definitely a better processor for this application.

The 2 capture channels make reading the servo pulses trivial.

-Bob

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


2001\04\21@213359 by Brian Reed

flavicon
face
>You do need 2 pwm outputs for each H bridge, both are not running at the
>same time though :-)
>>An '876 is definitely a better processor for this application.

Or 1 PWM per h-bridge and a DIRection bit.  Feed the direction
bit to an AND gate, as well as through an inverter to another AND.
The second input to each AND is a PWM signal.  This prevents
the program from turning both sides of the H-bridge on at the
same time, and makes the 877's dual PWM output able to drive
2 (bi-dir) H-bridges.

I figure ya know all that, but mentioned for the others reading
along.

- Bri

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


2001\04\21@215818 by Bob Blick

face
flavicon
face
At 09:35 PM 4/21/2001 -0400, you wrote:
>>You do need 2 pwm outputs for each H bridge, both are not running at the
>>same time though :-)
>>>An '876 is definitely a better processor for this application.
>
>Or 1 PWM per h-bridge and a DIRection bit.  Feed the direction
>bit to an AND gate, as well as through an inverter to another AND.
>The second input to each AND is a PWM signal.  This prevents
>the program from turning both sides of the H-bridge on at the
>same time, and makes the 877's dual PWM output able to drive
>2 (bi-dir) H-bridges.

Not if you use the capture channels for measuring the servo pulses, you
can't have 2 captures and 2 PWM. That's why I did the PWM in software.
Although I've never had both directions turn on at once, if you design your
H-bridge correctly(it only takes 2 small transistors extra) you can prevent
shorts and get a braking channel for "free".

-Bob

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


2001\04\23@034952 by Paul Harris

flavicon
face
What you are trying to do is possible.
I have played around with something simular and got a 16F84 to do it.

The two RC pulse that you wish to measure if they are comming from the
same reciever will be 20ms apart.
So in the system I am using I have OR'd the pulses toeather and run
them both in to RB0 interupt port.
I have then run one of the pulses in to another port as well to allow
the code to determin which pulse it has been interupted by.

The dual PWM is easy.

The most difficult part of what you want to do is how to convert the
length of the pulses in to the number that you need to put in to the
PWM routien.

When I did it. It has taken a lot of 16bit maths to get someting that
gives a enough resoulution.

Another idear may be to dump the 16F84 and use one of the newer pics
with more functions eg 16bit timers and hardware PWM generators eg
16F627 or 16F628 (still 18 pin package)

Paul Harris


{Original Message removed}

2001\04\23@153642 by David Cary

flavicon
face
Dear people designing H bridge drivers:

You probably have already figured out that "servo" PWM is very different from
"motor drive" PWM.

"servo" PWM: typically repeats at 20 to 70 Hz; 1 ms lo for reverse; 1.5 ms lo
for neutral; 2 ms lo for full forward, hi for rest of period.
"motor drive" PWM: typically repeats at 20 KHz to 100 KHz; solid lo for off; 1/2
period lo, 1/2 period hi for half-speed; solid hi for full on.

Brian Reed <RemoveMEpiclistTakeThisOuTspamREEDONLINE.COM> on 2001-04-21 08:35:13 PM wrote:
> Subject:     Re: [PIC]: Newbie - RC receiver to 2xPWM outputs with a 16F84
...
{Quote hidden}

I agree that we only need 1 PWM and 1 DIRection bit per H bridge, but I don't
understand the rest of your description.

Bob Blick <spamBeGonebblickspamBeGonespamSABER.NET> on 2001-04-21 08:55:27 PM wrote:
> if you design your
> H-bridge correctly(it only takes 2 small transistors extra) you can prevent
> shorts and get a braking channel for "free".



Do you have a pointer to a "correctly-designed" H bridge ?


The H bridge circuit I'm about to install on my robot has the DIRection bit go
directly to the "left" half of the H bridge (actually a small transistor,
flyback diode, and a SPDT relay) which drives one motor lead. The "right" half
of the H bridge is controlled by the PWM, and drives the other motor lead. (PIC
PWM output goes through 2 inverters to give it a little more power and convert
TTL to +12V, then that 0 to +12V PWM signal connects to a power PFET on the top
right and a power NFET on the lower right).

(Pardon the crude ASCII diagram)

          +12V   +12V
           |      |
           o Bhi-o[PFET
          \       |
           \--(M)-+
                  |
           o Blo-|[NFET
           |      |
           GND   GND

Bhi and Blo are both connected to the 0 to +12 V PWM signal.
The relay is controlled by the direction bit.
Not shown: 4 flyback Schottky diodes, connecting every motor lead to every
battery lead.

I haven't actually applied power yet, but I'm planning on
 Full forward: DIR = Forward, PWM = 0xff
 slow forward: DIR = Forward, PWM = 0x20
 stop: DIR = Forward, PWM = 0x00
 stop: DIR = Reverse, PWM = 0xFF
 slow reverse: DIR = Reverse, PWM = 0xDF
 full reverse: DIR = Reverse, PWM = 0x00.

Does this make any sense ?

(The relay in the left half H bridge is break-before-make. Right now, the 2
transistors in the right half H bridge are make-before-break, but the
transistion time is so small that I'm hoping it doesn't matter -- I *think* I
can tweak that circuit to get independent Bhi and Blo break-before-make if I
really need to, without any changes in software).

I was looking at High-side switching with 2 NFETs, but right now I think it's
simpler to use this PFET for motors that pull less than 10 A (when stalled):
$1.05 IRFR5305-ND (DPAK) -55 Vdss, -25 A Id P-CH   (Price from Digikey on 2000)

Here's some H bridge links I've found useful:

 http://www.4qd.co.uk/
 http://www.4qdtec.com/pwm-01.html
 Power H Bridge Driver  http://www.PicNPoke.com/projects/mdrive.pdf
 IR Design Tip DT-98.2 Bootstrap Component Selection For Control IC's
http://www.irf.com/technical-info/designtp/dt98-2.htm  (for H bridges and half
bridges that use N type transistors on the hi side).
 High-side switching
http://www.irf.com/_FKK4aEd/technical-info/appnotes/an-978.pdf  MOS-gate drivers
(MGDs), the bootstrap circuit, brushless motor driver

-- David Cary

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\04\23@161137 by Sean H. Breheny

face picon face
Hi David,

I think you have that backwards (at least for most servos). The high time
ranges from 1ms to 2ms, not the low time.

Sean


At 02:34 PM 4/23/01 -0500, you wrote:
>"servo" PWM: typically repeats at 20 to 70 Hz; 1 ms lo for reverse; 1.5 ms lo
>for neutral; 2 ms lo for full forward, hi for rest of period.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\04\23@165801 by Bob Blick

face
flavicon
face
> "servo" PWM: typically repeats at 20 to 70 Hz; 1 ms lo for reverse; 1.5 ms lo
> for neutral; 2 ms lo for full forward, hi for rest of period.

Actually it's 1 to 2 millisec HIGH not LOW. Also reverse and forward vary
from manufacturer to manufacturer - Futaba is 1 ms forward(or left), 2 ms
reverse(or right).

> "motor drive" PWM: typically repeats at 20 KHz to 100 KHz; solid lo for off; 1/2
> period lo, 1/2 period hi for half-speed; solid hi for full on.

That's awfully high frequency for motor PWM, your losses will be very
high.


> > H-bridge correctly(it only takes 2 small transistors extra) you can prevent
> > shorts and get a braking channel for "free".
>
> Do you have a pointer to a "correctly-designed" H bridge ?

Depends on your H bridge. If you use a standard H bridge, there is a pin
for forward and a pin for reverse. Drive them both for a disastrous short
circuit, or braking if it is designed correctly. It sounds like you added
logic before the bridge so you have a "go" input and a "dir" input, so you
don't need protection against "both". Here's the design I spoke of:

http://www.bobblick.com/bob/projects/hbridge/hb01.html

Driving both inputs does motor braking.

{Quote hidden}

If you use a relay, why not use a DPDT relay and just one MOSFET and one
diode?

Cheers,

Bob Blick

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\04\23@202641 by Brian Reed

flavicon
face
Start by looking at http://www.reedonline.com/brian/robot/bedlam/logic1.gif

An AND gate is a device with 2 inputs (in this case) and one output.  The
output is always false (0V) unless 'input a' --AND-- 'input b' are both on.

So, when one input to an AND is ON, and PWM is fed to the other input,
the PWM signal will pass through the device.  By wiring the DIR bit through
an inverter to one AND gate in the circuit, only one AND gate could ever be
outputting at one time.

A nice thing about this circuit is that you don't have to programmatically
flip the value of PWM for reversal (like your method to stop):
 stop: DIR = Forward, PWM = 0x00
 stop: DIR = Reverse, PWM = 0xFF

With my circuit:
 stop: PWM = 0x00 (doesn't care about the direction bit).
 full fwd: DIR=Forward, PWM=0xFF
 full rev: DIR=Reverse, PWM=0xFF

- Bri


{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\04\23@230958 by Brian Reed

flavicon
face
Bob,

>www.bobblick.com/bob/projects/hbridge/hb01.html
>Driving both inputs does motor braking.

Cool - I printed that PDF out (the schemo).  I'm trying to figure
out what happens across the motor legs when braking ... both
legs to ground (or V++)?  Or maybe the motor flyback current
makes the circuit apply equal & opposite power?  Hmm the
later might eliminate the need for flyback diodes that I don't see
in your schemo?

Just curious,

- Bri

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\04\23@235339 by Bob Blick

face
flavicon
face
>>www.bobblick.com/bob/projects/hbridge/hb01.html
>>Driving both inputs does motor braking.
>
>Cool - I printed that PDF out (the schemo).  I'm trying to figure
>out what happens across the motor legs when braking ... both
>legs to ground (or V++)?  Or maybe the motor flyback current
>makes the circuit apply equal & opposite power?  Hmm the
>later might eliminate the need for flyback diodes that I don't see
>in your schemo?

The advantage of using TIP series darlington transistors is builtin
pinch-off resistors and freewheel diodes, saving a few parts(plus the
transistors are only 60 cents each in single quantities).

When you drive both inputs, both lower transistors are turned off and the
upper transistors are on, pulling both motor terminals to V+, and braking
occurs.

Cheers,

Bob

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


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