|Demand Peripherals Robotics and Automation Made Easy|
PWMIN4: Quad Pulse Width Modulation Input
The PWMIN4 peripheral lets you measure the duty cycle of four inputs. Outputs include the duty cycle as a decimal fraction as well as an output that gives the relative timing of the pulses.
The quad PWM input peripheral measures the widths of periodic pulses on each of the four pins on a Baseboard connector. Pulse widths are measured with 16 bits of accuracy for both the high and low periods of a pulse. The clock source driving the pulse width counters ranges from 5 Hertz to 20 MegaHertz.
The PWMIN4 peripheral uses direct input from FPGA pins. That is, the peripheral works best with either of the GPIO cards. More information about the GPIO cards is available here cards/gpio4.html and here cards/gpio4-st.html.
Resources:PWMIN4 has resources to set the sample clock rate, report the duty cycle, and to give a detailed report of the pulse start and stop times.
clksrc : frequency of the PWM sample counters. A clock frequency of zero turns off the peripheral. The frequency is given in Hertz and must be one of the following:
20000000 10000000 5000000 1000000 500000 100000 50000 10000 5000 1000 500 100 50 10 5 0
dutycycle : duty cycles of the four inputs. Dutycycle is a read-only resource that gives the on time as a fraction of a complete cycle. A dash indicates that the input did not complete a full cycle in time permitted by a 16 bit duration counter. Dutycycle works with dpcat.
waveform : relative timing of the four inputs. The waveform gives theclock frequency followed by a comma separated list of values and times between transitions for all four inputs. The values alternate between the four bit value at the input and how long that value (in clock cycles) was held. While more difficult to parse and understand compared to the dutycycle data, the raw sample data retains some of the relative phase information captured by the peripheral.
The peripheral captures three transitions for each of the four input lines. Each transition has a value and duration measured in clock cycles. If all four pins are active the waveform output stream will have 24 numbers on each line.
Only three transitions on a pin are needed to determine the low and high times (and the thus the frequency and duty cycle). Input from a pin is ignored once all three transitions on it have been recorded. This input masking prevents a fast changing input from overflowing the sample buffer. An 'x' in the example below shows this masking.
As an example, consider the following partial output line from the waveform resource for a quad PWM-in peripheral with a 1 MHz clock source:
1000000, 5, 201, 7, 336, 5, 24, 7, 1020, 4, 294, 5, 453, ..... The bits and timing represented in this example are: BITS HELD FOR ... MICROSECONDS 0101 201 0111 336 0101 24 0111 1024 01x0 294 01x1 453
Many radio controlled airplanes use four servos as actuators. Configure the PWMIN4 peripheral to monitor and output the pulse widths from a four channel RC receiver.
The cycle time on an RC reciever is usally 20 milliseconds. A clock rate of 1 MHz gives maximum cycle time of 65 milliseconds. (5 MHz is too fast, giving a maximum cycle time of just over 13 milliseconds.) Since the on time for an RC control pulse is between one and two milliseconds, a time resolution of 1 microsecond corresponds to about 10 bits of precision.
Configure the clock and start the stream of duty cycle readings
dpset pwmin4 clksrc 1000000 dpcat pwmin4 dutycycle