Skip to content

Teensy 4.1 Problems #89

@jimmie11

Description

@jimmie11

I have a relatively large program running on a Teensy 4.1. The program has a web server, a TCP server and interfaces to two sensors.

The system is connected to a traffic loop. When a car comes, the loop is triggered and the teensy senses a "dry contact". I then start reading from the connected sensors. I am not using a pull-up resistor with the loop as I am relying on the internal one as shown in the attached code.

After about 800 loop activations, my code stops sensing the loop. I am sure that my code did not crash because I can still connect to the TCP server and can display data from the Teensy on a web browser. So the program is still running but is not sensing any loop closures. When I restart the program by connecting to its web server, everything starts working again.

I would appreciate any help regarding what may be causing this problem.

The code is below:

#include <Bounce2.h>
        Bounce myLoop1 = Bounce();
        Bounce myLoop2 = Bounce();
        int debounce_interval_time = 7;

        #define loop1 32    
        #define loop2 33

        volatile unsigned long   lastLoopTime;
        volatile bool leddarCapturing = false;

        bool loopInterrupt = false;
        long loopInterruptTime;
        long numLoopInterrupt = 0;

        void setup(void)
        {
          setUpPins();
          BounceInterrupt();

        }


        void loop()
        {
          //---------------------------------------------------------------------------------
            myLoop1.update();
            myLoop2.update();

            if (myLoop1.read() == 0) activateLoop1New();
          //---------------------------------------------------------------------------------
        }

        void setUpPins()
        {
          //------------------------------------------------------------------------------
          pinMode(loop1, INPUT_PULLUP);
          pinMode(loop2, INPUT_PULLUP);
          //------------------------------------------------------------------------------
          delay(500);
        }

        void BounceInterrupt()
        {
          //------------------------------------------------------------------------------
            myLoop1.attach(loop1);
            myLoop1.interval(debounce_interval_time);

            myLoop2.attach(loop2);
            myLoop2.interval(debounce_interval_time);
          //------------------------------------------------------------------------------
        }

        void activateLoop1New()
        {
          if ((millis() - lastLoopTime) > 120)  //Guard against multiple loop triggers within a short time
          {
            //----------------------------------------
            lastLoopTime = millis();
            if (! Capturing) 
            {
              digitalWrite(yellowPin, HIGH);
            }
            if (Capturing)
            {
              loopInterrupt = true;    
              loopInterruptTime = millis();
              numLoopInterrupt = numLoopInterrupt + 1;
              digitalWrite(yellowPin, LOW);
            }
            //----------------------------------------
          }
        }

Quick reply to this message[ Reply](https://forum.pjrc.com/newreply.php?do=newreply&p=310060&noquote=1)  [ Reply With Quote](https://forum.pjrc.com/newreply.php?do=newreply&p=310060) Reply With Quote   Multi-Quote This Message

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions