I'm just getting started with PIC processors, driven mainly by a shortage of the simpler PICAXE from my local retailer. My question is, how do I read the length of a PWM pulse on a certain input pin (analogous to the PULSIN command on PICAXEs). I'm using the MPLab IDE, and the specific PIC in question is the 12F683.
Secondly, (sorry to combine two questions into one), are there libraries out there that contain 'common' functions (PWM output, i2c support and the like)? Google's turning up dry-ish, but it seems to me that such libraries have to be out there, somewhere…. Thanks for any help!
EDIT: the language is C, and the PWM signal is the output from a RC reciever intended for a servo, so, it is a 1-2 ms high pulse every 20 ms (if I understand that correctly)
Best Answer
There are various ways to measure the width of incoming pulses. Which is most appropriate depends on the width of the pulses, what accuracy you need, and which peripherals your PIC has. Some possibilities are:
This method allows for the shortest duration pulses and has the most accuracy, but takes two CCP modules.
There are other methods too, but without knowing more about the characteristics of your pulses it's not worth spending time on them. Given that your PIC has a single CCP module and timer 1 with gating option, methods 2 and 4 are worth considering. Again, it would help to know more about the pulse characteristics.
One thing I didn't metion is overflow handling for long pulses, but if your pulses are known to be short enough this is not a issue.