The main aim of this thesis work was
- To create a neural network on PRU that can estimate rotor position and speed using current and voltage data in FOC
- Analyze the performance of the neural network in terms of accuracy and response time against the Hardware encoder
FOC
Field-Oriented Motor Control
- Transforms 3-phase current into a rotating reference frame, controls the torque and reverses back to a 3-phase output
- Results in the highest torque and motor efficiency
- Accurate rotor position needed!
PRU – core
Programmable Real-time Unit
- 32-bit RISC microcontroller(3ns cycle time)
- Single-cycle broadside load and store
- Two-cycle interrupt latency
- 1024-bit wide data bus for broadside interface
- Complete subsystem with flexible DMA
- Single-cycle core extension 32 bit MAC
Test setup and data collection
- Nanotec DB42S03, a 3-phase 4-pole pair BLDC motor, is used
- BP-AM2BLDCSERVO booster pack is used for motor control
- An incremental encoder with 4000 ticks is used to measure rotor position
- R5F core of AM243 LP saves Vα, Vβ, Iα, Iβ, to MSRAM
- 32768 entries of each variable are saved as float32_t format (4 bytes)

Position estimation network
- A fully connected feed-forward network is used for training with 32 inputs, 24 hidden neurons, and 2 outputs
- 70 % of the collected data is used for training and the remaining 30% is used for testing the model
- ReLU is used as the hidden layer activation function
- The sine and cosine of the rotor angle are predicted in the final layer, and the activation function is Tanh
- During training flow, an early stopping is implemented based on the mse error, such that if the training is not. improving over a set of n iterations, then it stops.
- The trained model weights and biases are converted into fixed-point q24 format
- 1st bit(msb) – sign
- 7 bits – integer
- last 24 bits – decimal part
Training results
- Final model predicted with an MSE of 0.00013, which indicates a good level of prediction accuracy
- The entire training took 52 minutes, 2000 epochs



Deployment of the neural network on PRU
- Weights and biases are preloaded into Broadside RAM (BS RAM)
- Industrial Ethernet peripheral (IEP) CMP4 is used to trigger the task manager every 62.5us to sync with motor control, which is also triggered by the same IEP
- During each function call, inputs are loaded into the PRU registers
- Each input is then loaded into the MAC registers with respect to its weights
- For 32 input single neuron, PRU takes 435 cycles
- Tanh LUT for the final layer takes 25 cycles
- Overall, PRU takes a total of 11,462 cycles (34.4us)
Results
- From no load open loop to closed loop, the maximum error is 4.51 degrees (electrical)
- The motor starts in open loop to 500 rpm, then switches to closed loop at 625milliseconds.
- During the experiment, the motor runs steadily at 500 rpm

Limitations
- Data collection is a time-consuming process
- Angle estimation errors can lead to speed estimationinaccuracies as speed is calculated as the derivative of angle
- For different loads, a different neural network is needed
Conclusion
- Designed and trained multiple neural network architectures using Python (PyTorch) specifically to estimate motor speed and rotor position.
- Achieved over 95% accuracy in both open-loop and closed-loop control for rotor angle and speed estimation.
- Successfully deployed trained models onto the Programmable Real-time Unit (PRU) 32-bit RISC core using Assembly language.
- Optimized neural network execution using fast-access broadside memories and data processing accelerators on the PRU core.
- Tuned PI and PID controllers for precise control of motor currents and speed in a 3-phase BLDC motor system