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

delay

Discussion in 'AVR' started by rostyslav, Sep 26, 2014.

  1. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    hi everyone.
    sorry for my english, i'm foreign. i started to study english and microcontrollers recently. but i wish to study it in english only. so I hope for your help.

    so 1st question
    how i can to get a delay, for example , 30 sec. How it works?

    thank you very much.
    best regards.
     
  2. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,514
    Likes:
    507
    Location:
    Vermont (GMT-5:00)
    Hi rostyslav, welcome to ETO!

    We can't help you much without knowing what microcontroller and compiler you plan to use.

    What I can tell you is that there are two main ways to make a delay--a NOP statement ("no operation") that basically says to not do anything. This "wastes" a certain number of clock cycles (depends on your processor how many you waste, but I want to say it's usually one cycle). You can line up a bunch of these in a row to create a delay. However, this method is fairly useful, and you can't do anything with your processor until those NOP statements are done. This leads us to our second option, which is to make use of the Timers that are built into some microcontrollers. These timers count up once each cycle, and when they hit a pre-defined value, they trigger an "interrupt". You can use the timers to create delays.

    Again, it would help to know what kind of microcontroller and what compiler you'd want to use, as they are all different.

    Regards,
    Matt
     
    • Agree Agree x 1
  3. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    thank you very much!!! feels friendly atmosphere here.
    i bought microcontroller atmega 168 and use compiler avr studio
     
  4. dave

    Dave New Member

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


     
  5. cowboybob

    cowboybob Well-Known Member Most Helpful Member

    Joined:
    Oct 22, 2011
    Messages:
    3,051
    Likes:
    479
    Location:
    James Island, SC

    This has a very short program that addresses your question about the "delay" function:

    http://www.pololu.com/docs/0J36/3.b
     
    • Agree Agree x 1
  6. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    time to learning is started..... thanks all!
     
  7. cowboybob

    cowboybob Well-Known Member Most Helpful Member

    Joined:
    Oct 22, 2011
    Messages:
    3,051
    Likes:
    479
    Location:
    James Island, SC
    Have fun, rostyslav!
     
  8. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    I'll be back again!!!
     
  9. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    so, as I understand after that microcontroller was connected to 5 v it begin counting. then counting arrives to 1024 and will reset. after that register 1st flag? it is correct?:banghead:
     
  10. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,514
    Likes:
    507
    Location:
    Vermont (GMT-5:00)
    Yes and no. What you refer to is an 8-bit counter. Some microcontrollers have 16-bit counters, which can count even longer. Also, the timer does not begin when you connect power. You have to tell the timer to begin in the code, and before you do that you need to set it up (set mode, initial conditions, etc). When the timer counts up to its limit and resets, it sets an interrupt flag. If you have an ISR ("Interrupt Service Routine"), it will trigger at that time.
     
    • Agree Agree x 1
  11. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    Is possible count frequency with flags? like by speed sensor
     
  12. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,514
    Likes:
    507
    Location:
    Vermont (GMT-5:00)
    If you know the frequency at which your timer is incrementing, then yes. However, you will not be using the timer interrupt. Instead, you'll need to use an external interrupt, and the timer to clock the amount of time between signals. Obviously you'll need some extra circuitry to do this, depending on your speed sensor.

    I don't think you really understand what a "flag" is though. It's just a bit that is set if a certain condition becomes true. You should read your microcontrollers datasheet to see how they work on that processor.
     
    • Like Like x 1
  13. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    for example , if I wish to receive signal from speed sensor on my car and establish condition when if frequency is 100 times for second, then to do something, else to do nothing, so which extra circuitry I need?
     
  14. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,514
    Likes:
    507
    Location:
    Vermont (GMT-5:00)
    It highly depends on what kind of speed sensor you have. I think that question would be better suited for an automotive forum that deals with the type of car you have. We can only help once we know what kind of signals exist at the output of your car's speed sensor. Let us know when you have that information, and we'll move on from there.
     
    • Informative Informative x 1
  15. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    for now thank you very much. I like to be here very much. When I'll have information about signal by sensor I immediately tell you.
    thanks again
     
  16. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,967
    Likes:
    1,099
    ONLINE
    • Like Like x 1
  17. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    Gyus I don't understand. When I give voltage at pin of microcontrollers it become high level?
     
  18. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    for example I would the microcontrolers when receive voltage on pin a turn on pin d.:(
     
  19. cowboybob

    cowboybob Well-Known Member Most Helpful Member

    Joined:
    Oct 22, 2011
    Messages:
    3,051
    Likes:
    479
    Location:
    James Island, SC
    Look up "IF" statements for AVR Studio.

    Digital Input/Output (DIO) Pins must be declared (in software that you write) as either having a normal "HIGH" condition (or "ON": a voltage is present or a ground is absent) or a normal "LOW" condition ("OFF": a voltage is absent or a ground is present).

    Then an IF statement can compare the condition of the pin to what was declared as normal, above) and when different than normal (or, for that matter, the same as normal), perform some task (for instance, set a different pin to a HIGH/ON or a LOW/OFF condition.
     
    Last edited: Oct 10, 2014
    • Like Like x 1
  20. cowboybob

    cowboybob Well-Known Member Most Helpful Member

    Joined:
    Oct 22, 2011
    Messages:
    3,051
    Likes:
    479
    Location:
    James Island, SC
    Look up IF statements in AVR Studio.
     
  21. rostyslav

    rostyslav New Member

    Joined:
    Sep 26, 2014
    Messages:
    18
    Likes:
    0
    Location:
    Ucraine
    In what way I can declare pin as "HIGH"?
     

Share This Page