A timer Interrupt to cause delay

Click For Summary
SUMMARY

The discussion centers on implementing a timer interrupt using the Microchip PIC24FJ128GA010 microcontroller to create a delay of approximately one second. The provided code configures TIMER1 with a prescale of 256 and sets up an interrupt service routine (ISR) that currently does not perform any actions beyond clearing the interrupt flag. Participants highlight that the ISR must execute meaningful operations to achieve the desired delay effect, as simply marking the interrupt serviced is insufficient.

PREREQUISITES
  • Understanding of timer interrupts in embedded systems
  • Familiarity with Microchip PIC24FJ128GA010 microcontroller architecture
  • Knowledge of C programming for embedded applications
  • Basic concepts of interrupt service routines (ISRs)
NEXT STEPS
  • Review the Microchip PIC24FJ128GA010 datasheet for detailed timer and interrupt configurations
  • Implement meaningful functionality within the TIMER1 interrupt service routine
  • Explore the use of the sleep() function in conjunction with interrupts for timing control
  • Study examples of timer interrupts in embedded C programming for practical insights
USEFUL FOR

Embedded systems developers, microcontroller programmers, and anyone interested in learning about timer interrupts and their implementation in C for the PIC24FJ128GA010 microcontroller.

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?
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 1 ·
Replies
1
Views
3K