1. Ce site utilise des cookies. En continuant à utiliser ce site, vous acceptez l'utilisation des cookies. En savoir plus.

C/C Pédale de soudage v2

Discussion dans 'Arduino' créé par vibram, 14 Juin 2016.

  1. vibram

    vibram Compagnon

    Messages:
    792
    Inscrit:
    15 Mars 2014
    Pédale de soudage v2
    Salut à tous,

    Je me permets de lancer un nouveau sujet car le projet est légèrement différent.
    Maintenant que j'ai la première version de ma pédale complètement fonctionnelle (encore merci à tous pour votre aide), voici les améliorations apportées pour la V2:

    Comme suggéré par phil135, je vais essayé de faire un circuit ouvert.
    Cela permettra entre autre de ne pas avoir de valeur complètement loufoque en cas de problème.
    Voici donc les différents éléments:

    Ecran LCD de 20x4 sur lequel je commence par choisir l'ampérage minimum, l'ampérage maximum et l'erreur possible entre l'ampérage théorique et l'ampérage réel. (j'ai décidé d'utiliser des encodeurs rotatifs, c'est un test ! et j'ai poussé le vice en me servant des attachinterrupt, on verra ce que ça donne lors des premiers tests).
    Il y aura un capteur a effet hall chargé de mesurer l'ampérage lors du soudage (il sera vraisemblablement relié à la prise terre par simplicité, c'est ce que j'ai retenu grâce à la loi des circuits. Là encore, à vérifier).
    Enfin, lors du soudage, la pédale activera un potentiomètre. la fonction map me permettra de calculer la valeur théorique du courant et ainsi la comparer à la valeur réelle.
    Pour faire cela je me sers d'un arduino mega comme j'ai 6 pins pour le attachinterrupt et suffisamment de gpio pour le LCD et les connexions avec le poste.
    J'ai pondu une première version du code qui compile.
    maintenant j'attends tous les éléments afin de réaliser les premiers tests (pas directement sur le TIG bien sur).

    Comme d'habitude, je suis ouvert à toute remarque, je me sers de ce projet pour apprendre les bases :wink:

    Code:
    // Made by Paul Sauvignac
    // License: CC-BY-NC-SA 3.0
    
    #include <LiquidCrystal.h>
    
    #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);
    }
    
     
    Dernière édition: 21 Juin 2016
  2. vibram

    vibram Compagnon

    Messages:
    792
    Inscrit:
    15 Mars 2014
    Pédale de soudage v2
    Salut,

    J'ai besoin d'un coup de main car je bloque !
    Les encodeurs rtatifs se revelent etre une vraie plaie mais j'aimerais quand meme les utiliser dans mon projets.
    J'utilise des encodeurs ALPS EC12E...

    Les seuls exemples qui fonctionennt utilises forcement un bout de code hexadecimal ou binaire, chose que je ne maitrise absolument pas et les traducteurs en ligne ne m'aident pas suffisament.

    Voici donc un sketch qui fonctionne sous un arduino UNO:


    Code:
    /*******Interrupt-based Rotary Encoder Sketch*******
    by Simon Merrett, based on insight from Oleg Mazurov, Nick Gammon, rt, Steve Spence
    */
    
    static int pinA = 2; // Our first hardware interrupt pin is digital pin 2
    static int pinB = 3; // Our second hardware interrupt pin is digital pin 3
    volatile byte aFlag = 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 bFlag = 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 encoderPos = 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 oldEncPos = 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 reading = 0; //somewhere to store the direct values we read from our interrupt pins before checking to see if we have moved a whole detent
    
    void setup() {
      pinMode(pinA, INPUT_PULLUP); // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
      pinMode(pinB, INPUT_PULLUP); // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
      attachInterrupt(0,PinA,RISING); // set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below)
      attachInterrupt(1,PinB,RISING); // set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below)
      Serial.begin(115200); // start the serial monitor link
    }
    
    void PinA(){
      cli(); //stop interrupts happening before we read pin values
      reading = PIND & 0xC; // read all eight pin values then strip away all but pinA and pinB's values
      if(reading == B00001100 && aFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
        encoderPos --; //decrement the encoder's position count
        bFlag = 0; //reset flags for the next turn
        aFlag = 0; //reset flags for the next turn
      }
      else if (reading == B00000100) bFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation
      sei(); //restart interrupts
    }
    
    void PinB(){
      cli(); //stop interrupts happening before we read pin values
      reading = PIND & 0xC; //read all eight pin values then strip away all but pinA and pinB's values
      if (reading == B00001100 && bFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
        encoderPos ++; //increment the encoder's position count
        bFlag = 0; //reset flags for the next turn
        aFlag = 0; //reset flags for the next turn
      }
      else if (reading == B00001000) aFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation
      sei(); //restart interrupts
    }
    
    void loop(){
      if(oldEncPos != encoderPos) {
        Serial.println(encoderPos);
        oldEncPos = encoderPos;
      }
    }
    Ce sketch est tiré d'ici:
    http://www.instructables.com/id/Improved-Arduino-Rotary-Encoder-Reading/

    J'ai testé ce code, cela fonctionne.
    On voit qu'il fait appel aux GPIO PIND puis un mysterieux bout de code.
    La ligne suivante est également un mysterieux code que je ne comprends malheureusement pas.


    Maintenant je dois utiliser 3 encodeurs.
    J'ai donc un arduino mega affin de pouvoir faire tourner tous mes attachinterrupt.
    Donc la premiere difficulté, cest que la manipulation des ports est différente, CF ce tableau:
    http://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0

    J'ai donc modifié le code en ajoutant pas mal de variables mais toujours basé sur l'exemple ci dessus
    A noter que les 6 pins compatibles avec l'interrupt sont le 2,3,18,19,20 & 21

    Code:
    /*******Interrupt-based Rotary Encoder Sketch*******
    by Simon Merrett, based on insight from Oleg Mazurov, Nick Gammon, rt, Steve Spence
    */
    
    #define GapPinA 2 // Our first hardware interrupt pin is digital pin 2
    #define GapPinB 3
    #define AmpMinPinA 18
    #define AmpMinPinB 19
    #define AmpMaxPinA 20
    #define AmpMaxPinB 21
    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
    
    
    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)
      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
    }
    // GAP Move
    
    void GapMinusPinA(){
      cli(); //stop interrupts happening before we read pin values
      Gapreading = PINE & 0xC; // read all eight pin values then strip away all but pinA and pinB's values
      if(Gapreading == B00001100 && 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 == B00000100) GapbFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation
      sei(); //restart interrupts
    }
    
    void GapPlusPinB(){
      cli(); //stop interrupts happening before we read pin values
      Gapreading = PINE & 0xC; //read all eight pin values then strip away all but pinA and pinB's values
      if (Gapreading == B00001100 && 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 == B00001000) GapaFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation
      sei(); //restart interrupts
    }
    // AMP MIN MOVE
    void AmpMinMinusPinA(){
      cli(); //stop interrupts happening before we read pin values
      AmpMinreading = PIND & 0xC; // 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
      sei(); //restart interrupts
    }
    
    void AmpMinPlusPinB(){
      cli(); //stop interrupts happening before we read pin values
      AmpMinreading = PIND & 0xC; //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
      sei(); //restart interrupts
    }
    
    // AMP MAX MOVE
    void AmpMaxMinusPinA(){
      cli(); //stop interrupts happening before we read pin values
      AmpMaxreading = PIND & 0xC; // read all eight pin values then strip away all but pinA and pinB's values
      if(AmpMaxreading == B00001100 && 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 == B00000100) AmpMaxbFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation
      sei(); //restart interrupts
    }
    
    void AmpMaxPlusPinB(){
      cli(); //stop interrupts happening before we read pin values
      AmpMaxreading = PIND & 0xC; //read all eight pin values then strip away all but pinA and pinB's values
      if (AmpMaxreading == B00001100 && 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 == B00001000) AmpMaxaFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation
      sei(); //restart interrupts
    }
    
    void loop(){
      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;
    }
    }
    Naivement, en me basant sur la spreadsheet google, j'ai remplacé D par E etc avant que ca colle a mes numeros de pin maisbien sur cela ne fonctionne pas car le bout de code hexadecimal et binaire ne doivent pas être adaptés.

    J'aimerais donc si possible que l'on m'explique ces bouts de code que je ne comprends pas et éventuellement des pistes pour corrger l'erreur.
    Ou alors avez vous une alternative ?
    Je pense qu'on doit pouvoir s'en sortir avec un digitalread mais comme je ne comrends pas la condition dans le if avec le masque, je suis completement bloqué.
    En esperant que la nuit me porte conseil...

    merci à vous!
     
  3. speedjf37

    speedjf37 Compagnon

    Messages:
    982
    Inscrit:
    15 Octobre 2009
    Localité:
    indre et loire
    Pédale de soudage v2
    Bonjour,

    Il faut adapter le code aux bits utilisée en particulier les masques.
    J'ai juste adapté les lignes qui changent par rapport aux pin utilisées

    https://www.arduino.cc/en/Hacking/PinMapping2560

    #define GapPinA 2 //PE4
    #define GapPinB 3 //PE5
    reading = PINE & 0x30; //B00110000
    if (reading == B00110000 && xx_Flag)

    else if (reading == B00010000) xx_bFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation

    else if (reading == B00100000) xx_aFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation

    // INVERSER les pin pour garder l'ordre des masques
    #define AmpMinPinB 18 //PD3
    #define AmpMinPinA 19 //PD2
    reading = PIND & 0x0C; //B00001100
    if (reading == B00001100 && xx_Flag)

    else if (reading == B00000100) xx_bFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation

    else if (reading == B00001000) xx_aFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation

    // INVERSER les pin pour garder l'ordre des masques
    #define AmpMaxPinA 20 //PD1
    #define AmpMaxPinB 21 //PD0
    reading = PIND & 0x03;//B00000011
    if (reading == B00000011 && xx_Flag)

    else if (reading == B00000001) xx_bFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation

    else if (reading == B00000010) xx_aFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation

    Cordialement JF
     
  4. vibram

    vibram Compagnon

    Messages:
    792
    Inscrit:
    15 Mars 2014
    Pédale de soudage v2
    Merci speedjf37,

    Je vais essayé de comprendre et d'interpreter ca à tête reposée cet aprem !
    je me doutais qu'il fallait adapter, mais c'est la manière utilisée que je ne connais pas.
    J'ai regardé les bases du binaire ce matin, je vais voir si j'arrive à retrouver mes petits comme on dit
     
  5. vibram

    vibram Compagnon

    Messages:
    792
    Inscrit:
    15 Mars 2014
    Pédale de soudage v2
    Pourrais-tu expliquer comment tu arrives à "0x30", "0x0C", "0x03", j'ai beau essayé de regarder avec des convertisseur, je ne comprends pas la logique.
    Enfin c'est l'ensemble des masques que je ne maitrise pas en réalité.

    merci :wink:
     
  6. speedjf37

    speedjf37 Compagnon

    Messages:
    982
    Inscrit:
    15 Octobre 2009
    Localité:
    indre et loire
    Pédale de soudage v2
    J'ai mis en binaire la correspondance avec l’hexadécimal (base 16 -> un caractère 0 à F pour chaque quartet de 4 bits )
    en binaire les poids des bits par quartet : 8 4 2 1


    #define AmpMaxPinA 20 //PD1
    #define AmpMaxPinB 21 //PD0
    Port D bit 0 et 1
    0x03 = B00000011 soit les bit 0 et 1 poids(2 + 1) = 3

    #define AmpMinPinB 18 //PD3
    #define AmpMinPinA 19 //PD2
    Port D bit 2 et 3
    0x0C = B00001100 soit les bit 2 et 3 poids(8 + 4) = 12

    #define GapPinA 2 //PE4
    #define GapPinB 3 //PE5
    Port E bit 4 et 5
    0x30 = B00110000 soit les bit 4 et 5 poids(2 + 1) = 3
     
  7. vibram

    vibram Compagnon

    Messages:
    792
    Inscrit:
    15 Mars 2014
    Pédale de soudage v2
    Merci bien.
    J'ai pas encore assimilé le passage du binaire à l'hexa (mais il existe des traducteur) en revanche jai bien compris les masques pour savoir quoi lire !
    tip top merci, je teste le sketch avec les 3 encodeurs ce soir
     
  8. vibram

    vibram Compagnon

    Messages:
    792
    Inscrit:
    15 Mars 2014
    Pédale de soudage v2
    mon sujet ne suscite pas les foules mais sait on jamais si un jour cela peut servir tant mieux.
    J'ai mis a jour le code:
    Tout fonctionne sur un afficheur LCD 20x4:
    Reglage de l'amperage minimum, maximum et de la tolérance entre courant réel et théorique, lecture du potentiomètre actionné par la pédale.

    Maintenant il me reste à tester le module mesurant le courant mais c'est pas évident car je ne veux pas le faire sur mon TIG directement. Je pense essayé sur une batterie de 12v d'abord mais ce ne sera que pour tester la lecture. Ensuite j'ai la boucle qui selon la valeur réelle +/- la tolérance, va envoyer la commande de correction au TIG. Mais ca je ne pourrai essaye qu'en situation réelle malheureusement
     
Chargement...
Articles en relation
  1. vibram
    Réponses:
    56
    Affichages:
    1 946
  2. vibram
    Réponses:
    59
    Affichages:
    2 769

Partager cette page