[Caution: Researched but untested ideas below] On Fri, 20 Apr 2001, Mike Evans 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'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?) 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 mailto:piclist-unsubscribe-request@mitvma.mit.edu