PIC18Fxxx DC Servomotor using PIC18F452 with Proteus Simulation

Summary of PIC18Fxxx DC Servomotor using PIC18F452 with Proteus Simulation


This project implements a PID-based closed-loop DC servomotor control system on a PIC18F452, featuring trapezoidal motion profiling, encoder feedback, RS232 command/tuning, EEPROM storage, and Proteus VSM simulation for development and testing.

Parts used in the PIC18F452 DC Servomotor Project:

  • PIC18F452 Microcontroller
  • DC Servomotor
  • Motor Driver IC (PWM controlled)
  • Incremental Encoder
  • External I2C EEPROM (24C01)
  • RS232 Interface (USART)
  • Power Supply (24V motor, 5V logic)
  • Discrete components (resistors, capacitors, switches)

Introduction

This project demonstrates a DC servomotor control system based on Microchip Application Note AN696, implemented using the PIC18F452 microcontroller.
It is a complete microcontroller project that combines PID-based motor control, motion profiling, and RS232 serial communication.
Designed for embedded systems learning, this project shows how real-time control algorithms work inside a practical electronics application.
Using Proteus simulation, the entire system can be tested virtually before moving to hardware.
It is ideal for engineers and students exploring motor control, firmware design, and industrial-style motion systems.PIC18F servo control is demonstrated in this project using the PIC18F452 microcontroller to implement closed-loop PID motor positioning with encoder feedback, PWM drive, and Proteus simulation for accurate motion control.

PIC18F DC servo motor prototype
Illustrative View of the Concept.

How the Project Works (Overview)

The PIC18F452 controls a DC servomotor using a closed-loop PID control algorithm.
Motor position and speed feedback are obtained through encoder pulses counted by hardware timers.
Based on a predefined motion profile, the firmware continuously calculates position error, applies PID compensation, and updates PWM duty cycle in real time.
Commands are sent over RS232, allowing motion segments, PID gains, and execution modes to be modified dynamically.

Block Diagram / Workflow Explanation

  1. RS232 Interface receives motion commands and configuration parameters

  2. PIC18F452 MCU processes commands and manages motion profiles

  3. Trajectory Generator computes velocity and position references

  4. Encoder Feedback updates actual motor position and velocity

  5. PID Controller calculates correction based on position error

  6. PWM Module (CCP1) drives the motor driver

  7. DC Servomotor executes precise controlled movement

This loop runs continuously inside a Timer2 interrupt, ensuring deterministic real-time control.

Key Features

  • PID-based closed-loop DC servomotor control

  • Trapezoidal motion profile generation (acceleration, velocity, deceleration)

  • RS232 command-based motor control and tuning

  • External EEPROM storage for motion segments and PID gains

  • Encoder-based position and velocity feedback

  • PWM motor drive using CCP module

  • Multiple execution modes via DIP switches

  • Designed for Proteus simulation and hardware deployment

Components Used

  • PIC18F452 Microcontroller

  • DC Servomotor

  • Motor Driver IC (PWM controlled)

  • Incremental Encoder

  • External I²C EEPROM (24C01)

  • RS232 Interface (USART)

  • Power Supply (24V motor, 5V logic)

  • Discrete components (resistors, capacitors, switches)

Applications

  • Industrial motion control training systems

  • Robotics actuator control

  • CNC axis simulation and learning platforms

  • Mechatronics and automation projects

  • Embedded motor control education

  • Servo tuning and PID experimentation

Explanation of Code (High-Level)

The firmware is written in MPLAB C18 and structured around real-time control concepts:

  • Interrupt Service Routine (ISR)
    Executes servo calculations at fixed intervals using Timer2.

  • Trajectory Generator (UpdTraj)
    Produces trapezoidal velocity and position profiles.

  • Position Update (UpdPos)
    Reads encoder pulses using Timer0 and Timer1.

  • PID Controller (CalcPID)
    Computes PWM duty cycle using proportional, integral, and derivative gains.

  • Command Parser (DoCommand)
    Interprets RS232 commands for motion segments, PID tuning, and execution control.

  • EEPROM Interface
    Stores and retrieves motion profile data and PID parameters via I²C.

Source Code

Download
#define	DIST	0						// Array index for segment distance
#define	VEL	1						// Array index for segment vel. limit
#define	ACCEL	2						// Array index for segment accel.
#define	TIME	3						// Array index for segment delay time
#define	INDEX	PORTBbits.RB0		// Input for encoder index pulse
#define	NLIM	PORTBbits.RB1		// Input for negative limit switch
#define	PLIM	PORTBbits.RB2		// Input for positive limit switch
#define	GPI	PORTBbits.RB3		// General purpose input
#define	MODE1	!PORTBbits.RB4		// DIP switch #1
#define	MODE2	!PORTBbits.RB5		// DIP switch #2
#define	MODE3	!PORTBbits.RB6		// DIP switch #3
#define	MODE4	!PORTBbits.RB7		// DIP switch #4
#define	SPULSE	PORTCbits.RC5	// Software timing pulse output
#define	ADRES	ADRESH				// Redefine for 10-bit A/D converter

Proteus Simulation

In Proteus VSM, the PIC18F452 executes the firmware while the DC servomotor responds to PWM signals in real time.
Encoder pulses feed back into Timer0 and Timer1, allowing accurate position tracking.
RS232 terminal input enables live tuning of PID gains and motion segments, making the simulation highly interactive and educational.

(FAQs)

1: Can this project run fully in Proteus simulation?

Yes, the complete system is designed for Proteus VSM testing.

2: Which PIC microcontrollers are compatible?

PIC18Fxxx devices with PWM, timers, and USART support are suitable.

3: How is motor position feedback implemented?

Using encoder pulses counted by Timer0 and Timer1.

4: Can PID parameters be changed during runtime?

Yes, via RS232 commands and stored in EEPROM.

5: What motion profile is used?

Trapezoidal motion profile with acceleration, velocity limit, and deceleration.

6: What baud rate does RS232 use?

19200 baud at 20 MHz system clock.

7: Is this suitable for real hardware deployment?

Yes, the design closely matches industrial servo control principles.

8: Can this be modified for stepper motors?

The control logic would require changes, but the framework is reusable.

Conclusion

This PIC18F452 DC servomotor project is a powerful example of real-time embedded motor control.
It combines PID algorithms, motion profiling, EEPROM management, and serial communication into one cohesive system.
Whether used in Proteus simulation or real hardware, it offers excellent learning value for anyone working in embedded systems and motor control.

Quick Solutions to Questions related to PIC18F452 DC Servomotor Project:

  • Can this project run fully in Proteus simulation?
    Yes, the complete system is designed for Proteus VSM testing.
  • Which PIC microcontrollers are compatible?
    PIC18Fxxx devices with PWM, timers, and USART support are suitable.
  • How is motor position feedback implemented?
    Using encoder pulses counted by Timer0 and Timer1.
  • Can PID parameters be changed during runtime?
    Yes, via RS232 commands and stored in EEPROM.
  • What motion profile is used?
    Trapezoidal motion profile with acceleration, velocity limit, and deceleration.
  • What baud rate does RS232 use?
    19200 baud at 20 MHz system clock.
  • Is this suitable for real hardware deployment?
    Yes, the design closely matches industrial servo control principles.
  • Can this be modified for stepper motors?
    The control logic would require changes, but the framework is reusable.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter