detecting pulse width using a PIC

Status
Not open for further replies.

mr. mister

New Member
hello all

i'm trying to feed the output of one channel of a 6 channel receiver into a PIC, the channel is controlled by a switch i can flick on or off

i've been told that the pulse window for the output generated by the receiver is about 20ms, hence in this case i am assuming that since the channel is controlled by an on and off switch there will only be two types of pulse widths generated

what i want to know is how do i go about using the PIC to detect one pulse width as a high and the other as a low???

cheers in advance.
 
mikroBasic has an "Button ()" comand that waits for a I/O pin to thurn high for a certan amout of time.This cod be used to detect an pulse
 
Most PIC BASIC's include the 'PulseIn' command, this measures the width of an incoming pulse.

It's simple to do in assembler as well, the pulse width varies from 0.5mS to 1.5mS (at a 20mS repetition rate). Simply check the input line until it goes high (start of the pulse), then keep incrementing a register (or more than one if required) until the input goes low again. If required, after each increment you could call a delay, in order to keep the requirements down to a single register - a 10uS delay would give a value from 50 to 150, which fits nicely in a single 8 bit register.

Most PIC's also have a CCP facility, you can use that to capture the incoming pulse width, but for R/C pulses a simple software loop is more than good enough.
 
mr. mister said:
can someone give me a code example, if that isn't asking for too much???

will be much appreciated

Check my IR tutorials, they measure they width of the incoming pulses.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…