This commit is contained in:
Adrien Van 2017-02-15 06:44:18 +01:00
parent 4120d69772
commit 25dea5bb23
2 changed files with 94 additions and 4 deletions

View File

@ -1,6 +1,34 @@
#ifndef REGULATIONINTENSITE_H #ifndef REGULATIONINTENSITE_H
#define REGULATIONINTENSITE_H #define REGULATIONINTENSITE_H
float get_curent(); typedef struct {
float rapportR;
int pinU;
float uMesure;
float uReel;
} PontDiviseur;
typedef struct {
float r;
int pinU1;
int pinU2;
float u1;
float u2;
float i;
} CurentFromR;
typedef struct {
float targetI;
int pinPWM;
float *curI;
} Reg;
float readCurentFromR(CurentFromR *);
float readUFromPontDiviseur(PontDiviseur *);
void regulationI(Reg *);
void regulationVCE(Reg *);
#endif #endif

View File

@ -6,6 +6,10 @@
#define __PWM_OUT__ 3 #define __PWM_OUT__ 3
float target_curent = 0.05;//ma float target_curent = 0.05;//ma
PontDiviseur sourceU;
PontDiviseur colecteurU;
CurentFromR baseI;
Reg regIBase;
void setup() void setup()
{ {
@ -13,6 +17,16 @@ void setup()
pinMode(__ANALOGIN_BR__,0); pinMode(__ANALOGIN_BR__,0);
pinMode(__PWM_OUT__,1); pinMode(__PWM_OUT__,1);
digitalWrite(__PWM_OUT__, 122); digitalWrite(__PWM_OUT__, 122);
sourceU.rapportR = 0;
sourceU.pinU = A2;
colecteurU.rapportR = 0;
colecteurU.pinU = A3;
baseI.pinU1 = A0;
baseI.pinU2 = A1;
baseI.r = 10000;
regIBase.curI = &(baseI.i);
regIBase.pinPWM = 3;
regIBase.targetI = 0.05;
Serial.begin(9600); Serial.begin(9600);
} }
@ -20,7 +34,7 @@ void loop()
{ {
static float curent; static float curent;
static int pwm_value = 0; static int pwm_value = 0;
curent = get_curent(); // curent = get_curent();
Serial.println(curent); Serial.println(curent);
if(curent<target_curent*0.95) if(curent<target_curent*0.95)
{ {
@ -35,7 +49,7 @@ void loop()
delay(10); delay(10);
} }
float get_curent() /*float get_curent()
{ {
int b = analogRead(__ANALOGIN_BR__); int b = analogRead(__ANALOGIN_BR__);
int a = analogRead(__ANALOGIN_AR__); int a = analogRead(__ANALOGIN_AR__);
@ -45,3 +59,51 @@ float get_curent()
//Serial.print(a);Serial.print(";");Serial.print(b);Serial.print(";");Serial.print(dv);Serial.print(";");Serial.print(curent);Serial.print(";"); //Serial.print(a);Serial.print(";");Serial.print(b);Serial.print(";");Serial.print(dv);Serial.print(";");Serial.print(curent);Serial.print(";");
return curent; return curent;
} }
*/
float readCurentFromR(CurentFromR * data)
{
data->u1 = analogRead(data->pinU1);
data->u2 = analogRead(data->pinU2);
float dv = (data->u1-data->u2)*(5.0/1023.0) ; //Tension réel
data->i = (dv/(float)data->r)*1000;
return data->i;
}
float readUFromPontDiviseur(PontDiviseur * data)
{
data->uMesure = analogRead(data->pinU);
data->uReel = data->uMesure*data->rapportR;
return data->uReel;
}
void regulationI(Reg * reg)
{
uint16_t *ocr;
switch (reg->pinPWM) {
case 3:
ocr = &OCR2B;
break;
case 5:
ocr = &OCR0B;
break;
case 6:
ocr = &OCR0A;
break;
case 9:
ocr = &OCR1A
break;
case 10:
ocr = &OCR1B;
break;
case 11:
ocr = &OCR2A;
break;
}
if(*(reg->curI)<(reg->targetI)*0.9)
(*ocr)++
else if(*(reg->curI)>(reg->targetI))
(*ocr)--
else{
Serial.print((sourceU.uReel-colecteurU.uReel)/100);Serial.print(";");Serial.println(colecteurU);
delay(500);
}
}