Forum Électro-Bidouilleur

Merci de vous connecter ou de vous inscrire.

Connexion avec identifiant, mot de passe et durée de la session
Recherche avancée  

Nouvelles:

Voir les contributions

Cette section vous permet de consulter les contributions (messages, sujets et fichiers joints) d'un utilisateur. Vous ne pourrez voir que les contributions des zones auxquelles vous avez accès.

Messages - pentahertz

Pages: [1]
1
Discussion Gnrale d'lectronique / Re: emetteur dcf77 en Europe
« le: décembre 12, 2023, 02:55:28 pm »
oui j'en ai tester beaucoup
ca fonctionne mais de gros probleme pour la reception
ca fonctionne pas tous les jours j'avais utilise ce code arduino nano

#include <TimeLib.h>
#define DCF77PIN 2           // input  - DCF signal from antenna pcb. Pin must an interrupt input!
#define DCF_INTERRUPT 0         // Interrupt number associated with pin

#define LED_LEAPYEAR 31       // output - LED - Leap year
#define LED_DCFSTATUS 42      // output - LED - On when we have good DCF data


// Pulse flanks
static unsigned long leadingEdge = 0;
static unsigned long trailingEdge = 0;
unsigned long previousLeadingEdge = 0;
int bufferPosition = 0;
// used in <Int0handler>
volatile unsigned int DCFSignalState = 0; // interrupt variables ALWAYS need volatile qualifier!!
boolean errorCondition = false;
// used in <loop>
int previousSecond = 0;
unsigned int previousSignalState = 0;

// DCF Buffers and indicators
static int DCFbitBuffer[59];                         // here, the received DCFbits are stored
const int bitValue[] = {1, 2, 4, 8, 10, 20, 40, 80}; // these are the decimal values of the received DCFbits
// dcf variables to store decoded DCF time in
int dcfMinute = 0;
int dcfHour = 0;
int dcfDay = 0;
int dcfWeekDay = 0;
int dcfMonth = 0;
int dcfYear = 0;
int dcfDST = 0;
int leapYear = 0;
// variables to check if DCF bits are valid
bool dcfValidSignal = false;
int dcfP1counter = 0;
int dcfP2counter = 0;
int dcfP3counter = 0;
int dcfParityCheckP1 = 0;
int dcfParityCheckP2 = 0;
int dcfParityCheckP3 = 0;


// variables used to store weeknumber and daynumber values
int dayNumber;
int weekNumber;

// only after start on a new minute, display received bits on inner LED ring
boolean MinuteMarkerFlag = false;


void setup() {
  // put your setup code here, to run once:
 Serial.begin(115200);
 pinMode(DCF77PIN, INPUT);
 initialize();
 attachInterrupt(DCF_INTERRUPT, int0handler, CHANGE);
   
}

//================================================================================================================
//
// Function name : processDcfBit
// called from   : <scanSignal>
//
// Purpose       : after reception of one good DCF bit, do some checks and save it in the DCFbitBuffer array
// Parameters    : none
// Return value  : none
//
//================================================================================================================

void processDcfBit(int dcfBit)
{
  //--------------------------------------------------------------------
  // display incoming DCF bits on inner LED ring
  //--------------------------------------------------------------------
  // only if we have valid DCF data or after an Minute Mark (EoM) signal


  //--------------------------------------------------------------------
  //   // Fill DCFbitBuffer array with DCFbit
  //--------------------------------------------------------------------
  DCFbitBuffer[bufferPosition] = dcfBit;

  //--------------------------------------------------------------------
  // Parity check
  //--------------------------------------------------------------------
  // DURING reception of the DCF bits, calculate and display the results of the DCF parity check.
  //
  // There is a Parity bit for the minutes, the hours and for the date.
  // DCF77 works with EVEN parity, this works as follows:
  // The hours for example have 6 bits plus a paritybit. The bits with value 1 are add up including the paritybit,
  // the result must be an even number. If there is a bit wrong received, a 0 is as 1, or a 1 is as 0 received,
  // then the result is uneven.  source: http://www.picbasic.nl/frameload_uk.htm?http://www.picbasic.nl/info_dcf77_uk.htm

  if (bufferPosition == 0)
  {
 
    // reset variables
    dcfP1counter = 0;
    dcfP2counter = 0;
    dcfP3counter = 0;
    dcfParityCheckP1 = 0;
    dcfParityCheckP2 = 0;
    dcfParityCheckP3 = 0;
  }

  // ----------------------------------------
  // First parity check: minute bits
  // ----------------------------------------
  if (bufferPosition == 28)
  {
    for (int i = 21; i <= 27; i++)
    {
      // count the number of bits with the value '1'
      dcfP1counter += DCFbitBuffer;
    }

    // perform P1 parity check. Parity is OK if the sum is an EVEN value
    if ((DCFbitBuffer[28] + dcfP1counter) % 2 == 0)
    {

      // Parity P1 PASS
      dcfParityCheckP1 = 1;
    }
    else
    {

      // we have no valid data!
      dcfValidSignal = false;

    }
  }

  // ----------------------------------------
  // Second parity check: hour bits
  // ----------------------------------------
  if (bufferPosition == 35)
  {
    for (int i = 29; i <= 34; i++)
    {
      dcfP2counter += DCFbitBuffer;
    }

    // perform P2 parity check. Parity is OK if the sum is an EVEN value
    if ((DCFbitBuffer[35] + dcfP2counter) % 2 == 0)
    {

      // Parity P2 PASS
      dcfParityCheckP2 = 1;
    }
    else
    {

      // we have no valid data!
      dcfValidSignal = false;
    }
  }

  // ----------------------------------------
  // Third parity check: date bits
  // ----------------------------------------
  if (bufferPosition == 58)
  {
    for (int i = 36; i <= 57; i++)
    {
      dcfP3counter += DCFbitBufferhttp://forum.arduino.cc/index.php/topic,44476.0.html

int dayWeekNumber(int y, int m, int d, int w)
{
  // Number of days at the beginning of the month in a normal (not leap) year.
  int days[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};

  // Start to calculate the number of days of the first two months
  if (m == 1 || m == 2)
  {
    // for any type of year we calculate the number of days for January or february
    dayNumber = days[(m - 1)] + d;
  }

  // now calculate for the other months
  // first, check for a leap year
  else if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
  {
    // we have a leap year, so calculate in the same way but adding one day
    dayNumber = days[(m - 1)] + d + 1;
  }

  else
  {
    //no leap year, calculate in the normal way, such as January or February
    dayNumber = days[(m - 1)] + d;
  }

  // Now start to calculate Week number
  if (w == 0)
  {
    //if it is sunday (time library returns 0)
    weekNumber = (dayNumber - 7 + 10) / 7;
  }

  else
  {
    // for the other days of week
    weekNumber = (dayNumber - w + 10) / 7;
  }

  // finished! return with the week number as an INT value
  return weekNumber;
}

//================================================================================================================
//
// Function name : calculateLeapYear
// called from   : <decodeBufferContents>
//
// Purpose       : determine if a given year is a leap year
// Parameters    : year - the year to test
// Return value  : '1' if the year is a leap year, '0' otherwise
//
//================================================================================================================

int calculateLeapYear(int year)
{
  if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
  {
    return 1;
  }
  else
  {
    return 0;
  }
}





void decodeBufferContents(void)
{
  // Buffer is full and ready to be decoded
  dcfMinute = bitDecode(21, 27);
  dcfHour = bitDecode(29, 34);
  dcfDay = bitDecode(36, 41);
  dcfWeekDay = bitDecode(42, 44);
  dcfMonth = bitDecode(45, 49);
  dcfYear = bitDecode(50, 57);

  //call function to calculate day of year and weeknumber
  dayWeekNumber(dcfYear, dcfMonth, dcfDay, dcfWeekDay);

  // Get value of Summertime DCFbit. '1' = Summertime, '0' = wintertime
  dcfDST = bitDecode(17, 17);

  // determine Leap Year
  leapYear = calculateLeapYear(dcfYear);
}




//================================================================================================================
//
// Function name : finalizeBuffer
// called from   : <scanSignal>
//
// Purpose       : Process the succesfully received DCF data of one minute
// Parameters    : none
// Return value  : none
//
//================================================================================================================

void finalizeBuffer(void)
{
  //--------------------------------------------------------------------
  // We are here because of the detected 2 second 'gap'.
  // Now check if it correspondends with the buffer counter
  // 'bufferPosition' which should be value 59
  //--------------------------------------------------------------------
  if (bufferPosition == 59 && dcfValidSignal == true)
  {

    // process buffer and extract data sync the time with the RTC
    decodeBufferContents();

    setTime(dcfHour, dcfMinute, 0, dcfDay, dcfMonth, dcfYear);
    Serial.println();
    Serial.print("Time: ");
    Serial.print(dcfHour);
    Serial.print(":");
    Serial.print(dcfMinute);
    Serial.println();
    Serial.print("Date: ");
    Serial.print(dcfDay);
    Serial.print("-");
    Serial.print(dcfMonth);
    Serial.print("-");
    Serial.print(dcfYear);
    Serial.println();
 
    // Reset running buffer
    bufferPosition = 0;

    // Reset DCFbitBuffer array, positions 0-58 (=59 bits)
    for (int i = 0; i < 59; i++)
    {
      DCFbitBuffer = 0;
    }

    // reset flag
    MinuteMarkerFlag = false;

  } // if (bufferPosition == 59)

  //--------------------------------------------------------------------
  // The buffer is not yet filled although the 2 second 'gap' was detected.
  // Can be result of a noisy signal, starting in middle of receiving data etc.
  // Turn 'Minute Mark' LED ON
  //--------------------------------------------------------------------
  else
  {
     // Reset running buffer and start afresh. Now we are in sync with the incoming data
    bufferPosition = 0;

    // Reset DCFbitBuffer array, positions 0-58 (=59 bits)
    for (int i = 0; i < 59; i++)
    {
      DCFbitBuffer = -1;
  }
  unsigned long startTime = sTimes[index % 100] - 1000L;
  index--;
  int tries = 0;
  while (k >= 0 && tries < 100) {
    tries++;
    unsigned long currTime = sTimes[index % 100];
    int bitVal = bits[(index + 1) % 100 ];

    for (int skip = 0; skip <= 4; skip++) {
      long tDiff = ((long)startTime) - ((long)currTime) - 1000L - skip * 1000L;
      if (tDiff < 0L) {
        tDiff = -tDiff;
      }
      if (tDiff < 20L + 10L * skip) {
        startTime = currTime;
        if (skip > 0) {
          for (int a = 0; a < skip; a++) {
            k--;
          }
        }
        if (k >= 0) {
          signalArr[k] = bitVal;
        }
        k--;
        break;
      }
    }


    index--;
  }
  boolean correctTimeStart = (signalArr[0] == 1);
  boolean parityMins = checkEvenParity(signalArr, 1, 8, 8);
  boolean parityHours = checkEvenParity(signalArr, 9, 15, 15);
  boolean parityDate = checkEvenParity(signalArr, 16, 38, 38);
  if (DEBUG) {
    debugSignal(signalArr, sTimes, bits, i);
  }

  for (int k = 0; k < 40; k++) {
    if (signalArr[k] != -1) {
      signalArr[k] = signalArr[k] * decodeMultipliers[k];
    }
  }

  int dcf_mins = getValue(signalArr, 1, 7);
  int dcf_hours = getValue(signalArr, 9, 14);
  int dcf_day = getValue(signalArr, 16, 21);
  int dcf_month = getValue(signalArr, 25, 29);
  int dcf_year =  getValue(signalArr, 30, 37);


  last_dcf_hours = dcf_hours;
  last_dcf_mins = dcf_mins;
  last_dcf_day = dcf_day;
  last_dcf_month = dcf_month;
  last_dcf_year = dcf_year;
  last_dcf_received = millis();

  if (correctTimeStart && parityMins && parityHours && parityDate) {
    dcfTimeDateReceived(dcf_hours, dcf_mins, dcf_day, dcf_month, dcf_year);
  }
  else if (correctTimeStart && parityMins && parityHours && !parityDate) {
                         // wait for a second
  digitalWrite(LED_BUILTIN, LOW);
    dcfOnlyTimeReceived(dcf_hours, dcf_mins);
    dcfIncompleteTimeDateReceived(dcf_hours, dcf_mins, dcf_day, dcf_month, dcf_year);
  } else if (parityDate) {
    dcfOnlyDateReceived(dcf_day, dcf_month, dcf_year);
    dcfIncompleteTimeDateReceived(dcf_hours, dcf_mins, dcf_day, dcf_month, dcf_year);
  }  else {
    dcfIncompleteTimeDateReceived(dcf_hours, dcf_mins, dcf_day, dcf_month, dcf_year);
  }

}// fin analyseSignal

boolean checkEvenParity(int* arr, int startBit, int endBit, int parityBit)
{
  int sum = 0;
  for (int k = startBit; k <= endBit; k++) {
    if (arr[k] != -1) {
      sum += arr[k];
    } else {
      sum = -1;
      break;
    }
  }
  int parity = arr[parityBit];
  if (sum == -1) {
    return false;
  }
  if (parity == -1) {
    return false;
  }
  if (sum % 2 == 0) {
    return true;
  }
  return false;

} //fin checkEvenParity

void debugPrint(String prefix, unsigned long time, unsigned long elapsed)
{
  Serial.print(prefix);
  Serial.print(time);
  Serial.print(" - ");
  Serial.print(elapsed);
  Serial.println();
} // fin debugPrint

void debugSignal(int* arr, unsigned long* st, int* bt, int i)
{
  Serial.println("RAW Data (2 lines)");
  for (int index = i - 40; index < i; index++) {
    Serial.print(st[index % 100]);
    Serial.print(",");
  }
  Serial.println();
  for (int index = i - 40; index < i; index++) {
    Serial.print(bt[index % 100]);
    Serial.print(",");
  }
  Serial.println();
  Serial.print("SIGNAL: ");
  for (int k = 0; k < 40; k++) {
    if (arr[k] == -1) {
      Serial.print("?");
    } else {
      Serial.print(arr[k]);
    }
    Serial.print(",");
  }
  Serial.println();
}// fin debugSignal

int getValue(int* arr, int startBit, int endBit)
{
  int sum = 0;
  for (int k = startBit; k <= endBit; k++) {
    if (arr[k] != -1) {
      sum += arr[k];
    } else {
      sum = -1;
      break;
    }
  }
  return sum;

}// fin getValue



3
Trucs et Astuces d'lectronique / Re: Supplment gratuit Elektor t 2023
« le: août 14, 2023, 07:48:21 am »
merci pour le lien

5
Trucs et Astuces d'lectronique / conomiseur de batterie
« le: août 06, 2023, 07:59:32 am »

6
Discussion Gnrale d'lectronique / Tachymtre compte tours scooter
« le: novembre 21, 2022, 01:22:00 pm »

7
Discussion Gnrale d'lectronique / Re: transistors darlington ULN2803A
« le: août 08, 2022, 06:40:15 am »

8
Discussion Gnrale d'lectronique / Re: transistors darlington ULN2803A
« le: juillet 30, 2022, 03:32:02 pm »
avez vous un montage qui permet d'alimenter le esp8266 par un port du attiny85 en 3.3v ou il faut mettre un relais ?

9
Discussion Gnrale d'lectronique / transistors darlington ULN2803A
« le: juillet 30, 2022, 11:05:21 am »

10
Discussion Gnrale d'lectronique / Re: Horloge numrique "fabrication"
« le: juillet 06, 2022, 06:33:01 am »
bonjour
j'ai fabriquer une horloge avec des afficheurs de 5 pouces c'est tres grand
le pb il y a plusieur leds en serie donc la tension et pres de 9.6v
il faut un controleur genre uln 2803

11
bonjour,
j'en ai acheter 2 modeles avec 3 canal et 2 canal jamais eu ce probleme
tu utilise alexa ?

13
Discussion Gnrale d'lectronique / Re: DEEPSLEEP RESET HARD
« le: juin 16, 2022, 06:01:23 pm »

14
Discussion Gnrale d'lectronique / Re: DEEPSLEEP RESET HARD
« le: juin 16, 2022, 05:56:02 am »

15
Discussion Gnrale d'lectronique / DEEPSLEEP RESET HARD
« le: juin 15, 2022, 01:18:23 pm »

Pages: [1]