A timer Interrupt to cause delay

AI Thread Summary
The discussion centers on a user's attempt to implement a timer interrupt in a program for a microcontroller to create a delay of approximately one second for displaying binary numbers. The user has configured the timer and interrupt settings but is not achieving the desired delay. Key points raised include the configuration of the timer and the interrupt service routine, which currently only clears the interrupt flag without performing any additional actions. Concerns are expressed about the effectiveness of the interrupt handler, as it does not seem to perform any meaningful task beyond acknowledging the interrupt. Additionally, there is a mention of the general purpose of interrupts in operating systems, highlighting their role in managing processes and resources. The conversation suggests that the code may not function as intended due to the lack of operations within the interrupt handler, which is critical for achieving the desired timing effect.
Mathslova
Messages
7
Reaction score
0
I am new to interrupts, so i have made a simple program using a timer interrupt to cause a delay of about 1 sec in displaying the binary numbers. However I have failed to achieve this.

Anyone knows the problem with my program?

any assitance will be highly appreciated.

#include <p24FJ128GA010.h>

_CONFIG2( FNOSC_FRCPLL & OSCIOFNC_OFF ); // Internal oscillator - 4xPLL giving 16 MIPS
// pin RC15 has the oscillator

int main()
{
//Configure the device to use the internal oscillator
OSCCONbits.COSC = 1u; // Internal oscillator with PLL
CLKDIVbits.RCDIV = 0u; //Internal oscillator not divided (8MHz)
CLKDIVbits.DOZEN =0; //No post scaling
CLKDIVbits.DOZE =0; //



//Set the LSB of port A to be outputs
TRISA = 0xFF00;

//TIMER1 Configuration Register
T1CON = 0;
T1CONbits.TCKPS = 0b11; //Prescale = 256
T1CONbits.TON = 1; //Timer on
TMR1 = 0; //Timer = 0

//Configure TIMER1 interrupt
_T1IP = 4; //Interrupt priority = 4
PR1 = 62500-1; //Period Register

_T1IF = 0; //Clear timer interrupt flag
_T1IE = 1; //Switch on timer 1 interrupt enable

TMR1 = 0;

while(1)
{
Idle();
asm("nop");
PORTA = 0b11111111;
PORTA = 0b00000000;

}//end while loop


}//end main loop





//TIMER1 Interrupt
void __attribute__((interrupt, no_auto_psv)) _T1Interrupt()
{

_T1IF = 0; //Clear interrrupt flag before returning
}
 
Technology news on Phys.org
I am aware of timer interrupts. I've used the sleep(int seconds) procedure to set a thread to sleep for a set number of seconds. You can have a process wait for a resource with the wait() function or its equivalent and have the process currently using the process signal the waiting process when its done.

But, if you're only familiar with interrupts in the programming sense, then you might not be aware of the purpose of interrupts. In Operating Systems, an interrupt stops the currently running process so that the process which was formerly blocked-waiting for an event, can now run.

For instance, your keyboard is able to accurrately able to show all characters you're typing in the rate at which you're going, eventhough other processes (such as the ones involving your monitor screen) are operating, with the use of interrupts.

However, I wonder how does one in a UNIX/Unix-like system implement interrupts without the usage of mutexes, semaphors, and the like.
 
It looks as if you are running this code on some kind of microcontroller? Which one?

Although I'm not familiar with the specific microcontroller you're using, it doesn't appear to me that this code should be expected to do anything. It looks to me like 1 second after the line _T1IE = 1; we should expect _T1Interrupt to trigger. But it doesn't look like T1Interrupt actually does anything? It looks like it just marks the interrupt serviced and returns. As michinobu points out interrupts are, well, "interrupts", the code will not be waiting around after the _T1IE = 1; line for the interrupt to occur.

What is it you think this interrupt handler is doing?
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
3
Views
2K
Replies
2
Views
2K
Replies
2
Views
6K
Replies
2
Views
7K
Replies
1
Views
3K
Back
Top