Skip to content

Ahmed-Faraaz/pacemaker-controller-frdmk64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Pacemaker Controller — FRDM-K64 & Device Controller-Monitor

This project implements a multi-mode cardiac pacemaker and external Device Controller-Monitor (DCM). The system was developed for MT 3K04 based on the Boston Scientific Pacemaker System challenge.

The pacemaker logic runs on a FRDM-K64F Freedom board, while the heart model is represented using an STM32 Nucleo board with supporting driver circuitry. Pacemaker control logic is modeled in MATLAB Simulink/Stateflow, and the DCM is built in Python with a graphical user interface, SQL-backed parameter storage, and UART-based serial communication.

This project is an academic embedded systems/control project and is not intended for clinical or medical use.


Project Overview

The goal of this project was to design, implement, and test a programmable pacemaker system with multiple pacing modes, real-time hardware interaction, and an external control interface.

The system consists of two major components:

  1. Pacemaker Controller

    • Runs on the FRDM-K64F board.
    • Implements pacing logic generated from Simulink/Stateflow.
    • Interfaces with sensing and pacing hardware.
  2. Device Controller-Monitor (DCM)

    • Python desktop application.
    • Allows users to configure pacemaker parameters.
    • Stores user credentials and programmed parameters.
    • Communicates with the pacemaker through UART serial communication.

Key Features

  • Multi-mode pacemaker control logic
  • MATLAB Simulink/Stateflow implementation
  • Auto-generated embedded control code for FRDM-K64F
  • Python-based DCM with GUI
  • SQL-backed user and parameter storage
  • UART serial communication between DCM and pacemaker
  • Support for programmable pacing parameters
  • Rate-adaptive pacing using accelerometer input
  • Hardware-in-the-loop testing with a simulated heart platform
  • Egram window for signal visualization

Supported Pacemaker Modes

The pacemaker supports the following permanent pacing modes:

Mode Description
AOO Atrial asynchronous pacing
VOO Ventricular asynchronous pacing
AAI Atrial demand pacing
VVI Ventricular demand pacing
AOOR Rate-adaptive atrial asynchronous pacing
VOOR Rate-adaptive ventricular asynchronous pacing
AAIR Rate-adaptive atrial demand pacing
VVIR Rate-adaptive ventricular demand pacing
DDDR Dual-chamber, rate-responsive pacing

Each mode supports programmable parameters related to pacing rate, pulse characteristics, refractory periods, sensing, and rate adaptation.


Programmable Parameters

Supported parameter categories include:

  • Pulse Parameters

    • Pulse amplitude
    • Pulse width
  • Rate Parameters

    • Lower Rate Limit (LRL)
    • Upper Rate Limit (URL)
    • Maximum Sensor Rate (MSR)
    • Atrial Refractory Period (ARP)
    • Ventricular Refractory Period (VRP)
    • AV delay
  • Rate-Adaptive Parameters

    • Activity threshold
    • Reaction time
    • Recovery time
    • Response factor
    • Maximum sensor rate

System Architecture

Device Controller-Monitor
        │
        │ UART Serial Communication
        ▼
FRDM-K64F Pacemaker Controller
        │
        │ Pacing / Sensing Signals
        ▼
STM32 Nucleo Heart Simulator + Driver Circuitry

The DCM is responsible for programming and interrogating the pacemaker. The FRDM-K64F board runs the pacing logic and communicates with the heart simulator through sensing and pacing hardware interfaces.


Hardware Overview

Pacemaker Platform

The pacemaker controller is implemented on the FRDM-K64F Freedom board.

Responsibilities include:

  • Running generated pacemaker control logic
  • Receiving programmed parameters from the DCM
  • Processing atrial and ventricular sensing inputs
  • Delivering pacing outputs
  • Supporting rate-adaptive pacing using accelerometer data
  • Sending device status and Egram data back to the DCM

Heart Simulator Platform

The heart simulator is implemented using an STM32 Nucleo board with driver circuitry.

Responsibilities include:

  • Simulating atrial and ventricular heart activity
  • Providing sensed signals to the pacemaker
  • Receiving pacing pulses from the pacemaker
  • Supporting hardware-in-the-loop validation of pacing modes

Simulink / Stateflow Design

The pacemaker control logic is modeled using MATLAB Simulink and Stateflow.

The model is divided into three major sections:

1. DCM Interface

Handles communication between the pacemaker and the external DCM.

Responsibilities include:

  • Receiving programmed parameters
  • Receiving selected pacing mode
  • Handling serial communication inputs
  • Processing accelerometer inputs for rate adaptation

2. Main Stateflow Logic

Contains the main pacing decision logic.

Responsibilities include:

  • Mode selection
  • Atrial and ventricular pacing decisions
  • Sensing and inhibition logic
  • Refractory period handling
  • Rate-adaptive behaviour
  • AV delay timing
  • Dual-chamber pacing coordination

3. Hardware Outputs

Maps abstract pacing and sensing states to physical hardware pins.

Responsibilities include:

  • Driving atrial and ventricular pacing outputs
  • Controlling sensing and impedance-related outputs
  • Driving LEDs and hardware indicators
  • Mapping Simulink signals to board-level outputs

Rate-Adaptive Pacing

Rate-adaptive modes use accelerometer data to estimate patient activity and adjust pacing rate accordingly.

The rate-adaptive subsystem:

  1. Reads accelerometer input.
  2. Computes activity magnitude.
  3. Smooths the activity signal.
  4. Maps activity level to a target pacing rate.
  5. Adjusts pacing rate between the Lower Rate Limit and Maximum Sensor Rate.
  6. Uses reaction and recovery time settings to avoid abrupt rate changes.

This allows the simulated pacemaker to increase pacing rate during higher activity and gradually return to baseline during rest.


Mode Implementation Overview

Each pacing mode is implemented using Stateflow states with pacing and timing logic.

AOO / VOO

Asynchronous pacing modes.

  • Pace at a fixed interval derived from LRL.
  • Do not respond to sensed cardiac activity.
  • Alternate between charging and pacing states.

AAI / VVI

Demand pacing modes.

  • Sense atrial or ventricular activity.
  • Inhibit pacing when intrinsic activity is detected.
  • Use refractory periods to prevent inappropriate sensing.

AOOR / VOOR

Rate-adaptive asynchronous modes.

  • Extend AOO and VOO behaviour.
  • Adjust pacing period based on activity-derived sensor rate.

AAIR / VVIR

Rate-adaptive demand pacing modes.

  • Extend AAI and VVI behaviour.
  • Include sensing, inhibition, refractory periods, and rate adaptation.

DDDR

Dual-chamber rate-responsive pacing.

  • Supports both atrial and ventricular sensing.
  • Coordinates pacing between chambers.
  • Incorporates AV delay.
  • Uses rate-adaptive pacing behaviour.

Device Controller-Monitor

The DCM is a Python desktop application used to configure, monitor, and communicate with the pacemaker.

Key features include:

  • Tkinter-based graphical user interface
  • User authentication
  • Support for up to 10 users
  • Secure password handling
  • Per-user pacemaker parameter storage
  • SQL database for users and parameters
  • Mode-specific parameter editing
  • Egram display window
  • Serial communication over UART
  • Pacemaker programming and interrogation
  • Send/receive confirmation and communication status feedback

Serial Communication

The DCM communicates with the pacemaker using UART.

The serial communication module supports:

  • Parameter packing into byte arrays
  • Parameter unpacking from received messages
  • Pacemaker programming
  • Pacemaker interrogation
  • Communication status checking
  • Device identity handling
  • Error and confirmation feedback

Repository Structure

pacemaker-controller/
├── dcm/                         # Python DCM application, GUI, database, and serial communication
├── simulink/                    # Simulink and Stateflow pacemaker models
├── firmware/                    # Generated or embedded pacemaker code
├── docs/                        # Reports, diagrams, and project documentation
├── tests/                       # Test cases and validation notes
├── artifacts/                   # Screenshots, plots, logs, and demo outputs
├── README.md
└── requirements.txt

How to Run

1. Install Python Dependencies

Create and activate a virtual environment:

python -m venv .venv
.venv\Scripts\activate

Install dependencies:

pip install -r requirements.txt

If a requirements file is not available, install the core dependencies manually:

pip install pyserial

Tkinter and SQLite are typically included with standard Python installations.


2. Run the DCM

From the repository root, run the DCM application:

python dcm/main.py

If the project uses a different entry-point file, run the main GUI script inside the dcm/ folder.


3. Connect Hardware

Connect the system hardware before programming or interrogating the pacemaker:

  1. Connect the FRDM-K64F pacemaker board to the computer.
  2. Connect the STM32 Nucleo heart simulator to the pacemaker driver circuitry.
  3. Confirm that the correct serial port is selected in the DCM.
  4. Program or interrogate the pacemaker through the DCM interface.

4. Run Simulink Model

Open the Simulink model in MATLAB and deploy it to the FRDM-K64F board.

General workflow:

  1. Open MATLAB.
  2. Open the pacemaker Simulink model.
  3. Confirm hardware support package settings.
  4. Build and deploy the model to the FRDM-K64F.
  5. Use the DCM to configure mode and parameters.
  6. Validate pacing behaviour using the heart simulator.

Testing

Testing covered both pacemaker control logic and DCM functionality.

Pacemaker Mode Testing

Test cases were developed for:

  • AOO
  • VOO
  • AAI
  • VVI
  • AOOR
  • VOOR
  • AAIR
  • VVIR
  • DDDR

Tests verified pacing timing, sensing response, refractory behaviour, rate adaptation, and mode-specific outputs.

DCM Testing

The DCM was tested for:

  • User login and authentication
  • User creation limits
  • Parameter validation
  • Mode selection
  • Database storage and retrieval
  • Serial communication failures
  • Known and unknown pacemaker connection scenarios
  • Egram window behaviour
  • GUI responsiveness

Communication Testing

Serial communication tests included:

  • No connected device
  • Known device connected
  • New device connected
  • Parameter send and receive confirmation
  • Interrogation response handling
  • Error and timeout scenarios

Requirements Summary

Pacemaker Requirements

  • Implement all specified pacing modes.
  • Support programmable pacing parameters.
  • Use hardware-hiding abstractions through Simulink subsystems.
  • Support sensing, pacing, and refractory timing.
  • Implement rate-adaptive behaviour using accelerometer input.
  • Communicate with the DCM over UART.

DCM Requirements

  • Display and edit programmable parameters.
  • Store user credentials and mode parameters.
  • Support up to 10 users.
  • Communicate with the pacemaker through serial telemetry.
  • Display communication status.
  • Provide Egram visualization.
  • Support pacemaker programming and interrogation.

Current Status

The project demonstrates a working academic pacemaker control system with embedded control logic, hardware-in-the-loop testing, and an external Python-based controller-monitor.

The implementation shows integration across:

  • Embedded systems
  • Model-based design
  • State-machine control
  • Serial communication
  • GUI development
  • SQL-backed parameter storage
  • Hardware testing

Contributors

  • Faraaz Ahmed
  • Manav Bal
  • Daksh Mathur
  • Armin Sound
  • Gavin Carrol
  • Manav Bal

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages