1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

how i can use Interuption in program

Discussion in 'AVR' started by danilk, Mar 1, 2016.

  1. danilk

    danilk New Member

    Joined:
    Mar 1, 2016
    Messages:
    1
    Likes:
    0
    hi everyone , i have a problems about interuption in AVR atmega, i trying to solve a problems is

    Turn led with two buttons
    bt1 in pd2 (int0)
    bt2 in pd3 (int1)
    LED must be Eteine if it exceeds 20s staying on, for that you need to configure a temp basis interupption for each 1s and realize a timer that counts the seconds
    party to achieve
    the configuration input output
    int0 configure and int1
    ISR (int0) and SRI (int1)
    configure the interuption of SRI timer 1
    SRI (tcnt1_compa_vect)
    incrementation of the counter
    reset to zero of the counter
    any solution ?
     
  2. riccardo

    riccardo Member

    Joined:
    Apr 15, 2010
    Messages:
    104
    Likes:
    2
    Location:
    United Kingdom
    Unfortunately it is difficult to tell what you are asking. Please ask someone to help you with the translation so that people can understand your question.
     
  3. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland

    Could you pleaser attach your full code? Use code tags if possible:
    {code}
    //code here
    {/code}
    ^replace above {} with [] so it looks like this:
    Code (text):

    //code here
     
    I'm no expert in AVR on in any code in that manner but still, willing to help!
    what I understood, is that you want led to turn OFF after 20 seconds?
    If that's the case, what funtion buttons serve? Counter on/off and reset?
    I'd do it so instead of counting seconds each time second has passed, I'd use Interrupt with timer registry with either overflow or compare-match method, which are then combined with timer interrupt....
    IF timing is not issue/non-cricital, you could also use chip-timer (millis for example) and use switches with boolean status.
    After writing this, I realized this is AVR, not arduino but oh well, those are still my cup of tea in this subject :D...
     
  6. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    What Atmega? What development environment?

    In my current project I use int4 for a button.
    Code (C):
    /* Initialize interrupts for button in INT4 (PORTE PIN4) */
    DDRE &= ~(1<<4);      /* PE4 as input */
    PORTE &= ~(1<<4);     /* No pullups (external pull-ups) */
    EIMSK |= (1<<INT4);   /* Enable INT4 */
    sei();                /* Enable global interrupts */
    And the ISR is:
    Code (C):
    ISR(INT4_vect)
    /* This handles Button presses */
    {
        /* Toggle LED etc.*/
    }
     

Share This Page