Timer Interrupts question

Thread Starter

zanuro3

Joined Mar 28, 2017
5
A microcontroller has a Timer peripheral that can be configured to generate a hardware interrupt every 10 ms. I need to describe an interrupt service routine that maintains real time I.E. ticks, seconds, minutes and hours based on this interrupt. I also need to explain what happens to the MCU registers (accumulators, index register, stack pointer, program counter, etc) when the interrupt occurs and when the interrupt ends and explain the logic of the program.

Not sure how to go about this. If the clock cycle is 10 ms, I believe I understand how the ticks will give me seconds and seconds will give me minutes after. However, I don't know what happens to the registers as each interrupt occurs. Thanks in advance.
 

click_here

Joined Sep 22, 2020
446
A microcontroller has a Timer peripheral that can be configured to generate a hardware interrupt every 10 ms. I need to describe an interrupt service routine that maintains real time I.E. ticks, seconds, minutes and hours based on this interrupt. I also need to explain what happens to the MCU registers (accumulators, index register, stack pointer, program counter, etc) when the interrupt occurs and when the interrupt ends and explain the logic of the program.

Not sure how to go about this. If the clock cycle is 10 ms, I believe I understand how the ticks will give me seconds and seconds will give me minutes after. However, I don't know what happens to the registers as each interrupt occurs. Thanks in advance.
That is very implementation specific - Do you have a particular microcontroller that this question relates to?
 

DickCappels

Joined Aug 21, 2008
8,000
This is not that difficult. How would you do it if it were you, not some piece of hardware, and you were getting (for example) and email notification of each minute passing?

By the way, is this schoolwork?
 

Thread Starter

zanuro3

Joined Mar 28, 2017
5
That is very implementation specific - Do you have a particular microcontroller that this question relates to?
I'm mostly familiar with the motorola HCS12 but I believe this can be implemented on any microcontroller. It doesn't have to be explained using the registers I mentioned (accumulator, program counter). I only mentioned those since they are typical registers found in an MCU.
 

Thread Starter

zanuro3

Joined Mar 28, 2017
5
This is not that difficult. How would you do it if it were you, not some piece of hardware, and you were getting (for example) and email notification of each minute passing?

By the way, is this schoolwork?
This is a mix of schoolwork and curiosity. I'm not sure to be completely honest. The first thing that comes to mind is using our 10 ms tick, we would need to count it 1000 times to get exactly 1 second and then every time 60 seconds reach, we divide by 60 to get 1 minute. However, I'm having trouble trying to see what happens to the registers during this process. Please keep in mind, I'm still somewhat of a beginner when it comes to microprocessor systems.
 

click_here

Joined Sep 22, 2020
446
It's been a looong time sinse I programmed the HC11, but from memory you'd put the jmp ADDRESS into a vector table that gets called when the interrupt occurs.

6.3.2 here has more detailed info.

Basically you use the oscillator frequency to work out how many cycles of the clock is required to get a fraction of the time and have a timer compare interrupt.

When a certain amount of them happen you know that 10mS has passed; when you know a certain amount of 10mS has passes, 1 second has passed (ect...)
 

DickCappels

Joined Aug 21, 2008
8,000
You seem to have the basic concept down. Do you have reference materials that show how to increment a register and compare its value with a constant? After that you will be left is conditional branches. jumps, and of course I/O along with the interrupt service mentioned by @click_here .
 
In the archetecture I learned on, Interrupts had a "vector". This was essentially the address of the ISR.

the first thing that has to happen is the interrupts get disabled.
Before it got there the program counter and the processor status word was pushed on the stack.

Then it went and did the ISR

A return from interrupt restored the program counter and processor status word and restored the interrupts.

easy example.

pseudo assembly language.

Compare A with #1' This sets the processor status word if the result was positive, negative or zero
INTERRUPT
RTI_Here: Branch if equal.

It was a little more complicated than that, but that's the basic idea. Interrupts had priority and the PSW contains a lot more stuff. So, the retirn from interrupt would branch to RTI_Here and the processor would have no idea it ever left.

The service guys had a fit because they could not figure out what the problem was. The CPU was dropping a bit in the PSW when it changed modes. i.e. supervisor and user. Once I figured that out, they could fix it.
 

MIS42N

Joined Jan 25, 2013
19
I also need to explain what happens to the MCU registers (accumulators, index register, stack pointer, program counter, etc) when the interrupt occurs and when the interrupt ends ...
All of that is described in detail in the datasheet for the particular processor you are looking at. And it is different for each. The PIC16F628A does nothing with the accumulator, status register etc so the first thing the ISR has to do is save them and the last thing it does is put them back. The PIC161455 does it all in hardware so the ISR can run using registers knowing they will automatically be restored by the RETFI (return from interrupt).
Not sure how to go about this. If the clock cycle is 10 ms, I believe I understand how the ticks will give me seconds and seconds will give me minutes after. However, I don't know what happens to the registers as each interrupt occurs. Thanks in advance.
It's a strange sort of request. Understanding an IRC is simple, it is a bit of code started by an event (in your case the timer peripheral) and ends when it exits. However, interrupt routines are usually short bits of code being used by some other mainline code that does other things. It is possible to have mainlines that do nothing (i.e Loop GOTO Loop) or (Loop SLEEP ; GOTO Loop) and all the useful things happen in IRCs. In your case it looks like the IRC has to update a pile of counters before exiting.
 
Top