Interupts

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
GJB
Posts: 11
Joined: Tue Jan 09, 2007 9:37 pm
Contact:

Interupts

Post by GJB »

Interrupts

I have a line of flow code symbols which are my opening code to the program, among other things they reset variables and memory to zero.

The penultimate call is to enable Timer0 which calls a service routine. The interrupt frequency is set to 19200 Hz.

The first thing I do in my interrupt service routine is to disable interrupts (TIM0), so as to avoid the routine being interrupted.

At the end of the interrupt service routine, I re-enable TIM0.

In the opening code which first enabled TIM0, I have an input routine placed after the TIM0 enable statement. This input routine never gets called.

At first thought that the interrupt frequency was so fast that as soon as my interrupt service routine re-enabled TIM0, it was recalled. So I moved the re-enable TIM0 statement to a position after my input routine call.

But it still never gets called, so I am beginning to think that interrupts do not have pointers which inform them where to return to ? Or I am not resetting a flag somewhere.

Is it possible to find an explanation of what calls Flow Code actually makes when the user uses En-TIM0 and call this routine type statements?

I took a quick look at the microchip website and it spoke of PCLATH and Status, and not using paged memory locations, but without knowing how much of this is implemented by flow code, I don't know how to proceed.

Also, I have noticed that having produced code in which TIM0 successfully calls a working routine, simply enabling TIM1 stops all interrupts from firing.

Sorry to be a numpty
Geo

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello

please send me your code and I will take a look for you.

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

Do you specifically need to disable the timer interrupt while it is running? Ideally, interrupt routines should be executed as quickly as possible so that they do not impact the rest of the program.

For example, if you created a program that displayed the time on an LCD which had an interrupt routine called every 100ms, you should not put the actual time display code in the interrupt routine. The preferred approach would be for the interrupt routine to simply update some global "time" variables and for the main program loop to actually display the time periodically.

GJB
Posts: 11
Joined: Tue Jan 09, 2007 9:37 pm
Contact:

Post by GJB »

Hi Steve & Ben
firslty an appology for not responding, but I have been away for a number of weeks.

Secondly re Steve's point, I understood that all pros disable the interupt timer when servicing an interupt routine. It was explained to me that if the I-timer refired quicker than it takes to run the resulting routine, then the I-routine itself would be contantly interupted, is this not the case ?

In the program I wrote (and I will find and post it to you ben) when the timer fired and the interupt routine was called, I could not identify to which point the program returned once the interupt routine had completed.

Immediatley after the timer enable, I placed an input routine to read switch status, this routine was never called, which seemed to me to indicate that wherever the program pointer was taking it after running the I-routine, it was not the step following the timer enable call.

change of subject, can I post flow code here Ben, or do I mail it to you direct?
GJB

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello

Disabling the interrupt routine is a good idea if you are not bothered about the frequency of the TMR0 being precise. If you disable the interrupt the the value in the TMR0 gets overwritten when re enabling the interrupt.

The PICmicro returns to the point after the last instruction that was executed before the interrupt was triggered. Eg it carries on with what it was doing before the interrupt occurred.

If the timer interrupt routine is too large then it will always be interrupting and never actually manage to leave the interrupt routine.

You can mail me direct with programs. My email is ben@matrixmultimedia.co.uk

GJB
Posts: 11
Joined: Tue Jan 09, 2007 9:37 pm
Contact:

Post by GJB »

Yes, I think I now see what was going on.

In my code I had

instruction-x
timer enable
instruction-X+1

And so I think from your explination, timer enable would fire the Ir routine and the code pointer would point back to instruction-x and not x+1

so the point of return would be the timer enable and I think this fires immediatly on the first event?

Geo

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello

It depends on the interrupt frequency of TMR0.

If you set the prescalar to something like 1:256 then the interrupt will occur something like this.

instruction 1
timer enable
instruction 2
instruction 3
instruction 4
...
instruction 257
Interrupt service routine
instruction 258
instruction 259
...
instruction 513
Interrupt service routine
instruction 514
etc


If you have a very low prescalar then the following will occur

instruction 1
timer enable
Interrupt service routine
Interrupt service routine
Interrupt service routine
Interrupt service routine
Interrupt service routine
Interrupt service routine
Interrupt service routine
etc

Post Reply