# valmyr/fpoc architecture

> Architecture diagram of the GitHub repository valmyr/fpoc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/valmyr/fpoc
- Repository: https://github.com/valmyr/fpoc

## Overview

FpOC is an FPGA-based PMSM/BLDC current-control system. Its documented demo samples phase currents and rotor angle, computes a torque/current-control response, drives three-phase PWM, and optionally reports target and actual current over UART. The README identifies the top-level interface and major FOC capabilities; source excerpts were unavailable, so internal module wiring is shown only where the documented design and module roles support it.

Main entry points: [`RTL/foc/foc_top.v`](https://github.com/valmyr/fpoc/blob/main/RTL/foc/foc_top.v) (FOC Controller), [`RTL/fpga_top.v`](https://github.com/valmyr/fpoc/blob/main/RTL/fpga_top.v) (FPGA Top), [`RTL/i2c_register_read.v`](https://github.com/valmyr/fpoc/blob/main/RTL/i2c_register_read.v) (I2C Register Read), [`RTL/adc_ad7928.v`](https://github.com/valmyr/fpoc/blob/main/RTL/adc_ad7928.v) (AD7928 ADC Interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integration["Board Integration"]
  node_fpga["FPGA Top<br/>[fpga_top.v]"]
end

subgraph group_sensing["Sensing"]
  node_i2c["I2C Register Read"]
  node_adc["AD7928 ADC Interface<br/>[adc_ad7928.v]"]
end

subgraph group_control["FOC Control"]
  node_foc["FOC Controller<br/>[foc_top.v]"]
  node_clarke["Clarke Transform<br/>[clark_tr.v]"]
  node_park["Park Transform<br/>[park_tr.v]"]
  node_sincos["Sine Cosine<br/>[sincos.v]"]
  node_pi["PI Controller<br/>[pi_controller.v]"]
  node_hold["Hold Detection<br/>[hold_detect.v]"]
  node_polar["Cartesian To Polar<br/>[cartesian2polar.v]"]
  node_svpwm["SVPWM Generator<br/>[svpwm.v]"]
end

subgraph group_output["Outputs"]
  node_uart["UART Monitor<br/>[uart_monitor.v]"]
end

node_encoder(("AS5600 Encoder"))
node_phase_currents(("Phase Currents"))
node_motor_driver(("Motor Driver"))
node_serial(("Serial Monitor"))

node_encoder -->|"provides angle"| node_i2c
node_fpga -->|"reads registers"| node_i2c
node_phase_currents -->|"analog currents"| node_adc
node_fpga -->|"samples currents"| node_adc
node_i2c -->|"angle data"| node_foc
node_adc -->|"current samples"| node_foc
node_foc -->|"transforms currents"| node_clarke
node_foc -->|"transforms currents"| node_park
node_foc -->|"uses angle"| node_sincos
node_foc -->|"controls current"| node_pi
node_foc -->|"checks hold"| node_hold
node_foc -->|"converts command"| node_polar
node_foc -->|"generates PWM"| node_svpwm
node_fpga -->|"runs control"| node_foc
node_fpga -->|"sends monitor data"| node_uart
node_uart -->|"transmits values"| node_serial
node_fpga -->|"outputs three-phase PWM"| node_motor_driver

click node_fpga "https://github.com/valmyr/fpoc/blob/main/RTL/fpga_top.v"
click node_i2c "https://github.com/valmyr/fpoc/blob/main/RTL/i2c_register_read.v"
click node_adc "https://github.com/valmyr/fpoc/blob/main/RTL/adc_ad7928.v"
click node_foc "https://github.com/valmyr/fpoc/blob/main/RTL/foc/foc_top.v"
click node_clarke "https://github.com/valmyr/fpoc/blob/main/RTL/foc/clark_tr.v"
click node_park "https://github.com/valmyr/fpoc/blob/main/RTL/foc/park_tr.v"
click node_sincos "https://github.com/valmyr/fpoc/blob/main/RTL/foc/sincos.v"
click node_pi "https://github.com/valmyr/fpoc/blob/main/RTL/foc/pi_controller.v"
click node_hold "https://github.com/valmyr/fpoc/blob/main/RTL/foc/hold_detect.v"
click node_polar "https://github.com/valmyr/fpoc/blob/main/RTL/foc/cartesian2polar.v"
click node_svpwm "https://github.com/valmyr/fpoc/blob/main/RTL/foc/svpwm.v"
click node_uart "https://github.com/valmyr/fpoc/blob/main/RTL/uart_monitor.v"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_fpga toneBlue
class node_i2c,node_adc toneAmber
class node_foc,node_clarke,node_park,node_sincos,node_pi,node_hold,node_polar,node_svpwm toneMint
class node_uart toneRose
class node_encoder,node_phase_currents,node_motor_driver,node_serial toneIndigo
```

## Components

### Board Integration

- [FPGA Top](https://github.com/valmyr/fpoc/blob/main/RTL/fpga_top.v): `RTL/fpga_top.v`

### Sensing

- [I2C Register Read](https://github.com/valmyr/fpoc/blob/main/RTL/i2c_register_read.v): `RTL/i2c_register_read.v`
- [AD7928 ADC Interface](https://github.com/valmyr/fpoc/blob/main/RTL/adc_ad7928.v): `RTL/adc_ad7928.v`

### FOC Control

- [FOC Controller](https://github.com/valmyr/fpoc/blob/main/RTL/foc/foc_top.v): `RTL/foc/foc_top.v`
- [Clarke Transform](https://github.com/valmyr/fpoc/blob/main/RTL/foc/clark_tr.v): `RTL/foc/clark_tr.v`
- [Park Transform](https://github.com/valmyr/fpoc/blob/main/RTL/foc/park_tr.v): `RTL/foc/park_tr.v`
- [Sine Cosine](https://github.com/valmyr/fpoc/blob/main/RTL/foc/sincos.v): `RTL/foc/sincos.v`
- [PI Controller](https://github.com/valmyr/fpoc/blob/main/RTL/foc/pi_controller.v): `RTL/foc/pi_controller.v`
- [Hold Detection](https://github.com/valmyr/fpoc/blob/main/RTL/foc/hold_detect.v): `RTL/foc/hold_detect.v`
- [Cartesian To Polar](https://github.com/valmyr/fpoc/blob/main/RTL/foc/cartesian2polar.v): `RTL/foc/cartesian2polar.v`
- [SVPWM Generator](https://github.com/valmyr/fpoc/blob/main/RTL/foc/svpwm.v): `RTL/foc/svpwm.v`

### Outputs

- [UART Monitor](https://github.com/valmyr/fpoc/blob/main/RTL/uart_monitor.v): `RTL/uart_monitor.v`

### Other components

- **AS5600 Encoder**
- **Phase Currents**
- **Motor Driver**
- **Serial Monitor**

## Connections

- AS5600 Encoder → I2C Register Read: provides angle
- FPGA Top → I2C Register Read: reads registers
- Phase Currents → AD7928 ADC Interface: analog currents
- FPGA Top → AD7928 ADC Interface: samples currents
- I2C Register Read → FOC Controller: angle data
- AD7928 ADC Interface → FOC Controller: current samples
- FOC Controller → Clarke Transform: transforms currents
- FOC Controller → Park Transform: transforms currents
- FOC Controller → Sine Cosine: uses angle
- FOC Controller → PI Controller: controls current
- FOC Controller → Hold Detection: checks hold
- FOC Controller → Cartesian To Polar: converts command
- FOC Controller → SVPWM Generator: generates PWM
- FPGA Top → FOC Controller: runs control
- FPGA Top → UART Monitor: sends monitor data
- UART Monitor → Serial Monitor: transmits values
- FPGA Top → Motor Driver: outputs three-phase PWM
