# francospitale/phmetro architecture

> Architecture diagram of the GitHub repository francospitale/phmetro, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/francospitale/phmetro
- Repository: https://github.com/francospitale/phmetro

## Overview

##### Main Components
- Hardware Elements:
- pH Electrode: The sensor producing a voltage in response to the ion concentration.
- Signal Conditioning Stage: This includes the operational amplifier (for signal amplification), the filter (to remove noise), and level adaptation circuitry to match the input range of the ADC.
- PIC Microcontroller: Performs ADC conversions (configured for 10 bits), processes the incoming analog signal and computes the pH based on calibration formulas.
- LCD Display: Provides a user interface for displaying the computed pH values and calibration menus.

- Software/Firmware Components:
- ADC Configuration & Management: Module handling analog-to-digital conversions.
- Signal Conversion & Calibration Algorithms: Routines implementing the mathematical conversion of millivolt readings to pH values along with calibration adjustments.
- User Interface Logic: Handles display output and perhaps user interactions for adjusting calibration parameters.

##### Component Relationships and Data Flow
- Inside the microcontroller block, show internal divisions: one for ADC reading, another for signal processing (converting voltage to pH), and an output routine interfacing with the LCD.
- Optionally, include a calibration path where known pH buffer values (pH 4, 7, and 10) are used to adjust the conversion parameters.

##### Architectural Patterns and Design Principles
- Clear layering of the system: the analog front-end and the digital processing unit.
- Point out that the design adheres to the embedded systems best practices by decoupling the hardware signal acquisition from the firmware processing.
- That calibration is treated as an essential component, thereby requiring a separate process or module within the firmware for maintaining measurement precision.

##### Technologies and Frameworks
- Hardware technologies: PIC microcontroller, analog components (electrodes, operational amplifiers, filters).
- Software: Firmware written in C that configures and manages the ADC and drives the LCD, along with calibration routines.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Analog Front-End"
        PH_Electrode["pH Electrode"]:::analog
        Conditioning["Signal Conditioning: Amplification,Filtering,Level Adaptation"]:::analog
        PH_Electrode -->|"AnalogSignal"| Conditioning
    end

    subgraph "Digital Processing Unit"
        PIC["PIC Microcontroller (10-bit ADC)"]:::hardware
        Firmware["Firmware (ADC_Config,SignalProcessing,Calibration,UI)"]:::software
        LCD["LCD Display"]:::display
        PIC -->|"ADCData"| Firmware
        Firmware -->|"DisplayOutput"| LCD
        Firmware -->|"CalibrationLoop"| Firmware
    end

    Conditioning -->|"ConditionedSignal"| PIC

    Documentation["Project Documentation"]:::doc
    Firmware -->|"Reference"| Documentation

    click Firmware "https://github.com/francospitale/phmetro/tree/main/PHmetro"
    click Documentation "https://github.com/francospitale/phmetro/blob/main/README.md"

    classDef analog fill:#f9c,stroke:#333,stroke-width:2px;
    classDef hardware fill:#bbf,stroke:#333,stroke-width:2px;
    classDef software fill:#9f9,stroke:#333,stroke-width:2px;
    classDef display fill:#ff9,stroke:#333,stroke-width:2px;
    classDef doc fill:#fcc,stroke:#333,stroke-width:2px;
```
