Modeling Arduino in matlab

Hello

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() {
 Serial.begin(115200);
 pinMode(pwmout,OUTPUT);
 pinMode(13,HIGH);
 InitTimersSafe(); 
 bool success = SetPinFrequencySafe(pwmout, f);
 if(success) {
   digitalWrite(13,HIGH);
  }
 pwmWrite(pwmout,0); // initial setting
 delay(10);
 
}
void loop() { 
 float feedback =  feedback_voltage();
 float error = Vdesired - feedback;// discreet integration
 duty=floor(duty+Ki*255*error);
 
 duty = min(duty,255);
 duty = max(0,duty);

 //Serial.println(feedback);
 
 pwmWrite(pwmout,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.