B4R Question Timer interrupts in B4R?

Discussion in 'B4R Questions' started by positrom2, Apr 14, 2019.

  1. positrom2

    positrom2 Active Member Licensed User

    I am asking this since the Arduino-IDE up to the recent one (1.8.9) has a serious problem (a bug, at least for me) with the UNDO function, screwing up the code when used, occasionally, so it can't be used.
    https://forum.arduino.cc/index.php?topic=609254.0
    So I consider to come back to B4R...
    I am using the ESP32. In the Arduino-IDE, I am using a timer-interrupt to get a position reading as fast as possible from a sensor attached to SPI (50µs works at present), so the void loop (almost) always knows the position and can react on that.
    Code:
    void IRAM_ATTR onTimer() {
      portENTER_CRITICAL_ISR(&timerMux);
      digitalWrite(CSB, LOW);
      SPI.transfer(
    0xA1);
      dataLSB = SPI.transfer(
    0x00);
      digitalWrite(CSB, HIGH);
      digitalWrite(CSB, LOW);
      SPI.transfer(
    0xA2);
      dataMSB = SPI.transfer(
    0x00);
      digitalWrite(CSB, HIGH);
      position = (dataMSB << 
    8) | (dataLSB);
      position = (position >> 
    6)-90;
      dacWrite(DAC_Channel_1, position);
      portEXIT_CRITICAL_ISR(&timerMux);
      // Give a semaphore that we can check 
    in the loop
      //  xSemaphoreGiveFromISR(timerSemaphore, 
    NULL);
      // It 
    is safe to use digitalRead/Write here if you want to toggle an output
    }
    I read that interrupts are not implemented in B4R,(?).
    Would the use of the timers in B4R be equivalent to using the timer interrupts in the Arduino-IDE?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Interrupts can be used in libraries, though your code will run outside of the interrupt method.

    B4R timers are not based on interrupts.

    I think that an AddLooper should be fast enough. See the timings results: https://www.b4x.com/android/forum/threads/timers-loopers-and-callsubplus.65989/#content
    1750 loops per milliseconds = ~2 loops per microsecond.
     
  3. positrom2

    positrom2 Active Member Licensed User

    Thank you, I will see.
    But please help me (after two years coming back to B4R):
    I have an older project, containing, e.g. "Private ssd As AdafruitSSD1306"
    That line displays as usual (but compiling throws a lot of errors).
    Now I make a new project by
    "File, New, pasting the old code into the new project, and saving in the same directory as the old one.
    But there "ssd As AdafruitSSD1306" and references to "ssd.GFX" are underlined in red and "ssd" is posted as "Undeclared variable".
    Why are statements like "ssd As AdafruitSSD1306" recognized in the old code but not in the same code pasted in a new project?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Have you checked the relevant library in the libraries tab?
     
  5. positrom2

    positrom2 Active Member Licensed User

    Forgot about that.
    Compiles for the ESP8266 but not for ESP32....(see error obove).
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    This means that the library is not compatible with ESP32. Based on the error message it might be a simple change (other changes might be required as well).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice