Professional Documents
Culture Documents
change power
Group –B-
We will generate a wave that depends on the change in the
power produced by the voltage change if the power increases, we will
make sure the voltage increases. We will reduce the pulse width, but if
the voltage is reduced we will increase the pulse width.
If the power is reduced we will make sure the voltage if increased will
increase the wave width, but if the voltage is reduced we will reduce
the wave width.
The algorithm on which the program is written is written in a
language C
Electrical circuit
The code
float average = 0;
float voltage;
float current = 0;
float power = 0;
float R = 1000;
float s=50;
float TIME=0.001;
float TIMEH=0;
float TIMEL=0;
float power1=1;
float voltage1=2;
float power2=1;
float voltage2=2;
float R1 = 30000.0; //
float R2 = 7500.0; //
int value = 0;
float powerfloat2 = 0;
float powerfloat1 = 0;
float voltagefloat2 = 0;
float voltagefloat1 = 0;
void setup()
Serial.begin(9600);
pinMode(analogInput, INPUT);
pinMode(A0, INPUT);
pinMode(ENA , OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
void loop(){
///////////////////////////////////////////////////////////////////////////////////////////////////////////
float average = 0;
delay(1);
Serial.print("Current :");
Serial.print(average/1000);
Serial.println("A");
value = analogRead(analogInput);
// vout = (value * 20.0) / 1024.0; // see text
// voltage=(vin*10)+2;
power=voltage*(average/1000);
power2=power;
voltage2=voltage;
////////////////////////////////////////////////////////////////////////////////////////////////////////
Serial.print("voltage[1]=");
Serial.print(voltage1);
Serial.print(" voltage[2]=");
Serial.println(voltage2);
Serial.print("power[1]= ");
Serial.print(power1);
Serial.println(power2);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
voltagefloat2 = voltage2*0.1;
voltagefloat1 = voltage1*0.1;
powerfloat1 =power*0.1;
powerfloat2=power1*0.1;
Serial.println(powerfloat1);
Serial.println( powerfloat2);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
////
if ( powerfloat2 == powerfloat1){
s=50;
s=s-1;
s=s+1;
s=s+1;
s=s-1;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////
TIMEH=(TIME*s)/100;
TIMEL=TIME-TIMEH;
Serial.print("TIMEH=");
Serial.println(TIMEH*1000);
Serial.print("TIMEL= ");
Serial.println(TIMEL*1000);
delay(1000);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////
power1= power2;
voltage1= voltage2;
}