Skip to content

NablaCheese505/RPM-Meter-PIC18F4550

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚙️ Optical Digital Tachometer using PIC18F4550 & ITR8102

Render vs Physical Model
C PIC C Compiler SolidWorks Proteus

📖 Description

A fully functional Digital Tachometer (RPM meter) designed from scratch, integrating mechanical CAD, optical signal conditioning, and low-level embedded C programming. The system uses an ITR8102 optical sensor to detect the rotation of a DC motor through a custom 3D-printed 20-slot encoder disk. A PIC18F4550 microcontroller calculates the RPM in real-time using Hardware Interrupts (INT0) and Timers (Timer1), displaying the result on a 16x2 LCD.

Project in action

🛠️ Bill of Materials (BOM)

  • 1x PIC18F4550 Microcontroller (Tested on Miuva development board)
  • 1x ITR8102 Optical Sensor (Photointerrupter)
  • 1x DC Motor
  • 1x 16x2 LCD Display
  • 2x 10kΩ Resistors (for pull-ups/sensor conditioning)
  • Custom 3D-printed parts (Base, legs, motor stand, and 20-slot encoder disk)
  • 1x Microcontroller Programmer (e.g., PICkit 3 / PICkit 4)
  • 1x Variable DC Power Supply

🧠 Low-Level Configuration & Mathematics

This project relies heavily on real-time processing using the microcontroller's hardware peripherals rather than blocking delays:

  • Hardware Interrupt (INT0): The ITR8102 sensor output is connected to the RB0/INT0 pin. In the current implementation, the microcontroller triggers an interrupt on every falling edge (H_TO_L), accurately counting the 20 slots of the disk.
    • 💡 Engineering Insight: Through testing and experience, I realized that configuring the interrupt to trigger "on change" (detecting both rising and falling edges) would count 40 pulses per revolution instead of 20, effectively doubling the sensor's resolution.
  • Timer1 (Timekeeping): Timer1 is configured with an internal clock and a 1:8 prescaler. It triggers an interrupt every 12.5 ms. A counter keeps track of these interrupts; when 80 ticks pass, exactly 1 second has elapsed.
  • RPM Calculation: With 20 slots per revolution, the base formula is: RPM = (60 seconds * Pulses counted in 1 second) / 20 slots Simplified in code to save CPU cycles: RPM = 3 * pulses

⚙️ Mechanical Design (Rapid Prototyping)

The 3D printed base, legs, and motor stand were designed in SolidWorks. It's worth noting that this mechanical assembly is a rapid overnight prototype. It was designed and printed in a single night to meet a tight deadline. While it isn't structurally perfect or highly optimized, it successfully fulfills its core purpose: keeping the motor shaft, the encoder disk, and the optical sensor perfectly aligned for accurate readings.

📊 Experimental Validation (Oscilloscope vs. LCD)

To validate the sensor's signal integrity and the software's mathematical accuracy, the optical pulses were measured using a digital oscilloscope alongside the LCD output.

Experimental validation

🧮 The Proof

In the video above, we can observe two readings:

  • LCD Display: ~240 RPM
  • Oscilloscope: ~80 Hz (80 pulses per second)

Does the math add up? Yes!

  1. Convert the LCD RPM to Revolutions Per Second (RPS):
    240 RPM / 60 seconds = 4 RPS
  2. Multiply by the number of slots on the encoder disk (20 slots = 20 pulses per revolution):
    4 RPS * 20 pulses/rev = 80 pulses/second = 80 Hz

This perfectly confirms that the microcontroller is reading the physical hardware exactly as intended without losing any pulses.

📁 Repository Structure

RPM-METER-PIC18F4550/
│
├── binaries/
│   └── rpm_meter.hex                  # Compiled file ready to flash
│
├── docs/
│   ├── render.jpg                     # SolidWorks 3D Render
│   ├── render_vs_physicalmodel.jpg    # CAD vs Reality comparison
│   ├── schematic.png                  # Proteus circuit schematic
│   ├── scope_view.gif                 # Oscilloscope validation gif
│   ├── uC-P4_TACOMETRO_DIGITAL.pdf    # Full project report (Spanish)
│   └── working_project.gif            # Gameplay/Working demonstration
│
├── firmware/
│   ├── 18F4550.h                      # PIC18F4550 definitions
│   ├── MLCD.c                         # Custom 16x2 LCD driver library
│   ├── rpm_meter.c                    # Main logic, INT0, and Timer1 ISRs
│   └── rpm_meter.ccspjt               # CCS C Compiler project file
│
├── hardware/
│   └── Encoder.pdsprj                 # Proteus simulation file
│
├── mechanical/
│   ├── base.STL                       # 3D printable base
│   ├── legs_x4.STL                    # 3D printable legs
│   ├── motor_stand_x2.STL             # 3D printable motor stand
│   └── solidworks_rpm_mete_pack_and_go.zip # Full SolidWorks source files
│
└── README.md                          # This documentation file

💻 Software Requirements

  • Compiler: CCS PIC C Compiler
  • Simulation: Proteus Design Suite
  • CAD Software: SolidWorks (To open the .zip in the mechanical/ folder)
  • Flashing Tool: MPLAB X IPE (or PICkit standalone software)
  • Slicer Software Just in case you want to 3D print the provided .STL files

🚀 How to Build and Run

  1. Clone this repository.
  2. Mechanical: Unzip solidworks_rpm_mete_pack_and_go.zip to modify the 3D design, or directly slice the .STL files in the /mechanical folder to 3D print the parts.
  3. Firmware: Open rpm_meter.ccspjt in CCS C Compiler and compile it to generate a new .hex file.
  4. Flash the .hex to your PIC18F4550 using a programmer.
  5. Wire the circuit according to schematic.png, power the motor, and watch the RPMs update in real-time!

About

Real-time RPM meter utilizing PIC18F4550 hardware interrupts (INT0) and an ITR8102 optical sensor. Complete with CAD files and oscilloscope validation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages