Vin is a constant DC source. This circuit will take a random DC input between 12.6V and 48V, and then maintain a constant output voltage of 5V using a system of voltage feedback.
with the source code,
float D;
void setup()
{
TCCR0B = TCCR0B & B11111000 | B00000010;
pinMode(5, OUTPUT);
pinMode(A0, INPUT);
D = 0;
analogWrite(5, D);
Serial.begin(9600);
}
void loop()
{
int A0in = analogRead(A0);
float Vin = 10 * (A0in + 0.5) * 5 / 1023;
Serial.println(Vin);
if(Vin < 5) {
D += 5;
}
Serial.println(D);
analogWrite(5, D);
}
Vout starts from 0V and increases up to 1.7V but no more :(
How to fix it? (In the simulation above Vin = 48V)