Efficient PWM Generation Techniques on the PIC16F877A Using CCP Module and Interrupt-Based Timer Methods
pdf

Keywords

Pulse Width Modulation
PIC16F877A
CCP Module
Interrupt Service Routine
Timer0
Prescaler
Embedded Systems

How to Cite

[1]
P. J. A. Nkansah, E. K. Otu, and B. Prathap, “Efficient PWM Generation Techniques on the PIC16F877A Using CCP Module and Interrupt-Based Timer Methods”, Appl. Eng. Innov. Tech., vol. 3, no. 2, pp. 85–106, Nov. 2026, doi: 10.62777/aeit.v3i2.128.

Abstract

Pulse-width modulation (PWM) is a fundamental technique for DC motor speed control in embedded systems, yet resource-constrained 8-bit microcontrollers impose significant architectural limitations on its implementation. The PIC16F877A, a widely deployed mid-range microcontroller, provides a dedicated Capture/Compare/PWM (CCP) hardware module that produces high-accuracy PWM signals but restricts output to only two physical pins, limiting its utility in multi-actuator systems. This paper presents a systematic experimental evaluation of three PWM generation approaches on the PIC16F877A: the CCP module and two interrupt-driven software techniques using the 16-bit Timer1 and 8-bit Timer0 modules, respectively, with the Timer0 approach further extended through OPTION_REG prescaler configuration. Each technique is characterized with respect to duty cycle accuracy, frequency range, and resolution using a Keysight DSOX1204G digital storage oscilloscope. The CCP module achieves the highest accuracy, with a maximum duty cycle error of 0.36% across tested frequencies. The Timer0-based interrupt service routine technique, while yielding slightly lower accuracy in its base configuration, progressively approaches CCP-level precision through prescaler scaling — reducing duty cycle error at 25% duty cycle from 5.62% at a 1:4 prescale ratio to 1.46% at 1:16 — at the cost of reduced output frequency. The dual-functionality of PIC16F877A I/O pins via the TRIS register is also discussed as a complementary mechanism for efficient pin resource management. The evaluation is conducted at the level of open-loop waveform characterization on a bench oscilloscope. Within this scope, the results indicate that the Timer0 interrupt-driven approach with prescaler tuning offers a favorable balance between duty cycle accuracy and multi-pin flexibility for multi-channel motor control on resource-constrained platforms; closed-loop motor validation remains future work.

pdf

References

M. H. Rashid, Power electronics: devices, circuits, and applications, Fourth edition. Upper Saddle River, NJ: Pearson, 2014.

D. G. Holmes and T. A. Lipo, Pulse Width Modulation for Power Converters. IEEE, 2003. doi: 10.1109/9780470546284.

M. Barr, “Pulse Width Modulation,” Embedded Systems Programming, pp. 103–104, Sep. 2001.

Microchip Technology Inc., “PIC16F87XA Data Sheet: 28/40/44-Pin Enhanced Flash Microcontrollers,” Microchip Technology Inc., Data sheet DS39582B, 2003. [Online]. Available: https://ww1.microchip.com/downloads/en/deviceDoc/39582b.pdf

M. A. Mazidi, D. Causey, and R. D. McKinlay, PIC microcontroller and embedded systems: using Assembly and C for PIC18, Second edition. Noida, India: Pearson India Education Services, 2021.

M. Bates, PIC microcontrollers: an introduction to microelectronics, 2nd ed. Amsterdam ; Boston: Elsevier, Newnes, 2004.

Microchip Technology Inc., “AVR136: Low-Jitter Multi-Channel Software PWM,” Microchip Technology Inc., Chandler, AZ, USA, Application note Atmel-8020C, 2016. [Online]. Available: https://ww1.microchip.com/downloads/en/AppNotes/Atmel-8020-Low-Jitter-Multi-Channel-Software-PWM_ApplicationNote_AVR136.pdf

A. Y. Yousef and M. H. Mostafa, “Dual DC Motor Speed Control Based on Two Independent Digital PWM Signals using PIC16F877A Microcontroller,” Indones. J. Electr. Eng. Comput. Sci., vol. 2, no. 3, pp. 592–606, Jun. 2016, doi: 10.11591/ijeecs.v2.i3.pp592-606.

S. E. Arslan, F. E. Uzun, K. Gürkan, A. Acar, İ. O. Yildirim, and U. Güven, “Realization of SV-PWM motor control algorithm using ARM Cortex-M4 based microcontroller,” presented at the 2016 National Conference on Electrical, Electronics and Biomedical Engineering (ELECO), IEEE, Dec. 2016.

N. Mohan, T. M. Undeland, and W. P. Robbins, Power electronics: converters, applications, and design, 3rd ed. Hoboken, NJ: John Wiley & Sons, 2003.

R. Krishnan, Electric motor drives: modeling, analysis, and control. Upper Saddle River, N.J: Prentice Hall, 2001.

Microchip Technology Inc., “PICmicro Mid-Range MCU Family Reference Manual,” Microchip Technology Inc., Chandler, AZ, USA, Reference manual DS33023A, 1997. [Online]. Available: https://ww1.microchip.com/downloads/en/DeviceDoc/33023a.pdf

A. Y. Yousef and M. H. Mostafa, “Bidirectional Speed Control of DC Motor Based on Pulse Width Modulation using Microcontroller,” Int. J. Sci. Res. Sci. Technol., vol. 1, no. 5, pp. 52–60, 2015.

P. A. Kapadiya, I. R. Shah, and N. D. Mehta, “Study and Implementation of DC Drive using PIC16F877A Microcontroller,” Int. J. Res. Eng. Technol., vol. 03, no. 05, pp. 621–625, May 2014, doi: 10.15623/ijret.2014.0305114.

A. S.M.Bakibillah, N. Rahman, and Md. Anis Uz Zaman, “Microcontroller based Closed Loop Speed Control of DC Motor using PWM Technique,” Int. J. Comput. Appl., vol. 108, no. 14, pp. 15–18, Dec. 2014, doi: 10.5120/18979-0402.

S. Win, “Design and Construction of PIC-Based DC Motor Speed Controller for Small Robots,” Int. J. Sci. Res. Sci. Eng. Technol., pp. 608–615, Jun. 2020, doi: 10.32628/IJSRSET2073133.

M. Abdulhamid and T. Festus, “Design of Pulse Width Modulation Based DC Motor for Electric Vehicle,” J. Sib. Fed. Univ. Eng. Technol., vol. 15, no. 2, pp. 162–176, Apr. 2022.

O. Röpcke, “PWM, a Software Solution for the PIC16CXXX,” Microchip Technology Inc., Chandler, AZ, USA, Application note AN654 (DS00654A), 1997.

G. C. Buttazzo, Hard Real-Time Computing Systems: Predictable Scheduling Algorithms and Applications, vol. 24. in Real-Time Systems Series, vol. 24. Boston, MA: Springer US, 2011. doi: 10.1007/978-1-4614-0676-1.

J. Yiu, The definitive guide to ARM® Cortex®-M3 and Cortex-M4 processors, Third edition. Amsterdam: Elsevier, Newnes, 2014.

Keysight Technologies, “InfiniiVision 1000 X-Series Oscilloscopes: Data Sheet,” Keysight Technologies, Santa Rosa, CA, USA, Data sheet 5992–3484EN, 2024. [Online]. Available: https://www.keysight.com/us/en/assets/7018-06411/data-sheets/5992-3484.pdf

Creative Commons License

This work is licensed under a Creative Commons Attribution 4.0 International License.

Copyright (c) 2026 Prince Jonathan Appau Nkansah, Ernest Kumi Otu, Basappa Prathap (Author)