x. Impulse width measurement: ECCP PWM Meter Example for PIC18F2550, PIC18F24J50 and PIC18F26J50

The version 2 example (get ECCP PWM Meter v2 (x64).zip Downloads section) is adapted for PIC18F24J50 and PIC18F26J50 and Velleman K8055N-2 board (It also works on K8055-1 with PIC18F2xJ50 adapter). The output pins (RC1 = PWM OUT and RC2 = PWM IN) is the same. The example works on PIC18F24J50 or PIC18F26J50 with firmware v2.6.2.hex and later. You must also use the unified LIB_PCUSBProjects v4.2.NET4(x64).dll that is also available from Downloads section.

PIC18 microcontrollers have two (E)CCP units that can operate in three mores: capture, compare and PWM (pulse width modulation). Here is an example on how to program PIC18F2550 CCP unit to measure pulse width. A special *.HEX file, PIC18F2550 firmware v2.6.hex is provided in Downloads section. The example code together with DLL library v3.8 are in ECCP PWM Meter.zip. The timer 1 is used to provide clock for the CCP2 unit. The CC2 button reconfigures timer 1 to produce clock signal with 500 kHz instead of default signal with 1 MHz. Note that CCP2 measures impulse width with a 16-bit resolution. Therefore it is important to adapt the timer 1 clock frequency to use the most of the 16-bit range to achieve higher measurement result accuracy.

The pulse width in impulses can easily be converted in seconds by multiplying it with the length of a clock impulse. If the timer 1 is running on 1 MHz, the clock impulse lasts exactly 1 microsecond.

The original example (get ECCP PWM Meter (x64).zip Downloads section) below is based on a modified Velleman K8055-1 board with PIC18F2550, 4 MHz XTAL crystal and R35 resistor removed.

ECCP PWM Meter application. If no signal is detected on the PWM input, the value of 0 is displayed for pulse width. Click on the picture to enlarge it.

How to measure pulse width a modified Velleman K8055-1 Experiment board. Use PWM1 output for testing. Otherwise, connect an external PWM signal to PWM input to measure it with ECCP PWM Meter application. Click on the photo to enlarge it.