Auteur Sujet: Logiciel DCC CommandStation –EX-master avec fonction RailCom  (Lu 25 fois)

lebelge2

  • Newbie
  • *
  • Messages: 29
    • Voir le profil
Bonjour.

J’ai modifié légèrement ce logiciel pour qu’il insère un CutOut  à la fin des trames.
Donc maintenant compatible RailCom.

Fonctionne sur Mega et Uno.

Restrictions :

Pour le Mega; Dans MotorDriver.h  la Pin 9 est imposée.
    ex: new MotorDriver(7, 9, UNUSED_PIN, UNUSED_PIN, A0, 2.99, 2000, UNUSED_PIN),
Pour l'Uno; Dans MotorDriver.h  la Pin 12 est imposée.
    ex: new MotorDriver(7, 12, UNUSED_PIN, UNUSED_PIN, A0, 2.99, 2000, UNUSED_PIN),

Trois nouvelles sorties pour les signaux (Out1, Out2, CutOut/Brake) sur PC0, PC1, PC2
 (sur Mega 35 36 37, Uno A0 A1 A2)
Bien entendu que toutes les sorties d’origines fonctionnent toujours mais sans CutOut.
Le code est extrêmement simple, les bidouilleurs pourront modifier toutes les sorties.

La modification logiciel :

Tout ce passe dans l’interruption du Timer1 :ISR(TIMER1_OVF_vect)   dans DCCTimerAVR.cpp
Il faut la remplacer par le code que je propose ci-dessous avec les défines et variables.

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)  // MEGA
#define PINx   PINH             // Pin numéro 9 sur Mega (PH6)     
#define PinIn  6                // new MotorDriver(7, 9, UNUSED_PIN, UNUSED_PIN, A0, 2.99, 2000, UNUSED_PIN),
#define PORTx  PORTC            // Pin de sorties des signaux Out1, Out2, Brake/CutOut sur port C
#define Etat1  B00000100        // -_-_-_   Direct   Pin 35  (In1 pour type L298N, L6203, Dir pour type LMD18200)
#define Etat2  B00000010        // _-_-_-   Inversé  Pin 36  (In2 pour type L298N, L6203, Dir pour type LMD18200)
#define CutOut_ON  B00000111    // __----__          Pin 37  (BraKe Pour Type LMD08200)
#define CutOut_OFF B00000000    // ________
#else                                                           // UNO
#define PINx  PINB              // Pin numéro 12 sur Uno (PB4)
#define PinIn  4                // new MotorDriver(7, 12, UNUSED_PIN, UNUSED_PIN, A0, 2.99, 2000, UNUSED_PIN),
#define PORTx  PORTC
#define Etat1  B00000100
#define Etat2  B00000010
#define CutOut_ON  B00000111
#define CutOut_OFF B00000000
#endif

int i;
int temps;
int oldtemps;
int bitt;
uint8_t bitCount;
uint8_t DccBitVal;
volatile uint8_t dccrecState;
ISR(TIMER1_OVF_vect) {     // ISR called by timer interrupt every 58uS
  temps = (bitRead(PINx, PinIn));
  if (temps == 1)
    PORTx = Etat1;
  else
    PORTx = Etat2;
  interruptHandler();
 temps = (bitRead(PINx, PinIn));
  i++;
  if ((i % 2) == 0) {
    if (temps != oldtemps) {
      bitt += 1;
      DccBitVal = 0;
    }
    else {
      bitt += 2;
      DccBitVal = 1;
    }
    oldtemps = temps;
    if (bitt > 1) {
      bitt = 0;
      bitCount++;
      switch (dccrecState) {
        case 0:
          if (DccBitVal) {
            if (bitCount >= 10)
              dccrecState = 1;
          }
          else {
            bitCount = 0;
          }
          break;
        case  1:
          if (!DccBitVal ) {
            dccrecState = 2;
            bitCount = 0;
          }
          break;
        case 2:
          if (bitCount == 8 ) {
            dccrecState = 3;
          }
          break;
        case 3:
          if ( DccBitVal ) {
            dccrecState = 4;
          }
          else
            dccrecState = 2;
          bitCount = 0;
          break;
        case 4:
          dccrecState = 0;
          PORTx = CutOut_ON;
          delayMicroseconds(420);
          PORTx = CutOut_OFF;
      }
    }
  }
}


Dans le void setup()   (CommandStation-EX), placer le code ci-dessous.

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)  // MEGA
  pinMode(35, OUTPUT);         // OUT 1  PC0
  pinMode(36, OUTPUT);         // OUT 2  PC1
  pinMode(37, OUTPUT);         // BRAKE  PC2
#else                                                           // UNO
  pinMode(A2, OUTPUT);         // OUT 1  PC0
  pinMode(A1, OUTPUT);         // OUT 2  PC1
  pinMode(A0, OUTPUT);         // BRAKE  PC2
#endif

Testé avec Mega, Uno et L298N, doit fonctionner avec L6203
Je viens de recevoir un LMD18200 mais il est défectueux, donc rien testé

Cablage :
Mega  =======> Bridge  Driver                 
    35  =======> In1  (Dir pour type LMD18200)
    36  =======> In2
    37  =======> Brake, seulement pour type LMD18200

  Uno  =======> Bridge  Driver                 
    A2  =======> In1  (Dir pour type LMD18200)
    A1  =======> In2
    A0  =======> Brake, seulement pour type LMD18200

Bien à vous.
« Modifié: Aujourd'hui à 01:35:49 am par lebelge2 »