diff --git a/RegulationIntensite.h b/RegulationIntensite.h index ebf5fa4..0bc786f 100644 --- a/RegulationIntensite.h +++ b/RegulationIntensite.h @@ -1,6 +1,34 @@ #ifndef 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 diff --git a/RegulationIntensite.ino b/RegulationIntensite.ino index e991503..6f00085 100644 --- a/RegulationIntensite.ino +++ b/RegulationIntensite.ino @@ -6,6 +6,10 @@ #define __PWM_OUT__ 3 float target_curent = 0.05;//ma +PontDiviseur sourceU; +PontDiviseur colecteurU; +CurentFromR baseI; +Reg regIBase; void setup() { @@ -13,6 +17,16 @@ void setup() pinMode(__ANALOGIN_BR__,0); pinMode(__PWM_OUT__,1); 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); } @@ -20,7 +34,7 @@ void loop() { static float curent; static int pwm_value = 0; - curent = get_curent(); +// curent = get_curent(); Serial.println(curent); if(curentu1 = 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); + } +}