In my example, how ATmega328 work with X and Y device's

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

In the hypothetical situation, if I have ATmega 328, Sensor X to detect object and output device Y.

 

Response time of X is 60 ms

Response time of Y is 30 ms

 

Program flow for the system

 

 

How the atmega work with X and Y in context of timing?

 

Atmega is faster then X and Y. When sensor X detecte object , Does atmega wait for 60 ms to read X? And After that it turn on the device Y. Does it happens.

This topic has a solution.
Last Edited: Mon. Aug 10, 2020 - 04:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why is the AVR concerned with the response time of the sensor and output device?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you mean you have to poll the state of X and Y then set up a 30ms timer interrupt then read Y on every tick and X on every second tick.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

Why is the AVR concerned with the response time of the sensor and output device?

 

Kartman wrote:

Why is the AVR concerned with the response time of the sensor and output device?

 

When we design the program, we do not know which method would be more efficient.  I started on paper to solve problems. I  found two methods I just  want to find out what is the best method for system. 

 

In my opinion interrupt method is more efficient because it save time of CPU

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

everything has a cost. Interrupts won’t necessarily make it more efficient. Besides, what other work is there to do?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How the atmega work with X and Y in context of timing?

At least think about what you are planning...you are in charge of how the mega works the sensor response, since you are writing the program.

 

What do you want it to do?  If you don't know, it certainly won't happen.  Exactly what problem are you solving--you need to have a clear picture & idea of that.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sun. Aug 9, 2020 - 03:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was looking for the answer to  question,  why do you need a timer interrupt?

 

I found the Timer interrupt can be used in multitasking to allocate the time for each task . That's why I took two tasks 

 

But Multiple tasks can be complete in  sequence, so there will be no need for timer interrupt..

 

I am looking for an example of timer interrupt that indicate that we really need timer interrupt in our system

 

Last Edited: Sun. Aug 9, 2020 - 05:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am looking for an example of timer interrupt that indicate that we really need timer interrupt in our system

Why didn't you say so in your first post?

    Interrupts are used when rapid polling (to get an immediate response) would be too wasteful.

 

The interrupt is like your doorbell.  If you know someone is going to deliver a bar of gold sometime in the next 12 hours, you might go check your front door every 15 seconds so you can take it straight to the vault.  But all of this constant checking (polling) will waste your whole day; nothing gets done.  Instead, you set up a doorbell (interrupt)...now you can go about your tasks & the doorbell will interrupt you at the proper time, increasing you efficiency.

When you can't afford to wait around (but need a rapid response), use an interrupt.

 

If you want to do some timing & have a quick tick 100 times a second, you might try checking it 500 times a second for a rapid response & to ensure you don't miss it....so you waste a lot of time doing nothing...the big waiting game.

Instead, let the timer interrupt you at the proper time.  You don't miss anything, and get a rapid response.  You can use all that saved time to calculate chess moves.

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think we need to separate timers and interrupts. They're commonly used together, but lets not confuse the two.

 

Firstly, in terms of time - we have two choices - a delay where we waste cpu cycles. Knowing the speed of the cpu we can determine how many cycles to waste to give us a known time. The downside is the cpu is sitting there wasting cycles where it could otherwise be doing other useful work. If we knew how long this other 'useful' work took, then we could estimate time based on this, but that means ensuring the other work operates in a known time - this can be difficult to achieve in practice.

 

The solution to that is to have a separate reference of time. Commonly microcontrollers have timer hardware to perform this task. Using a timer, you can configure it to count time and provide a means to the code to determine if a certain amount of time has elapsed. There a two choices - have your code ask the timer if the time has elapsed, or configure the timer to give an interrupt. Whether you use interrupts or not depends on the application, however, it is usual to have the timer interrupt at a convenient time period - may 1ms, 10ms or whatever suits your application. You can then count these for longer time periods. If you're dealing with switches, relays, lamps etc - these are relatively slow. Eg: many relays take 100ms to open/close,  character lcds take around 100ms to update - as well, the average human won't be able to read anything changing much faster than 10 times per second.

 

With the Arduino system, they provide the millis() function which gives you a count of the milliseconds that has elapsed from power on. Your code can use this to time its functions. This is used in many Arduino sketches.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks avrcandies and kartman

 

I know what are timer interrupt but i dont know when they really needs in project.  So I want to design a system that really needs timer interrupt. For this I started searching project's on the internet. I have read many old threads but At most, I get information only for leds  pulse counter etc. I have not yet seen such a project that will show that interrupt really needed the in this project.

 

I need help to define problem statement that requires timer interrupt in the system design

Last Edited: Mon. Aug 10, 2020 - 09:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Djsarkar wrote:

I need help to define problem statement that requires timer interrupt in the system design

 

 

Simple. You write some code to solve a problem without using timer interrupts and it doesn't work.

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

Djsarkar wrote:

I need help to define problem statement that requires timer interrupt in the system design

 

 

Simple. You write some code to solve a problem without using timer interrupts and it doesn't work.

 


If I want a specific time period, I can get it in three ways delay function, polling and interrupt,

That's why the question, why do you need timer interrupt in project.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Djsarkar wrote:

If I want a specific time period, I can get it in three ways delay function, polling and interrupt, That's why the question, why do you need timer interrupt in project.

 

Let's look at those in details...

 

Delay function...

 

1) will only be accurate if you are not using interrupts elsewhere (eg serial comms). When you use an interrupt you will interrupt the delay function and then the result will not be accurate

2) blocks execution. When you execute 'delay-ms(500)' your chip will be unavailable to do anything else for, in this case, 500ms

 

Polling...

 

1) blocks execution. If you are polling on a change of state then the chip cannot do anything else. There are ways around this but that leads to even more...

2) no accurate timing possibilities

 

(Timer) Interrupts...

 

1) Predictable timing

2) Easy to design/use

3) One timer ISR can do multiple jobs

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

Last Edited: Mon. Aug 10, 2020 - 10:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wrote a tutorial here on multi-taskng that gives an example. Flex yourGoogle-fu and see if you can find it. If you can’t find it, then learning about timer interrupts is useless to you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Djsarkar wrote:

In the hypothetical situation...

 

Instead of trying to imagine hypothetical situations, why not write some code for a real situation?

 

Why not make something? What hardware do you have available?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unfortunatly I do not have any board for practice so I cannot test any program. All shops are mostly closed due to lock down

That's why I'm spending more and more time reading microcontroller data sheets. I am very eager to program the board but bad luck because of covid

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What part of the world do you live in?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

What part of the world do you live in?


I stay at mp India So where I live is declared a Containment Zone, Online delivery is not possible right now in my area.

It seems that until I have a board, I should not ask questions and just read the book.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's why the question, why do you need timer interrupt in project.

Did you read responses #8 & #9 why interrupts are so useful?

 

I have a sensor low/high signal which is going to go high sometime during the next two days.  When it does, I need to activate a driver transistor & start sending an spi byte within 20 microseconds of it rising.  The interrupt response is the answer!!  

If interrupts used as a timer response, then each tick of the timing can be accomplished without missing any (assuming no other interrupts block for multiple timer tick durations).  Hopefully, that puts your question to rest. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!