Forum Rule: Always post complete source code & details to reproduce any issue!
Page 5 of 5 FirstFirst ... 3 4 5
Results 101 to 110 of 110

Thread: Arduino Events

  1. #101
    Senior Member
    Join Date
    Jul 2014
    Location
    New York
    Posts
    443
    @defragster. First, I apologize for being long winded but Conceptually I thought I understood what was going on with the eventresponder, at least for the repeating timer piece. However, with all the talk about chaining I started to dig into the inner workings to figure chaining out.

    What I found was Tail-chaining as it refered to interrupts and the chaining of PIT timers, but I couldn't see where that was applicable to repeating timers.

    So I then looked at what was going on with the code and that led me to Systick_isr which is runs the runFromTimer() function which is using the linked list (which I knew nothing about, oh well). From what I think I am seeing that systick_isr is running every millisecond so each timer created is decremeted until it hits zero and then the original value gets reloaded into the list and the process starts all over.

    This is done via timer -> _ms decremented timer and timer -> reload which reloads the original timer value. The event gets triggered by the call to event.triggerEvent(0, timer). The process is shown below (i put a couple of prints where i thought things where happening):
    Code:
    =========
    #define EVENT2_TIME 850
    #define EVENT3_TIME 1050
    #define EVENT4_TIME 250
    #define EVENT0_TIME 750   (loop trigger at 750)
    ========
    EventResponder test 
    ms timer: 248
    ms timer: 247
    ms timer: 246
    ms timer: 245
    .......
    .......
    .......
    ms timer: 4
    ms timer: 3
    ms timer: 2
    ms timer: 1
    ms timer: 0
    Reload: 250
    ms timer: 250
    2213 - T4(0)           250 (T4)
    ms timer: 249
    ms timer: 248
    ms timer: 247
    .....
    .....
    .....
    ms timer: 3
    ms timer: 2
    ms timer: 1
    ms timer: 0
    Reload: 250            500  (T4)
    ms timer: 250
    2463 - T4(0)
    ms timer: 249
    ms timer: 248
    ms timer: 247
    ms timer: 246
    ....
    ....
    ....
    ms timer: 5
    ms timer: 4
    ms timer: 3
    ms timer: 2
    ms timer: 1
    ms timer: 0
    Reload: 250             
    ms timer: 100           next timer is at 850-750=100
                            for T2
    2713 - T4(0)            750  (T4) next trigger at 1000
    ms timer: 99
    ms timer: 98
    ms timer: 97
    .....
    .....
    .....
    ms timer: 5
    ms timer: 4
    ms timer: 3
    ms timer: 2
    ms timer: 1
    ms timer: 0
    Reload: 850         850 actually funny  because its loading
                        850 for T2 timer plus 850 passed
    ms timer: 150       150 left to go to T4 which is at 1000
    2813 - T2(0)
    ms timer: 149
    ms timer: 148
    ms timer: 147
    ......
    ........
    ......
    ms timer: 4
    ms timer: 3
    ms timer: 2
    ms timer: 1
    ms timer: 0
    Reload: 250
    ms timer: 50            50 left to T3
    2963 - T4(0)            bingo hit the T4 timer which is 
                            at 1000.  T3 should happen again
                            at 
    loop trigger dosomething
    dosomething event
    ms timer: 49
    ms timer: 48
    ms timer: 47
    ......
    ......
    ......
    ms timer: 3
    ms timer: 2
    ms timer: 1
    ms timer: 0
    Reload: 1050
    ms timer: 200
    3013 - T3(0)        Ok got through the cycle
    Now what i don't understand is how the linkedlist actually gets created. It is, i think i know how, but its not what is shown when i do search for c++ linkedlist. Still have to figure out how the interrupt piece works because I did see anything where a IRQ number is assigned. I did see where pendSV is set - have to figure that one out next. Do you have an example of eventresponder using interrupt events?

    Thanks for all your help.
    Mike

  2. #102
    The discussion I recall about tail chaining was only when the interrupt vector was already claimed but another purpose called for it to be added to but not replaced. That was resolved in TeensyThreads to allow EventResponder to continue to function with the updated code.

    As far as the linked list - that is just an internal storage detail for the Events to be queued and accessed and tended to as time passes.

  3. #103
    Senior Member
    Join Date
    Jul 2014
    Location
    New York
    Posts
    443
    @defragster. Thanks for the information. Clears a bit up for me on chaining.

  4. #104
    Senior Member
    Join Date
    Jul 2014
    Location
    New York
    Posts
    443
    Hi all. Was playing around more with EventResponder and decider to give a go at triggering events from threads. After some headaches i managed to get it to create a blink example based on @Bill Greiman post. What can I say. Here is code but not sure if this is the best method or there is a better way, any suggestions would be helpful:
    Code:
    #include <EventResponder.h>
    #include <Arduino.h>
    #include "TeensyThreads.h"
    
    const int LED = 13;
    bool test;
    int tOn, tOff;
    
    volatile int blinkcode = 0;
    
    EventResponder led_switch;
    
    void ledOn() {
      while(1) {
        digitalWrite(LED, HIGH);
        delay(500);
        led_switch.triggerEvent(1);
        //threads.yield();
      }
    }
    
    void ledOff() {
      while(1) {
          //Serial.println(led_switch.getStatus());
          if(led_switch.getStatus() == 1){
            threads.suspend(tOn);
            digitalWrite(LED, LOW);
            led_switch.triggerEvent(0);
            led_switch.clearEvent();
          }
          delay(500);
    
          threads.restart(tOn);
    
      }
    }
    
    
    void setup() {
      while (!Serial && millis() < 4000) ;
      Serial.println("EventResponder test");
      pinMode(LED, OUTPUT);
      tOn = threads.addThread(ledOn);
      tOff = threads.addThread(ledOff);
    }
    
    
    void loop() {
    
    }
    v/R
    Mike

  5. #105
    Hi

    What's the current status for the Interface? (EventResponder and MillisTimer)

    Is it "safe" to use in new code?

  6. #106
    Quote Originally Posted by AlainD View Post
    Hi

    What's the current status for the Interface? (EventResponder and MillisTimer)

    Is it "safe" to use in new code?
    Hi could somebody give a short answer?

    It won't be a critical project, but I rather not start over.

  7. #107
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,720
    It's still considered experimental. The API may change in the future.

  8. #108
    Quote Originally Posted by PaulStoffregen View Post
    It's still considered experimental. The API may change in the future.
    Paul

    thanks. Is it only a possible API change or is it still possible that the principal idea goes away for EventResponder and MillisTimer.
    I would use it to let class instances do thing automatic. For example a encoder knob with pushbutton -encoder class for the encoder- and a bounce claas inside it, but without the need to call update regulary.
    Changing API is small versus going away of the principle.

  9. #109
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,720
    The API details may change, but we're definitely going to have something similar if it does change.

  10. #110
    Quote Originally Posted by PaulStoffregen View Post
    The API details may change, but we're definitely going to have something similar if it does change.
    Thanks, will start using it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •