This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/EK-TM4C1294XL: how to monitor input signal for every 1 sec

Part Number: EK-TM4C1294XL

Tool/software: TI C/C++ Compiler

Hi all,

currently working on tm4c1294xl eval kit, currently iam working on project were i need to monitor input signal for every second if any change is there i need to perform neccesary action.

i tried with instruction  i32Val = GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_2) before starting the timer later on on i checking changes by if(i32Val == GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2))

by setting timer for every 1 second but it is not working , can any guide regarding this issue

Regards,

Prudhvi

  • easy: you sample the signal every second. end of the story.

  • Hi,
    Did you configure the GPIO Port E as input and enable Port E? How did you initialize the GPIO?

    Another question is where is your input coming from? Is it switching a lot within a second? If it is switching a lot then it is not reliable to read the input every 1 second. You may find the pin to be the same state at every second even though the input has switched many times. If you are looking for an input transition then you want to use the interrupt on the GPIO input. Whenever a specified edge is detected (i.e. rising edge or falling edge) then an interrupt is generated.
  • *** LIKE ***

    Well done Charles - far more astute than the response,  "Easy - read the pin every second!"        (only thing "easy" about that method is, (almost) assured "blindness"  - to transitions occurring > few Hertz!    While proclaimed as, "End of Story" - such may yield a "horror story.")

    Of course - your, "Interrupt upon any signal Edge Transition" is the normal/customary (and preferred) method - by far!       And creates a vastly improved, "End of Story."

  • The OP's issue may be related to:

    Configuration of the GPIO port/pins
    Configuration of the timer peripheral that is being used to time sampling of the input
    Sampling the input too infrequently
    If the input is sampled in interrupt context and the result handled in main context, then there is the possibility for synchronization issues within the code as well.

    However it is difficult to help without knowing more specifics about "but it is not working" -- we need to know a bit more about what exactly is not working. Posting the code that performs initialization, sampling, and showing how this is marshaled to whatever code is doing the handling, would be helpful too.

    Regarding the possibility for multiple edge transitions in the one second (or any other) period: If this input is coming from something like a pushbutton or other device which suffers from contact bounce, then for each closure / opening of the contact you are likely to get multiple transitions. This has the effect that if, for example, you are using a momentary pushbutton to implement the behavior of a "on / off" switch (push once to turn something on, push again to turn it off again), then it won't work correctly. Your software should sample the input more frequently and implement a debounce algorithm to reject the unwanted transitions.
  • Very caringly detailed - 12_squared.    Indeed conflicts w/the (lowercase inspired) "Easy - End of Story!"     As you (so) well note - the story HAS subtleties - rarely (very rarely - if ever) revealed by,  deeply thought,  "Does Not Work!"

    For YEARS - some here have argued for, "Poster Guidelines" which would enforce the presentation of, "Key Details" - just as you well note.    Vendor claims that "too difficult" - and "Does NOT Work" - as expected - echos endlessly - across this (unfruited) forum plain...

  • cb1_mobile said:

    Very caringly detailed - 12_squared.    Indeed conflicts w/the (lowercase inspired) "Easy - End of Story!"     As you (so) well note - the story HAS subtleties - rarely (very rarely - if ever) revealed by,  deeply thought,  "Does Not Work!"

    The story ALWAYS has subtleties. For best results on forums, one must be as specific as possible. It does take a certain amount of "homework" to prepare a good forum post -- and I've found on more than one occasion that as I was preparing such a post and collecting the details needed for it, I would come across the solution (or at least the cause of the problem) on my own.

    cb1_mobile said:

    For YEARS - some here have argued for, "Poster Guidelines" which would enforce the presentation of, "Key Details" - just as you well note.    Vendor claims that "too difficult" - and "Does NOT Work" - as expected - echos endlessly - across this (unfruited) forum plain...

    The form webpage for composing a question for the forum should include a short checklist of things that the poster is recommended to detail in their message. That way, as one is composing a post, one can see what types of things would typically be asked as follow-up questions and be reminded to detail those items up front. It should also include a link to the forum guidelines which has a more complete description of how to write a good post.
  • Several times - years past - I created, proposed & presented (right here) such a, "Poster Guidelines MANIFESTO."      (my "Off the Grid" - Escape/Roughing it cabin - was not far from the uni-Bomber's...     He of far more, "Manifesto Fame.")     Note - I have NO brothers ...  "to turn me in!"

    Certain vendor agents signaled their agreement - the guidelines were detailed & reasonable - and never adopted.     They sit - entombed & cob-webbed now - in forum rotation Hell...

    And predictably - blessed by "tacit approval" - "Does NOT Work" arrives w/mind-numbing regularity - wasting valued forum time, focus & energy...

  • Hi charles,

    thanks for reply i have intialised portE as an input port and i have to monitor heartbeat beat signal which is generated for every one second if not generated i need rise a signal after 5 sec


    can you help me with this issue
  • cb1_mobile said:

    Several times - years past - I created, proposed & presented (right here) such a, "Poster Guidelines MANIFESTO."      (my "Off the Grid" - Escape/Roughing it cabin - was not far from the uni-Bomber's...     He of far more, "Manifesto Fame.")     Note - I have NO brothers ...  "to turn me in!"

    Certain vendor agents signaled their agreement - the guidelines were detailed & reasonable - and never adopted.     They sit - entombed & cob-webbed now - in forum rotation Hell...

    And predictably - blessed by "tacit approval" - "Does NOT Work" arrives w/mind-numbing regularity - wasting valued forum time, focus & energy...

    Sorry to hear that but maybe you should put your forum guidelines on your own blog and link to it in replies to such "does not work" posts.

  • pras p said:
    Hi charles,

    thanks for reply i have intialised portE as an input port and i have to monitor heartbeat beat signal which is generated for every one second if not generated i need rise a signal after 5 sec


    can you help me with this issue

    Not sure exactly which issue you're having, but if you mean how to set up a pin change interrupt as Charles suggested:

    In initialization code try something like (note: untested code!):

    GPIOIntClear(GPIO_PORTE_BASE, GPIO_INT_PIN_2);
    GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_2);
    GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_2, GPIO_RISING_EDGE);
    GPIOIntEnable(GPIO_PORTE_BASE, GPIO_INT_PIN_2);
    IntEnable(INT_GPIOE);

    In your C startup file, put your interrupt handler in the correct place of the interrupt vector table.

    Somewhere in main before your main loop, do IntMasterEnable() to make sure interrupts work.

    Your interrupt would do something like (again, untested code!):

    void MyInterruptHandler(void)
    {
    uint32_t Status = GPIOIntStatus(GPIO_PORTE_BASE, true);
    GPIOIntClear(GPIO_PORTE_BASE, Status);

    if (Status == GPIO_INT_PIN_2) {
    // Do something here
    }
    }

    Hopefully I haven't forgotten a crucial step!

    Very important note: If this is a noisy input or makes unwanted transitions (as from a device prone to contact bounce issues like mechanical switches, pushbuttons, etc) or if it is just a noisy signal, then this method will cause unwanted interrupts and you will need a different method to handle this heartbeat signal. If this is a clean signal with no unwanted transitions then the interrupt can work but note that as with all interrupts your interrupt handler will be called asynchronously to your main code and you need to use whichever appropriate synchronization method to avoid those issues. Probably the easiest thing to do is declare a global volatile variable that you set in the interrupt and check for in your main code.

  • Greetings 12_squared,

    Suggest you & I - "flip a coin" - to determine who (first) gets to have their "heart-beat" so monitored/measured!
  • Hi,
    You can setup an oneshot 5s timer. Each time you receive a heartbeat interrupt you will kick off the timer. If you receive an interrupt every second then the timer is reloaded each time. If there is no heart beat for 5 seconds then the timer will expire and you can then assert a signal based on the timer timeout.
  • or you can do the other way around, without the use of a one-shot timer:

    1. time stamp the incoming pulse;
    2. poll the time. if it is more than n seconds, set a flag;
    3. done.
  • Charles Tsai said:
    Hi,
    You can setup an oneshot 5s timer. Each time you receive a heartbeat interrupt you will kick off the timer. If you receive an interrupt every second then the timer is reloaded each time. If there is no heart beat for 5 seconds then the timer will expire and you can then assert a signal based on the timer timeout.

    That is a really good idea! Simple and elegant. What I like most is that it requires minimal intervention from the CPU.

  • As firm/I do produce "MCU-based product" for the Medical Industry - might it be fair/proper to note - that such, "5 Seconds Elapsed - w/out a (human) "heartbeat"  likely indicates that the patient has EXPIRED?"     (5 Second heart-beat interval translates to Pulse Rate of  "12."      

    Even famed, superbly conditioned Sherpa guides - nearing the peak of  the Himalayas - are unlikely to survive @ 12 BPM!

  • cb1_mobile said:

    As firm/I do produce "MCU-based product" for the Medical Industry - might it be fair/proper to note - that such, "5 Seconds Elapsed - w/out a (human) "heartbeat"  likely indicates that the patient has EXPIRED?"     (5 Second heart-beat interval translates to Pulse Rate of  "12."      

    Even famed, superbly conditioned Sherpa guides - nearing the peak of  the Himalayas - are unlikely to survive @ 12 BPM!

    From the preceding messages I am not sure if the OP is monitoring a human heartbeat or a signal from some device which the OP is calling a "heartbeat." Perhaps if 5 seconds elapse without such a signal it means the device needs to be reset.

  • Should there exist "ANY" chance that the "heartbeat" is human generated - my issuing of caution must stand.

    Poster's opening post notes, "I need to monitor input signal for every second."

    It is my experience that (most) all "MCU heartbeats" are derived from some naturally occurring - or contrived - signal(s) originating from the MCU. Poster notes "input signal" - reasonably suggesting it is an "external signal" (and an uncertain one) - which is unlikely to comply w/"normal/customary"  MCU heartbeat...

    It would appear - from the (relative) simplicity of poster's question - that a full "awareness" of  "MCU's heartbeat" - is FAR from proven.      (My stack of chips - as justified herein - remains w/in the medical camp.)

  • Hi cb1,

      Is it possible that a person's hearbeat comes every second (ballpark number) but suddenly due to heart rhythm irregularity (I don't know the medical term) stops beating for a few seconds and then resume normal heartbeat again?

  • Hi Charles,        (you were NOT expected today!    Twas it not a "Charles-Free" Thurs & Fri?)     Some here - were about to run "Amuck!"    (ok - more amuck.)

    That medical term is "bradycardia," (slowed heart-rate) which is an arrhythmia - yet a "5 second absence" is EXTREME!

    Now a "Resting heart-rate of  "60" - is an indicator of an efficient heart/circulatory system!     And the "mating" - 1 second "beat interval" - indeed - further points to this as a "Medically based" posting.

    Keep also in mind - the 5 second interval was suggested by "helpers" - not the poster - and for the existing, "Facts in Evidence" - I much doubt that one inexperienced is  aware - of "heart-beat"  - as a descriptor of MCU's  health/functionality...     (All of the facts must be admitted & weighed - w/out prejudice - and w/recognizing the presenter's background & conditions)