[Solved]Could you help me to understand the timer interrupt

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
What do you mean by LED has response time?
Define response time.
What do you mean by LED takes time to turn on?
What does this have to do with interrupts?
Please look post 95

Response time is the total amount of time LED takes to respond

Jpanhalt will tell us what is interrupt in this exercise
 

trebla

Joined Jun 29, 2019
542
So LED takes time to turn on
Yes, but MCU does know that, unless there is some sensor attached which can tell to MCU if LED is lit up. So your program flow is not affected by "LED response time".
 

jpanhalt

Joined Jan 18, 2008
11,087
So LED takes time to turn on, off, you have not mention this delay time

Which sequence of RGB do you want when a switch is pressed or an interrupt occur?
That does not meet the requirement od only one switch per state change. For example:

1597324478501.png

The red X requires two switch changes. Keep thinking about it. Hint: list every change of state that requires only one switch to change. You may see a pattern. There are 8 states, and it can be done 8 steps and get back where you started, or given a starting state, you can do it in 7 steps.

Keep thinking.
 

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
That does not meet the requirement od only one switch per state change. For example:

View attachment 214685

The red X requires two switch changes. Keep thinking about it. Hint: list every change of state that requires only one switch to change. You may see a pattern. There are 8 states, and it can be done 8 steps and get back where you started, or given a starting state, you can do it in 7 steps.

Keep thinking.
I'm sorry if i am asking too much question but I say very honestly that I do not understand your question

How many switches are there to control the three LEDs?

Is a one switch controlling all three LEDs?

You have mentioned interrupts. What does this mean? Do you mean external interrupt for switche ?

The led on or off depends on the action of the switch. LED will be OFF when the switch is OFF and LED will be ON when the switch is ON
 

jpanhalt

Joined Jan 18, 2008
11,087
I'm sorry if i am asking too much question but I say very honestly that I do not understand your question

How many switches are there to control the three LEDs?

Is a one switch controlling all three LEDs?

You have mentioned interrupts. What does this mean? Do you mean external interrupt for switche ?

The led on or off depends on the action of the switch. LED will be OFF when the switch is OFF and LED will be ON when the switch is ON
Three switches -- one per LED
A switch controls one and only one LED
This whole thread is about interrupts. Aren't they a type switch?

You asked for a problem; I gave you one. Personally, I consider solving that question more valuable as a learning exercise for you than discussing how long it takes for an LED to change state.
 

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
Three switches -- one per LED
A switch controls one and only one LED
This whole thread is about interrupts. Aren't they a type switch?

You asked for a problem; I gave you one. Personally, I consider solving that question more valuable as a learning exercise for you than discussing how long it takes for an LED to change state.
My Solution

IMG_20200813_212907.jpg
 
Last edited:

jpanhalt

Joined Jan 18, 2008
11,087
That doesn't cover all the states. There are 8 of them.
How do you get from red=off, green=off, and yellow=on to all three on with just one switch? There are several of those errors. You can only operate ONE SWITCH to change states.

Hint: Although I have given you the minimal number of steps required, try doing it with more steps. Maybe you will see the pattern then.
 

jpanhalt

Joined Jan 18, 2008
11,087
Better, but not quite there:

1597340470991.png

You cannot turn green on and yellow off in the same step. That is changing 2 switches not one.

As an example (from your drawing):
State1 = all off
State2 = red,off green,off, yellow,on
State3 = red,off, green,on, yellow,on
State4 = red,off, green,on, yellow,off

Each step only involves one switch change. Hint: that's about halfway there.
 

jpanhalt

Joined Jan 18, 2008
11,087
Assuming this:
1597346654001.png

is Off - On - Off, you are missing On - Off - On. Then you have to show the transition.

There are 8 distinct states. You cannot do it with just 7.
 

jpanhalt

Joined Jan 18, 2008
11,087
I give up.

How many times have I re-emphasized to only change one switch per change of state and pointed out your error? Not only did you not improve over your last your state diagram, you went for 7 states to 6. That is not enough. I thought you were catching on, but apparently not.

Here's the way I did it: Reduce the red,green, yellow to places in a 3-bit binary table. Then work from there. Here's one answer:

1597357813403.png
I understand that you may not have heard of Gray code, but your attempts seemed just random and showed little evidence of actually trying to solve the problem logically as presented. Gray code has found many applications to state switching. The Wikipedia article describes one of the most important.

Good luck.
 

BobaMosfet

Joined Jul 1, 2009
2,110
I am trying to understand how timer interrupts work in a microcontroller. I want to understand how the timer interrupt works in any microcontroller Before to understand how a timer interrupt works in a particular microcontroller,

I am assuming there is a timer that starts from 0, 1, 2, 3 . . and ends up to 255. I want the timer interrupt to be generated when timer reaches at 30

  1. When the timer interrupt generates, will the timer increment beyond 30 (30, 31, 32, ... 255)?
  2. When will timer interrupt finish?
  3. Does the processor complete its tasks from O to 30 and After that the task written in the interrupt routine is completed?
Since you're interested in an overview, how any interrupt timer works on any processor, I won't bother you with details of specific processors that are irreleveant.

All interrupts are based upon a prescaler value (a value that scales the MCU clock frequency to something lower). Normally, you cannot generate an interrupt faster than half the MCU full frequency. (This is why in a 16MHz MCU, the fastest interrupt frequency is 8MHz) In any given MCU you configure a prescaler counter that simply increments a register, basically counting MCU cycles until it's time to fire the interrupt, then it fires it.

This happens indefinitely once the interrupt is created, until it is specifically removed/stopped.

Interrupts usually require that any code the is executed by the interrupt take far less time than it takes between interrupts, so that the task can complete. Otherwise, when the interrupt fires again, the code already being executed will be parked, and restarted at a more recent iteration- new interrupt. Only when interrupts finally complete, will it wind its way back out of this.

That's a very high level overview.
 

BobaMosfet

Joined Jul 1, 2009
2,110
I am trying to understand how timer interrupts work in a microcontroller. I want to understand how the timer interrupt works in any microcontroller Before to understand how a timer interrupt works in a particular microcontroller,

I am assuming there is a timer that starts from 0, 1, 2, 3 . . and ends up to 255. I want the timer interrupt to be generated when timer reaches at 30

  1. When the timer interrupt generates, will the timer increment beyond 30 (30, 31, 32, ... 255)?
  2. When will timer interrupt finish?
  3. Does the processor complete its tasks from O to 30 and After that the task written in the interrupt routine is completed?
Just adding this here- you want an interrupt at 30. 30 what?

Interrupts are TIME-BASED mechanisms, so you have to decide the time-frame over which interrupts occur. If you want just 30 interrupts, then you have to mean 30 per second, 30 per minute, 30 per half-second.... and so on.
 

slackguy

Joined Feb 11, 2016
76
"You cannot compare PIC with ARM in any reasonable fashion."

I can if I want to. By the time you read this: both will have released a new model incompatible with the previous one!
 

slackguy

Joined Feb 11, 2016
76
"I am trying to understand how timer interrupts work in a microcontroller."

" I want the timer interrupt to be generated when timer reaches at 30"

Spin head What? For someone who doesn't understand microcontroller or timers you certainly have specific needs!
 

slackguy

Joined Feb 11, 2016
76
I'm trying to be short here.

Microcrontrollers are extremely complicated, made of millions of sub-circuits which form a timer circuit, an add, a buffer, a trigger, or something. They are a CPU but are a small subset of subset of the Intel x5-Z8330 or "system on a chip". They contain many chips you can say.

A timer times (usu. said to be by crystal waveform frequency). A "counter" counts waves events irrespective of time.

An "interrupt" is really meaningless. It is just a label on one of the wires attached to the cpu circuitry (highly miniturized parts). It mereley means the CPU will perform actions if the right signal is seen on that line.

An "analog timer" can be simple to build with (a Texas Instrument chip) - a common project. There are digital counters and timers for hobby (they require a whole suite of sister chips and sockets) - but they are harder to find as they aren't produced (because hobby boards have replaced that).

Electrical engineering a microcontroller to count of 30 would be the "very advanced part" (most people would use their pc OS software to set and use a timer!), and not all cpu will or can "count to 30". Fully integrating a timer to a microcontroller (or rather modernly, inside one) CORRECTLY is a lifetime achievement - not something done for fun (it takes allot of still and time). You don't do it just to count to 30!

Don't be confused: if you search "Texas Instruments" you'll find if you find a "interrupt controller" they don't all work on a time or count basis but something 1,000 times more complicated. For these "interrupt" means "activation of some nearly indescribable circuit".

An analog timer chip with a data sheet having circuit the average hobbyist can make a 30 second blinking LED with. The thing about timing circuits is they are very difficult to set up "stable" (many internet free diagrams don't work - this is because they flood the wrong way and so never oscillate). The timer chip contains quality circuits that maintain oscillating balance - trickier than you think to do.

https://www.ti.com/lit/ds/symlink/ne555.pdf?ts=1597599399861&ref_url=https%3A%2F%2Fwww.ti.com%2Fproduct%2FNE555

Counter chips I'll leave for you to look for. There are many kinds for many purposes, perhaps the most popular was the BCD counter (when they were still made) used with BCD led display. However: if you want to count 30 pulse events it will be difficult: there are too many "counters" available to look through and most require you have set up a (crystal frequency) and communicate with it digitally. There again, as it counts (even if it doesn't require crystal input), you must also be able to see the output somehow. This goes deeper and deeper into setting up a mini digital suit of chips to get the result of a bcd led output (it's old school, you'll want to more modern things like Pi or Intel hobby or Arduino).

If you want to count to one or two or so things are much simpler: use analog :)

Circuits that detect and show a led light up ranging from 1 to 6 leds are easy to find: an example is the "led volt indicator" which is made to light up LED to show voltage. It does not occur upon time and reacts to "the event of change" and also "enumerates", so it can be called "a counter", though it is not used the way other counters are - there are so many kinds of counters it fits within the scope of counters still.
 
Last edited:
Top