Modeling Arduino in matlab


I’m 2nd year engineering student and I’m new to arduino. I have made a asynchronous buck converter using arduino (the feedback system consists of arduino reading the output voltage and controlling the dutycycle accordingly). Now I would like to model the system in Matlab. I can model the buck converter part as a 2nd order transfer function but the I do not have any idea on how to model the arduino part. I am attaching the step response (5V amplitude) of the real system and the arduino code used.

Is it possible to have a simple "transfer function associated " with this code taking into account the parameters associated with arduino (ADC sampling time, code execution time etc)

Thank you

""" arduino is performing as Integral corrector with gain Ki"""

#include <PWM.h>

int pwmout=10;
int feedback=A0;
float r = 0.50; // inverse of voltage devider gain used at analog input pin
float Ki = 0.1;   // integral gain

float Vdesired = 5;

int f = 15000;  // switching frequency

void setup() {
 bool success = SetPinFrequencySafe(pwmout, f);
 if(success) {
 pwmWrite(pwmout,0); // initial setting
void loop() { 
 float feedback =  feedback_voltage();
 float error = Vdesired - feedback;// discreet integration
 duty = min(duty,255);
 duty = max(0,duty);


float feedback_voltage(){
 float mesures = 0;
 int nb_mesures = 30;
 for (int i = 0; i < nb_mesures; i++){
  mesures = mesures + analogRead(feedback);
 float feedback_voltage = (mesures/nb_mesures)*(5.0/1024.0);
 feedback_voltage = feedback_voltage/r ;
 return feedback_voltage;   

stepresponse.pdf (106 KB)

Did you implement a PID inside Arduino code? If yes, then model it as a PID block.