Hi! This is my very first mailing to the list so I hope I dont break any rules (such as writing very long mails)... Tried searching the archieve for servo info but didn't find that much. However, I have a couple of ideas and questions I hope to get some feedback on. First, I've just started with PICs but think I'm catching up pretty fast. I do develop in C, too lazy to learn asm though I know a good asm-coder is pretty sure to generate better code that any C compiler. I'm using the HiTech PICC. I my project for an onboard flight computer for an R/C model, I have a few heavy tasks. One of them is to both monitor and adjust servo channels from the receiver to the servos. Both to generate servo position info and to be able to adjust control throws, exponentials, mixes, gyro-based adjustments etc. Since the servo sampling/pulsing seems to be quite intense for a PIC (I'm developing on 16f877's but the final board could use some other suitable model) I've thought of putting the servo control on a separate PIC. This would communicate (through SPI?) with the main controller. Generally, I'm trying to figure out the most efficient way to both read the servo pulses from the receiver and to generate output pulses. In meantime, I need to have time to respond to requests from the main controller. How many channesl In/Out is feasible to handle if I find an optimal method? (I'm basically assuming 20MHZ clock.) (For a background on servo pulses, see the end of the mail) My original thoughts are: Measure input pulses: --------------------- Connect servos to RB4-7 (ie handle 4 input channels). Interrupt on change-on-pin. Set up TMR1 in timer mode, to run continiously with a wrap-around of at least 40ms. When a pin change, if rising edge, note value of TMR1 for that pin, if falling edge, subtract stored value for that pin go get pulse width (need to account for TMR1 wrap-around). Convert measurements to suitable values for -100% - 100% servo position (or more suitably -128 - 127). Easy enought Generate output pulses: ----------------------- Now it gets trickier... The easy solution (IMHO) is to use two timers. One to initiate the first pulse, should interrupt every 20ms. Then, for every output channel, raise output pin and load timer with the value to wait for the correct width, depending on the desired servo position. At interrupt, lower the pin and do the next channel. Timer0 could be used for pulse length, possibly with an initial fixed value since every pulse is fixed(0,5ms)+variable(0-1ms). But I get into trouble with getting Timer2 (the one unused) count the 20ms between pulse cycles. So, I've tried to figure out a way to use Timer1 for both measurements and for the 20ms repeat. Of course I could code some extra logic to manually count number of TMR2's to prolounge the delay but that consts cycles. Any bright ideas on the timing here and general efficiency? Another issue I might have to consider is that the servo signal span doesn't seem too precise. Right now I'm more onto the idea of requiring zero and full spand calibration at startup to determine correct values. The third 'feature' is that this co-processor needs to be able to communicate with the main controller. I haven't started on this yet, but initial datasheet investigation reveils that SPI would be a good idea. There might perhaps be some timing issues with a heavily interrupt-loaded PIC, through, or? Anyway... All of this just to avoid spending 2 x $24.95 on one of this http://www.al-williams.com/awce/pak7.htm and one of this http://www.al-williams.com/awce/pak8.htm... But mine would be better... ;) ------Servos--------------------------------------- You probably all know this but anyway. Servos are (supposed to be) encoded as high pulses with a variable length of 0,5ms to 1,5ms, corresponding to position, where 1,0ms represents middle or zero deflection. Pulses should be repeated within 20ms which means one can usially generate one pulse for each channel and still have some time to wait until the next 20ms repetition. Regards, Thomas -- 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