Continue to Site

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.

  • 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.

delay

Status
Not open for further replies.

rostyslav

New Member
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.
 
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
 
thank you very much!!! feels friendly atmosphere here.
i bought microcontroller atmega 168 and use compiler avr studio
 
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:
 
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:

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.
 
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.
 
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?
 
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.
 
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
 
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:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top