Correction bug

This commit is contained in:
Adrien Van 2017-02-15 21:27:17 +01:00
parent e416ac79d5
commit d68add73df
3 changed files with 64 additions and 39 deletions

View File

@ -1,16 +1,48 @@
#include "mesure.h" #include "mesure.h"
#define __PIN_PWM__ 3
#define DEBUG
float target_curent = 0.05;//ma float target_curent = 0.05;//ma
courant collecteur(3,A0,A1,820); courant collecteur(A0,A1,100,1,1,0.248,0.248); // R1 10K, R2 3K3
courant base(A2,A3,10000);
/*
courant collecteur(Potentien Haut U1,Potentiel Bas U2,Resistance[,Pon résistif sur U1,Pon résistif sur U2, Raport Résistance U1, Raport Résistance U2]);
par ex
courant collecteur(A0,A1,800,1,1,0.2,0.8);
courant collecteur(A0,A1,800,1,0,0.1);
courant collecteur(A0,A1,800,0,1,0.8);
*/
void setup() void setup()
{ {
pinMode(3,1);
Serial.begin(9600); Serial.begin(9600);
Serial.println("Ic;Vce");
} }
void loop() void loop()
{ {
Serial.println(collecteur.lireCourant()); static int PWMCourent = 122;
delay(500); float iBase = base.lireCourant();
if(iBase < target_curent*0.9)
PWMCourent++;
else if(iBase > target_curent)
PWMCourent--;
#ifndef DEBUG
else
{
#endif
//Courent stabilisé on affiche les valeurs
Serial.print(collecteur.lireCourant());Serial.print(";");Serial.print(collecteur.lireTensionU2());Serial.print("\n");
delay(500);
#ifndef DEBUG
}
#endif
analogWrite(__PIN_PWM__, PWMCourent);
#ifdef DEBUG
Serial.print("PWM:");Serial.print(PWMCourent);
Serial.print("\tIBase:");Serial.println(base.lireCourant());
#endif
} }

View File

@ -3,13 +3,11 @@
#include "mesure.h" #include "mesure.h"
courant::courant(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r) courant::courant(uint8_t pinU1, uint8_t pinU2, int r)
{ {
this->pinPWM = pinPWM;
this->pinU1 = pinU1; this->pinU1 = pinU1;
this->pinU2 = pinU2; this->pinU2 = pinU2;
this->r = r; this->r = r;
pinMode(pinPWM, 1);
pinMode(pinU1, 0); pinMode(pinU1, 0);
pinMode(pinU2, 0); pinMode(pinU2, 0);
bridgeU1Enable = 0; bridgeU1Enable = 0;
@ -17,13 +15,12 @@ courant::courant(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r)
bridgeU1RapportR = 1; bridgeU1RapportR = 1;
bridgeU2RapportR = 1; bridgeU2RapportR = 1;
} }
courant::courant(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable, ...) courant::courant(uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable,...)
{ {
this->pinPWM = pinPWM;
this->pinU1 = pinU1; this->pinU1 = pinU1;
this->pinU2 = pinU2; this->pinU2 = pinU2;
this->r = r; this->r = r;
pinMode(pinPWM, 1);
pinMode(pinU1, 0); pinMode(pinU1, 0);
pinMode(pinU2, 0); pinMode(pinU2, 0);
this->bridgeU1Enable = bridgeU1Enable; this->bridgeU1Enable = bridgeU1Enable;
@ -35,9 +32,9 @@ courant::courant(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r, uint8_t br
{ {
this->bridgeU1Enable = bridgeU1Enable; this->bridgeU1Enable = bridgeU1Enable;
this->bridgeU2Enable = bridgeU2Enable; this->bridgeU2Enable = bridgeU2Enable;
bridgeU1RapportR = va_arg(ap, float); bridgeU1RapportR = va_arg(ap, double);
if(bridgeU2Enable) if(bridgeU2Enable)
bridgeU2RapportR = va_arg(ap, float); bridgeU2RapportR = va_arg(ap, double);
else else
bridgeU2RapportR = 1; bridgeU2RapportR = 1;
} }
@ -47,19 +44,17 @@ courant::courant(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r, uint8_t br
this->bridgeU2Enable = bridgeU2Enable; this->bridgeU2Enable = bridgeU2Enable;
bridgeU1RapportR = 1; bridgeU1RapportR = 1;
if(bridgeU2Enable) if(bridgeU2Enable)
bridgeU2RapportR = va_arg(ap, float); bridgeU2RapportR = va_arg(ap, double);
else else
bridgeU2RapportR = 1; bridgeU2RapportR = 1;
} }
va_end(ap); va_end(ap);
} }
void courant::config(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r) void courant::config(uint8_t pinU1, uint8_t pinU2, int r)
{ {
this->pinPWM = pinPWM;
this->pinU1 = pinU1; this->pinU1 = pinU1;
this->pinU2 = pinU2; this->pinU2 = pinU2;
this->r = r; this->r = r;
pinMode(pinPWM, 1);
pinMode(pinU1, 0); pinMode(pinU1, 0);
pinMode(pinU2, 0); pinMode(pinU2, 0);
bridgeU1Enable = 0; bridgeU1Enable = 0;
@ -67,13 +62,11 @@ void courant::config(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r)
bridgeU1RapportR = 1; bridgeU1RapportR = 1;
bridgeU2RapportR = 1; bridgeU2RapportR = 1;
} }
void courant::config(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable, ...) void courant::config(uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable, ...)
{ {
this->pinPWM = pinPWM;
this->pinU1 = pinU1; this->pinU1 = pinU1;
this->pinU2 = pinU2; this->pinU2 = pinU2;
this->r = r; this->r = r;
pinMode(pinPWM, 1);
pinMode(pinU1, 0); pinMode(pinU1, 0);
pinMode(pinU2, 0); pinMode(pinU2, 0);
this->bridgeU1Enable = bridgeU1Enable; this->bridgeU1Enable = bridgeU1Enable;
@ -85,9 +78,9 @@ void courant::config(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r, uint8_
{ {
this->bridgeU1Enable = bridgeU1Enable; this->bridgeU1Enable = bridgeU1Enable;
this->bridgeU2Enable = bridgeU2Enable; this->bridgeU2Enable = bridgeU2Enable;
bridgeU1RapportR = va_arg(ap, float); bridgeU1RapportR = va_arg(ap, double);
if(bridgeU2Enable) if(bridgeU2Enable)
bridgeU2RapportR = va_arg(ap, float); bridgeU2RapportR = va_arg(ap, double);
else else
bridgeU2RapportR = 1; bridgeU2RapportR = 1;
} }
@ -97,7 +90,7 @@ void courant::config(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r, uint8_
this->bridgeU2Enable = bridgeU2Enable; this->bridgeU2Enable = bridgeU2Enable;
bridgeU1RapportR = 1; bridgeU1RapportR = 1;
if(bridgeU2Enable) if(bridgeU2Enable)
bridgeU2RapportR = va_arg(ap, float); bridgeU2RapportR = va_arg(ap, double);
else else
bridgeU2RapportR = 1; bridgeU2RapportR = 1;
} }
@ -108,22 +101,22 @@ void courant::lireTension()
u1RAW = analogRead(pinU1); u1RAW = analogRead(pinU1);
u2RAW = analogRead(pinU2); u2RAW = analogRead(pinU2);
u1 = (u1RAW*(5.0/1024.0))*bridgeU1RapportR; u1 = (u1RAW*(5.0/1024.0))*(bridgeU1RapportR+1);
u2 = (u2RAW*(5.0/1024.0))*bridgeU2RapportR; u2 = (u2RAW*(5.0/1024.0))*(bridgeU2RapportR+1);
} }
float courant::lireCourant() double courant::lireCourant()
{ {
lireTension(); lireTension();
float i = ((u1-u2)/820.0)*1000; double i = ((u1-u2)/820.0)*1000;
return i; return i;
} }
float courant::lireTensionU1() double courant::lireTensionU1()
{ {
return u1; return u1;
} }
float courant::lireTensionU2() double courant::lireTensionU2()
{ {
return u2; return u2;
} }

View File

@ -12,21 +12,21 @@ class courant
uint8_t pinPWM; uint8_t pinPWM;
uint8_t pinU1; uint8_t pinU1;
uint8_t pinU2; uint8_t pinU2;
float u1; double u1;
float u2; double u2;
uint8_t bridgeU1Enable; uint8_t bridgeU1Enable;
uint8_t bridgeU2Enable; uint8_t bridgeU2Enable;
float bridgeU1RapportR; double bridgeU1RapportR;
float bridgeU2RapportR; double bridgeU2RapportR;
void lireTension(); void lireTension();
public: public:
courant(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r); courant(uint8_t pinU1, uint8_t pinU2, int r);
courant(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable, ...); courant(uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable, ...);
void config(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r); void config(uint8_t pinU1, uint8_t pinU2, int r);
void config(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1, uint8_t bridgeU2, ...); void config(uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1, uint8_t bridgeU2, ...);
float lireCourant(); double lireCourant();
float lireTensionU1(); double lireTensionU1();
float lireTensionU2(); double lireTensionU2();
;}; ;};
#endif #endif