Je commence ce post ici , mais on était plus vraiment dans le sujet du post.... :
Donc dans mon dernier message je disais avoir trouvé "Regulated Positive Voltage Booster" dans le playground.
Mon but est de stabiliser la tension sur un véhicule à une valeur choisie (par exemple 12.00 volts) et j'aimerais que cela soit le plus stable possible (0,05 volt).
Actuellement j'ai ce code qui me fait une stabilité de 0,5 volts :
volatile int ppm_count;
unsigned long send_Time=0;
unsigned long send_Freq=0;
unsigned long timeold_Time;
unsigned long timeold_Freq;
//unsigned long diff_Ppm;
unsigned long ppm; //Pulse per minute
int pwm_Volt;
int pinVolt = 9;
int val;
void setup()
{
TCCR1B = 0x09;
Serial.begin(9600);
attachInterrupt(0, ppm_fun, FALLING);
pinMode(pinVolt,OUTPUT);
}
void loop()
{
if (ppm_count >= 145) {
ppm = 540/(millis() - timeold_Freq)*ppm_count;
timeold_Freq = millis();
ppm_count = 0;
val=1;
}
long freq = 80000; //tension x 10'000
// freq/=35;
if (val==1){
if(ppm>=freq){
// diff_Ppm = freq-ppm;
//pwm_Volt=255-255*diff_Ppm/freq;
pwm_Volt--;
}
if (ppm<=freq){
//diff_Ppm = freq-ppm;
// pwm_Volt = 0+255*diff_Ppm/freq;
pwm_Volt++;
}
if( pwm_Volt >255){
pwm_Volt= 255;
}
if( pwm_Volt < 0){
pwm_Volt= 0;
}
val=0;
}
analogWrite(pinVolt,pwm_Volt);
send_Time=millis()-timeold_Time;
if (send_Time >=1000){
Serial.print(" ppm : ");
Serial.print(ppm,DEC);
Serial.print(" ");
Serial.print(" ppm_count : ");
Serial.print(ppm_count,DEC);
Serial.print(" ");
Serial.print(" pwm : ");
Serial.println(pwm_Volt,DEC);
timeold_Time = millis();
}
}
void ppm_fun()
{
ppm_count++;
//Each pulse, this interrupt function is run twice
}
Je trouve un problème majeur dans ce code :
- Avec la fonction interrupt(), ce sont les pulses enregistrés qui donne la durée de l'échantillonage, je préférerais avoir une durée fixe pour faire cet échantillonage.