problems in thingpeak and voltage sensed not displaying

I have already tested code for updating sensor values on thingspeak and it worked properly.
Now I am writing a program for a given source voltage to remain around 14.85V always and to display the same value continuously on thingspeak.
The code is below:

#include "TimerOne.h"
#include <SoftwareSerial.h>
int source_voltage = A0;
long int value_temp;
float analog(int);
float value_temp1;
int i=0,j=0;
int freq=10;  
#define DEBUG FALSE //comment out to remove debug msgs

//*-- Hardware Serial
#define _baudrate 9600

//*-- Software Serial
//
#define _rxpin      0
#define _txpin      1
SoftwareSerial debug( _rxpin, _txpin ); // RX, TX

//*-- IoT Information
#define SSID "disha"
#define PASS "fiftyfive55"
#define IP "184.106.153.149" // ThingSpeak IP Address: 184.106.153.149

// GET /update?key=[THINGSPEAK_KEY]&field1=[data 1]&field2=[data 2]...;
String GET = "GET /update?key=PT41QR66HL1NH8LU";

void setup() {
   pinMode(freq,OUTPUT);   
 pinMode(source_voltage,INPUT);
   Timer1.initialize(50);         // initialize timer1, and set a 1/2 second period
   Timer1.pwm(10, 0);
   Serial.begin( _baudrate );
 debug.begin( _baudrate );

 sendDebug("AT");
  delay(5000);
  if(Serial.find("OK"))
  {
    debug.println("RECEIVED: OK\nData ready to sent!");
    connectWiFi();
  }

}

void loop() {
  char buf[16];
  
    while(analog(source_voltage)<15)    //this loop maintains source voltage at 15V
{
i--;
if(i<0)
i=1;
for(j=0;j<=10;j++)
 Timer1.setPwmDuty(10,i); 
 value_temp1=analog(source_voltage);       //source voltage calculated and stored as float value 
 String temp=dtostrf(value_temp1,4,1,buf);  //converts float to string as thingpeak accepts only string 
 updateTS(temp);                                    //this calculated value is sent for updation on channel  
}
i++;
if(i>1023)
i=1022;
for(j=0;j<=10;j++)
      Timer1.setPwmDuty(10,i); 
 value_temp1=analog(pulse);
String temp=dtostrf(value_temp1,4,1,buf);
 updateTS(temp); 
delay(3000);                                           //wait as thingspeak updates every 3 seconds  
}
float analog(int x)                                    //subroutine to calculate source voltage
{
  int i=0;
  int out;
  out =analogRead(x);
   float out1=(out/1023.0)*4.9;
float out2=((out1)*(21.58+98.24))/(21.58);
return(out2);
}
//----- update the  Thingspeak string with 3 values
void updateTS( String T)
{
  // ESP8266 Client
  String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection
  cmd += IP;
  cmd += "\",80";
  sendDebug(cmd);
  delay(2000);
  if( Serial.find( "Error" ) )
  {
    debug.print( "RECEIVED: Error\nExit1" );
    return;
  }

  cmd = GET + "&field1=" + T +"\r\n";// L + "&field3=" + H +"\r\n";
  Serial.print( "AT+CIPSEND=" );
  Serial.println( cmd.length() );
  if(Serial.find( ">" ) )
  {
    debug.print(">");
    debug.print(cmd);
    Serial.print(cmd);
  }
  else
  {
    sendDebug( "AT+CIPCLOSE" );//close TCP connection
  }
  if( Serial.find("OK") )
  {
    debug.println( "RECEIVED: OK" );
  }
  else
  {
    debug.println( "RECEIVED: Error\nExit2" );
  }
}

void sendDebug(String cmd)
{
  debug.print("SEND: ");
  debug.println(cmd);
  Serial.println(cmd);
}

boolean connectWiFi()
{
  Serial.println("AT+CWMODE=1");//WiFi STA mode - if '3' it is both client and AP
  delay(2000);
  //Connect to Router with AT+CWJAP="SSID","Password";
  // Check if connected with AT+CWJAP?
  String cmd="AT+CWJAP=\""; // Join accespoint
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  sendDebug(cmd);
  delay(5000);
  if(Serial.find("OK"))
  {
    debug.println("RECEIVED: OK");
    return true;
  }
  else
  {
    debug.println("RECEIVED: Error");
    return false;
  }

  cmd = "AT+CIPMUX=0";// Set Single connection
  sendDebug( cmd );
  if( Serial.find( "Error") )
  {
    debug.print( "RECEIVED: Error" );
    return false;
  }
}

Now here if I write code purely to maintain source voltage at 15V and dump it in arduino all results are as expected and source voltage is maintained at 15V. But, say if now,if I want to update these values on thingspeak and use function in void loop()----> updateTS(temp); then, immediately after inclusion of this function the source voltage is equal to open circuit voltage and remains so and the same is displayed on thingspeak channel. Is there something wrong the way it’s written why? isn’t source voltage maintained at 15V ? Is it that the function is taking more time to return and the pwm signal given isn’t unable to track the time lapse due to calling that function…Can anyone please explain this?