Salut à tous,
Suite à mon premier sujet ici: http://www.soudeurs.com/fronius-conseils-et-choix-du-materiel-de-soudage/16089-montage-diffuseur-grille-sur-torche-fronius.html
je vous expose l'avancée de la version 2, un peu plus élaborée.
Je conserve les bases de la V1 à savoir:
Un arduino (mega pour la V2)
Un potentiomètre actionné par la pédale
Des mosfet afin d'isoler le TIG de l'arduino
Pour la V2, j'ajoute:
Un afficheur LCD déporté
Des réglages d'ampérage min et max, de la tolérance
Une mesure du courant de soudage via capteur à effet hall
J'ai deux deux modules.
Un premier boitier avec afficheur LCD, 3 encodeurs rotatifs et un potentiomètre.
Chaque encodeur rotatif permet de régler:
l’ampérage minimum
l’ampérage maximum
La tolérance entre ampérage théorique et réel
le potentiomètre permet de régler la luminosité du LCD
Ce module va être relié à l'arduino situé dans la pédale.
La pédale va actionner le potentiomètre. L'arduino va lire la valeur du potentiomètre et calculer le courant théorique.
Exemple: la lecture du potentiomètre va donner une valeur entre 0 et 1023
Si on définit l'ampérage minimum à 40 et le max à 80, une valeur de 300 au potentiomètre va donner 51.7A
550 au potentiomètre va donner : 61.5A etc
Le courant théorique est comparé au courant réel + ou - la tolérance. L'arduino envoie ensuite la commande adaptée ( amp -, amp + ou ne rien faire).
Actuellement, j'ai tout testé avec succès sur la partie gestion de l'affichage LCD, paramétrage des ampérages, tolérance...
Il me reste à vérifier la fiabilité de la lecture du capteur à effet hall et de l'action de l'arduino en fonction du résultat et vérifier qu'il n'y ai pas de problème de variable etc (même si en théorie j'ai déclaré mes variables pour éviter cela...)
Voici le code dans l'état actuel, bien entendu, je me décharge de toute responsabilité en cas de dommages !
[CODE]
// Made by Paul Sauvignac
// License: CC-BY-NC-SA 3.0
#include
#define GapPinA 2 // PE4
#define GapPinB 3 // PE5
#define AmpMinPinA 18 //PD2
#define AmpMinPinB 19 //PD3
#define AmpMaxPinA 20 //PD1
#define AmpMaxPinB 21 //PD0
#define on 4 // On pin
#define up 5 // Up amp pin
#define down 6 // Down amp pin
LiquidCrystal lcd(12, 11, 7, 8, 9, 10); //LCD parameters
volatile byte GapaFlag = 0; // let's us know when we're expecting a rising edge on pinA to signal that the encoder has arrived at a detent
volatile byte GapbFlag = 0; // let's us know when we're expecting a rising edge on pinB to signal that the encoder has arrived at a detent (opposite direction to when aFlag is set)
volatile byte AmpMinaFlag = 0; // let's us know when we're expecting a rising edge on pinA to signal that the encoder has arrived at a detent
volatile byte AmpMinbFlag = 0; // let's us know when we're expecting a rising edge on pinB to signal that the encoder has arrived at a detent (opposite direction to when aFlag is set)
volatile byte AmpMaxaFlag = 0; // let's us know when we're expecting a rising edge on pinA to signal that the encoder has arrived at a detent
volatile byte AmpMaxbFlag = 0; // let's us know when we're expecting a rising edge on pinB to signal that the encoder has arrived at a detent (opposite direction to when aFlag is set)
volatile byte GapencoderPos = 0; //this variable stores our current value of encoder position. Change to int or uin16_t instead of byte if you want to record a larger range than 0-255
volatile byte GapoldEncPos = 0; //stores the last encoder position value so we can compare to the current reading and see if it has changed (so we know when to print to the serial monitor)
volatile byte Gapreading = 0; //somewhere to store the direct values we read from our interrupt pins before checking to see if we have moved a whole detent
volatile byte AmpMinencoderPos = 0; //this variable stores our current value of encoder position. Change to int or uin16_t instead of byte if you want to record a larger range than 0-255
volatile byte AmpMinoldEncPos = 0; //stores the last encoder position value so we can compare to the current reading and see if it has changed (so we know when to print to the serial monitor)
volatile byte AmpMinreading = 0; //somewhere to store the direct values we read from our interrupt pins before checking to see if we have moved a whole detent
volatile byte AmpMaxencoderPos = 0; //this variable stores our current value of encoder position. Change to int or uin16_t instead of byte if you want to record a larger range than 0-255
volatile byte AmpMaxoldEncPos = 0; //stores the last encoder position value so we can compare to the current reading and see if it has changed (so we know when to print to the serial monitor)
volatile byte AmpMaxreading = 0; //somewhere to store the direct values we read from our interrupt pins before checking to see if we have moved a whole detent
boolean state = 0; // state at startup
boolean laststate = 0; // state after startup
int value = 0; // Potentiometer value
int oldvalue = 0; // Potentiometer value of last read
const int start = 30; // Potentiometer value for startup
const int duration = 300; // delay of each loop in ms
unsigned int push = 50; // duration of each push button in ms
unsigned int current = 0; // theoretical value in current from potentiometer
unsigned int ActualCurrent = 0; // Current measured by Hall sensor
// unsigned long previousMillis = 0; // last time loop done
int mVperAmp = 10; // See Scale Factors
int ACSoffset = 2500; // See offsets
int RawValue= 0;
unsigned int Voltage = 0;
void setup() {
pinMode(GapPinA, INPUT_PULLUP); // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
pinMode(GapPinB, INPUT_PULLUP); // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
pinMode(AmpMinPinA, INPUT_PULLUP); // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
pinMode(AmpMinPinB, INPUT_PULLUP); // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
pinMode(AmpMaxPinA, INPUT_PULLUP); // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
pinMode(AmpMaxPinB, INPUT_PULLUP); // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
pinMode(A0, INPUT); // pedal potentiometer
pinMode(A1, INPUT); // Hall current sensor
digitalWrite(on, LOW); // default state ON
digitalWrite(up, LOW); // default state UP
digitalWrite(down, LOW); // default state DOWN
pinMode(up, OUTPUT);
pinMode(down, OUTPUT);
pinMode(on, OUTPUT);
attachInterrupt(digitalPinToInterrupt(GapPinA), GapMinusPinA,RISING); // set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below)
attachInterrupt(digitalPinToInterrupt(GapPinB), GapPlusPinB,RISING); // set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below)
attachInterrupt(digitalPinToInterrupt(AmpMinPinA), AmpMinMinusPinA,RISING); // set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below)
attachInterrupt(digitalPinToInterrupt(AmpMinPinB), AmpMinPlusPinB,RISING); // set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below)
attachInterrupt(digitalPinToInterrupt(AmpMaxPinA), AmpMaxMinusPinA,RISING); // set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below)
attachInterrupt(digitalPinToInterrupt(AmpMaxPinB), AmpMaxPlusPinB,RISING); // set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below)
Serial.begin(9600); // start the serial monitor link
// LCD display
lcd.begin(20,4);
lcd.setCursor(0, 0);
lcd.print("Set parameters");
lcd.setCursor(0, 1);
lcd.print("with buttons below");
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Amp min:");
lcd.setCursor(10, 0);
lcd.print(AmpMinencoderPos);
lcd.setCursor(0, 1);
lcd.print("Amp max:");
lcd.setCursor(10, 1);
lcd.print(AmpMaxencoderPos);
lcd.setCursor(0, 2);
lcd.print("Gap:");
lcd.setCursor(5, 2);
lcd.print(GapencoderPos);
lcd.setCursor(0,3);
lcd.print("Real|Theo: ");
lcd.setCursor(12,3);
lcd.print(ActualCurrent);
lcd.setCursor(15,3);
lcd.print("|");
lcd.print(current);
}
// GAP Move
void GapMinusPinA(){
cli(); //stop interrupts happening before we read pin values
Gapreading = PINE & 0x30; // read all eight pin values then strip away all but pinA and pinB's values
if(Gapreading == B00110000 && GapaFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
GapencoderPos --; //decrement the encoder's position count
GapbFlag = 0; //reset flags for the next turn
GapaFlag = 0; //reset flags for the next turn
}
else if (Gapreading == B00010000) GapbFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation
lcd.setCursor(5, 2);
lcd.print(" ");
lcd.setCursor(5, 2);
lcd.print(GapencoderPos);
sei(); //restart interrupts
}
void GapPlusPinB(){
cli(); //stop interrupts happening before we read pin values
Gapreading = PINE & 0x30; //read all eight pin values then strip away all but pinA and pinB's values
if (Gapreading == B00110000 && GapbFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
GapencoderPos ++; //increment the encoder's position count
GapbFlag = 0; //reset flags for the next turn
GapaFlag = 0; //reset flags for the next turn
}
else if (Gapreading == B00100000) GapaFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation
lcd.setCursor(5, 2);
lcd.print(" ");
lcd.setCursor(5, 2);
lcd.print(GapencoderPos);
sei(); //restart interrupts
}
// AMP MIN MOVE
void AmpMinMinusPinA(){
cli(); //stop interrupts happening before we read pin values
AmpMinreading = PIND & 0x0C; // read all eight pin values then strip away all but pinA and pinB's values
if(AmpMinreading == B00001100 && AmpMinaFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
AmpMinencoderPos --; //decrement the encoder's position count
AmpMinbFlag = 0; //reset flags for the next turn
AmpMinaFlag = 0; //reset flags for the next turn
}
else if (AmpMinreading == B00000100) AmpMinbFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation
lcd.setCursor(10, 0);
lcd.print(" ");
lcd.setCursor(10, 0);
lcd.print(AmpMinencoderPos);
sei(); //restart interrupts
}
void AmpMinPlusPinB(){
cli(); //stop interrupts happening before we read pin values
AmpMinreading = PIND & 0x0C; //read all eight pin values then strip away all but pinA and pinB's values
if (AmpMinreading == B00001100 && AmpMinbFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
AmpMinencoderPos ++; //increment the encoder's position count
AmpMinbFlag = 0; //reset flags for the next turn
AmpMinaFlag = 0; //reset flags for the next turn
}
else if (AmpMinreading == B00001000) AmpMinaFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation
lcd.setCursor(10, 0);
lcd.print(" ");
lcd.setCursor(10, 0);
lcd.print(AmpMinencoderPos);
sei(); //restart interrupts
}
// AMP MAX MOVE
void AmpMaxMinusPinA(){
cli(); //stop interrupts happening before we read pin values
AmpMaxreading = PIND & 0x03; // read all eight pin values then strip away all but pinA and pinB's values
if(AmpMaxreading == B00000011 && AmpMaxaFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
AmpMaxencoderPos --; //decrement the encoder's position count
AmpMaxbFlag = 0; //reset flags for the next turn
AmpMaxaFlag = 0; //reset flags for the next turn
}
else if (AmpMaxreading == B00000001) AmpMaxbFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation
lcd.setCursor(10, 1);
lcd.print(" ");
lcd.setCursor(10, 1);
lcd.print(AmpMaxencoderPos);
sei(); //restart interrupts
}
void AmpMaxPlusPinB(){
cli(); //stop interrupts happening before we read pin values
AmpMaxreading = PIND & 0x03; //read all eight pin values then strip away all but pinA and pinB's values
if (AmpMaxreading == B00000011 && AmpMaxbFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
AmpMaxencoderPos ++; //increment the encoder's position count
AmpMaxbFlag = 0; //reset flags for the next turn
AmpMaxaFlag = 0; //reset flags for the next turn
}
else if (AmpMaxreading == B00000010) AmpMaxaFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation
lcd.setCursor(10, 1);
lcd.print(" ");
lcd.setCursor(10, 1);
lcd.print(AmpMaxencoderPos);
sei(); //restart interrupts
}
void loop(){
// unsigned long currentMillis = 0;
// if (currentMillis - previousMillis >= duration) {
// previousMillis = currentMillis;
// On-off
if (analogRead(A0)>start) {
state = 1;
}
else {
state = 0;
lcd.setCursor(16,3);
lcd.print(" ");
lcd.setCursor(16,3);
lcd.print("0");
}
// CHECK Serial.println(state);
if (!(state==laststate)) {
Serial.println("START");
digitalWrite(on, HIGH);
delay(push);
digitalWrite(on, LOW);
}
laststate=state;
//comparison between actual amp and theoretical value
if (analogRead(A0)>start) {
value = analogRead(A0);
ActualCurrent = analogRead(A1);
int current = map(value,0,1023,AmpMinencoderPos,AmpMaxencoderPos);
Serial.print("valeur potentiometre:");
Serial.println(value);
Serial.print("Courant theorique:");
Serial.println(current);
//lcd.setCursor(12,3);
//lcd.print(" ");
//lcd.setCursor(12,3);
//lcd.print(ActualCurrent);
lcd.setCursor(16,3);
lcd.print(" ");
lcd.setCursor(16,3);
lcd.print(current);
RawValue = analogRead(A1);
Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
ActualCurrent = ((Voltage - ACSoffset) / mVperAmp);
// Serial.println("Actual current:");
// Serial.println(ActualCurrent);
if ((current + GapencoderPos) > ActualCurrent) {
digitalWrite(up, HIGH);
delay(push);
digitalWrite(up, LOW);
}
else if((current + GapencoderPos) < ActualCurrent) {
digitalWrite(down, HIGH);
delay(push);
digitalWrite(down, LOW);
}
}
if(GapoldEncPos != GapencoderPos) {
Serial.print("Gap:");
Serial.println(GapencoderPos);
GapoldEncPos = GapencoderPos;
}
if(AmpMinoldEncPos != AmpMinencoderPos) {
Serial.print("Amp min:");
Serial.println(AmpMinencoderPos);
AmpMinoldEncPos = AmpMinencoderPos;
}
if(AmpMaxoldEncPos != AmpMaxencoderPos) {
Serial.print("Amp max:");
Serial.println(AmpMaxencoderPos);
AmpMaxoldEncPos = AmpMaxencoderPos;
}
delay(duration); }[/CODE]
Si vous avez des remarques, réflexions ou même une requête pour un usage perso, n'hésitez pas
je mettrai à jour lorsque j'aurais avancé sur le module à effet hall