creation classe courant
This commit is contained in:
parent
f9677d2a74
commit
e416ac79d5
|
@ -1,110 +1,16 @@
|
|||
#include "RegulationIntensite.h"
|
||||
#include "mesure.h"
|
||||
|
||||
#define __RESISTOR_VALUE__ 10000
|
||||
#define __ANALOGIN_BR__ A0
|
||||
#define __ANALOGIN_AR__ A1
|
||||
#define __PWM_OUT__ 3
|
||||
|
||||
float target_curent = 0.05;//ma
|
||||
PontDiviseur sourceU;
|
||||
PontDiviseur colecteurU;
|
||||
CurentFromR baseI;
|
||||
Reg regIBase;
|
||||
courant collecteur(3,A0,A1,820);
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(__ANALOGIN_AR__,0);
|
||||
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);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static float curent;
|
||||
static int pwm_value = 0;
|
||||
// curent = get_curent();
|
||||
Serial.println(curent);
|
||||
if(curent<target_curent*0.95)
|
||||
{
|
||||
pwm_value++;
|
||||
analogWrite(__PWM_OUT__, pwm_value);
|
||||
}
|
||||
else if(curent>target_curent)
|
||||
{
|
||||
pwm_value--;
|
||||
analogWrite(__PWM_OUT__, pwm_value);
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
|
||||
/*float get_curent()
|
||||
{
|
||||
int b = analogRead(__ANALOGIN_BR__);
|
||||
int a = analogRead(__ANALOGIN_AR__);
|
||||
float dv = (b-a)*(5.0/1023.0) ; //Tension réel
|
||||
float curent = (dv/(float)__RESISTOR_VALUE__)*1000;
|
||||
|
||||
//Serial.print(a);Serial.print(";");Serial.print(b);Serial.print(";");Serial.print(dv);Serial.print(";");Serial.print(curent);Serial.print(";");
|
||||
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);
|
||||
}
|
||||
Serial.println(collecteur.lireCourant());
|
||||
delay(500);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
#include <stdarg.h>
|
||||
#include "arduino.h"
|
||||
#include "mesure.h"
|
||||
|
||||
|
||||
courant::courant(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r)
|
||||
{
|
||||
this->pinPWM = pinPWM;
|
||||
this->pinU1 = pinU1;
|
||||
this->pinU2 = pinU2;
|
||||
this->r = r;
|
||||
pinMode(pinPWM, 1);
|
||||
pinMode(pinU1, 0);
|
||||
pinMode(pinU2, 0);
|
||||
bridgeU1Enable = 0;
|
||||
bridgeU2Enable = 0;
|
||||
bridgeU1RapportR = 1;
|
||||
bridgeU2RapportR = 1;
|
||||
}
|
||||
courant::courant(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable, ...)
|
||||
{
|
||||
this->pinPWM = pinPWM;
|
||||
this->pinU1 = pinU1;
|
||||
this->pinU2 = pinU2;
|
||||
this->r = r;
|
||||
pinMode(pinPWM, 1);
|
||||
pinMode(pinU1, 0);
|
||||
pinMode(pinU2, 0);
|
||||
this->bridgeU1Enable = bridgeU1Enable;
|
||||
this->bridgeU2Enable = bridgeU2Enable;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, bridgeU2Enable);
|
||||
if(bridgeU1Enable)
|
||||
{
|
||||
this->bridgeU1Enable = bridgeU1Enable;
|
||||
this->bridgeU2Enable = bridgeU2Enable;
|
||||
bridgeU1RapportR = va_arg(ap, float);
|
||||
if(bridgeU2Enable)
|
||||
bridgeU2RapportR = va_arg(ap, float);
|
||||
else
|
||||
bridgeU2RapportR = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->bridgeU1Enable = 0;
|
||||
this->bridgeU2Enable = bridgeU2Enable;
|
||||
bridgeU1RapportR = 1;
|
||||
if(bridgeU2Enable)
|
||||
bridgeU2RapportR = va_arg(ap, float);
|
||||
else
|
||||
bridgeU2RapportR = 1;
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
void courant::config(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r)
|
||||
{
|
||||
this->pinPWM = pinPWM;
|
||||
this->pinU1 = pinU1;
|
||||
this->pinU2 = pinU2;
|
||||
this->r = r;
|
||||
pinMode(pinPWM, 1);
|
||||
pinMode(pinU1, 0);
|
||||
pinMode(pinU2, 0);
|
||||
bridgeU1Enable = 0;
|
||||
bridgeU2Enable = 0;
|
||||
bridgeU1RapportR = 1;
|
||||
bridgeU2RapportR = 1;
|
||||
}
|
||||
void courant::config(uint8_t pinPWM, uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable, ...)
|
||||
{
|
||||
this->pinPWM = pinPWM;
|
||||
this->pinU1 = pinU1;
|
||||
this->pinU2 = pinU2;
|
||||
this->r = r;
|
||||
pinMode(pinPWM, 1);
|
||||
pinMode(pinU1, 0);
|
||||
pinMode(pinU2, 0);
|
||||
this->bridgeU1Enable = bridgeU1Enable;
|
||||
this->bridgeU2Enable = bridgeU2Enable;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, bridgeU2Enable);
|
||||
if(bridgeU1Enable)
|
||||
{
|
||||
this->bridgeU1Enable = bridgeU1Enable;
|
||||
this->bridgeU2Enable = bridgeU2Enable;
|
||||
bridgeU1RapportR = va_arg(ap, float);
|
||||
if(bridgeU2Enable)
|
||||
bridgeU2RapportR = va_arg(ap, float);
|
||||
else
|
||||
bridgeU2RapportR = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->bridgeU1Enable = 0;
|
||||
this->bridgeU2Enable = bridgeU2Enable;
|
||||
bridgeU1RapportR = 1;
|
||||
if(bridgeU2Enable)
|
||||
bridgeU2RapportR = va_arg(ap, float);
|
||||
else
|
||||
bridgeU2RapportR = 1;
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
void courant::lireTension()
|
||||
{
|
||||
u1RAW = analogRead(pinU1);
|
||||
u2RAW = analogRead(pinU2);
|
||||
|
||||
u1 = (u1RAW*(5.0/1024.0))*bridgeU1RapportR;
|
||||
u2 = (u2RAW*(5.0/1024.0))*bridgeU2RapportR;
|
||||
|
||||
}
|
||||
float courant::lireCourant()
|
||||
{
|
||||
lireTension();
|
||||
float i = ((u1-u2)/820.0)*1000;
|
||||
return i;
|
||||
}
|
||||
|
||||
float courant::lireTensionU1()
|
||||
{
|
||||
return u1;
|
||||
}
|
||||
float courant::lireTensionU2()
|
||||
{
|
||||
return u2;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef MESURE_H
|
||||
#define MESURE_H
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
class courant
|
||||
{
|
||||
private:
|
||||
int u1RAW;
|
||||
int u2RAW;
|
||||
int r;
|
||||
uint8_t pinPWM;
|
||||
uint8_t pinU1;
|
||||
uint8_t pinU2;
|
||||
float u1;
|
||||
float u2;
|
||||
uint8_t bridgeU1Enable;
|
||||
uint8_t bridgeU2Enable;
|
||||
float bridgeU1RapportR;
|
||||
float bridgeU2RapportR;
|
||||
void lireTension();
|
||||
public:
|
||||
courant(uint8_t pinPWM, 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, ...);
|
||||
void config(uint8_t pinPWM, 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, ...);
|
||||
float lireCourant();
|
||||
float lireTensionU1();
|
||||
float lireTensionU2();
|
||||
;};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue