Interrupt Prorites ???

For Formula Flowcode Micromouse users to discuss projects, flowcharts, and any other issues related to the Formula Flowcode Micromouse.

Moderator: Benj

Post Reply
A_Smith
Posts: 7
Joined: Tue Oct 26, 2010 4:59 pm
Contact:

Interrupt Prorites ???

Post by A_Smith »

Hi

Does anyone know how to prioritise TMRO over TMR1 or TMR2 in flowcode 4. I am using the TMR0 interrupt for a real time clock and using TMR2 for pulse width modulating LED's. The problem is that when TMR2 is enabled, my program runs really slow and looses time. For obvious reasons the RTC is more important than the PWM and TMR2 is interrupting at a far higher frequency so is more likely to cope with being second in the quewe.

Any help would be greatly appreciated.

Cheers

Andy

Matrix multimedia, I have posted here as I still have no access to the V4 forum even though I have registered. Any ideas why?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Interrupt Prorites ???

Post by medelec35 »

Hello A_Smith.
Are there any component macros including delays, LCD's etc within TMR2 interrupt macro routines? If so that will affect timer0
If not I would guess if TMR2 is set at the higher interrupt frequency, each time it's fired, then all other interrupts would be disabled, so count variable within TMR0 is on hold each time.
Hence seconds would be out.
How about only using timer0 for all functions.
You can have more than one variables incremented on each tick of timer0.
So when each variable has reached its particular value then LED can be enabled for a set time.
Or you can use just the one variable. If you assign to a 10bit integer, this one variable can be used for counting seconds and LED on/off times. The prescaler rate an be selected to give enough ticks for seconds and led timings, so long as variable for seconds count is greater than LED on count.

E.G
count = count+1
if count>300
LED1 on
if count>400
LED2 on
if count >550
seconds = seconds + 1
etc.
Martin

A_Smith
Posts: 7
Joined: Tue Oct 26, 2010 4:59 pm
Contact:

Re: Interrupt Prorites ???

Post by A_Smith »

Hi Medelec,

Thanks for the response, there are no components in TMR2. I have tried using TMR1 to control both the RTC and LEDs but the frequency of TMR1 is not high enough (24000Hz/100=240Hz) to modulate the LED's whilst using a count of 100 to give a duty variable between 0 and 100.

I have also tried using TMR2 to control the RTC and PWM and although TMR2 has a frequency of 64000Hz (highest round number an integer can count) there is too much going off in the Interrupt count macro so this still loses time. This is because I am modulating multiple channels (More than the two PWM components available) of LED's and each has calculations, decisions and obviously switching of the outputs. This also slows my main program to a crawl.

I have also tried just using either interrupt to change a variable between 1 and 0 and then outside of the interrupt count macro, looking for the 1 or 0 and using this to turn on or off the LED's. The RTC then seems to work ok but the LED's aren't modulating, just switching on and off at random.

Am I on the right lines or am I missing something? As mentioned, before, I have no programming experience so I may be going about this completely the wrong way.

Cheers

Andy

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Interrupt Prorites ???

Post by medelec35 »

Other people may have the answer on the priority side.
You can use timer0 for the whole lot, since you can achieve high frequencies from it.
The max frequency can be increased even further by using a C code box with a value assigned to tmr0 (or tmr0l depending on target device). This will start the timer at a value other than 0, so it finishes quicker.
If you don’t mind posting flowchart of what you have done so far, I can see if I can get it to work any better.
Martin

A_Smith
Posts: 7
Joined: Tue Oct 26, 2010 4:59 pm
Contact:

Re: Interrupt Prorites ???

Post by A_Smith »

Hi

I have managed to get it working by making both interrupts the same frequency. I don't know why but it works.

I now have a new problem, initially I was using an integer to count absolute time (24 hours x 60 minutes x 60 seconds) but then came across problems which I realised are due to the maximum integer not being high enough. I have read some other threads on 32 bit integers don't understand them enough to apply this. I have tried changing the absolute time count to a floating point but I am now getting warning messages about ROM, RAM and call stack when compiling to chip.

Is there a simple way to use 32 bit integers as I have some quite complex code and although the chip might cope with using multiple variables for single values, my brain can't.

Cheers

Andy

Post Reply