Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Quick Interrupt question

Status
Not open for further replies.
If I'm using a timer driven interrupt (sayyyyy TMR2), and need to execute time crucial routines in the normal program (non ISR)...
Is it better at the begining of the time crucial routine to stop the timer, and start it again after the routine is finished, or is it better to mask interrupts during the routine.

If the latter, if the timer overflows during the routine, will the program still be interrupted when the interrupts are once again enabled?

Does this make sense?
 
If you disable global interrupts then when you re-enable them the ISR will get executed.

Mike.
 
You're gonna have to provide more info as Nigel asked, you're not giving us enough information about your program and what you need it to do to answer. I'd go with Pommie and say just disable interupts till your critical routine is done, but we don't know anything else about your code or what it might do to the behavior of your program.
 
The time crucial routine is communication with the ds18b20 via it's 1 wire port.
And the interrupt will be updating the 7 segment display displaying the temp.

The timer cannot interrupt the coms routine so I need to pause/stop it, but as soon as it's done I need to refresh the display
 
The only part that is time crucial with OW routines are the writebit and readbit. So just clear the GIE bit during these routines.

Here's where I would do it in my C code.
Code:
void OwWriteBit(bit data){
    *Tris&=~Mask;           //pull bus low
    [COLOR="red"]//disable here[/COLOR] 
    delay_us(4);            //for 4us if a one
    if(data==0)
        delay_us(56);       //or 60uS is a zero
    *Tris|=Mask;            //release bus
    delay_us(4);
    if(data==1)
        delay_us(56);       //complete time slot
    [COLOR="red"]//enable here[/COLOR] 
}



Mike.
 
Mike, I have no idea how to how to program or read C.
But I know exactly what you mean.

As long as if the overflow occurs while GIE is disabled, the interrupt is triggered when GIE re-enabled.

Many thanks.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top