Using TRM0 and TRM2 at the same time

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Using TRM0 and TRM2 at the same time

Post by Jan Lichtenbelt »

Hi All,

I use TRM0 and TRM2 at the same time. TRM0 at 19.2 kHZ and TRM2 at 76.8 KHz (this is 4x 19.2 kHz).

On the moment of enabling both timers I get curious results.

Can that be due to the fact that at a rate of 19.2 kHz both interrupt are called at the same time?

Kind regards

Jan

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times

Re: Using TRM0 and TRM2 at the same time

Post by Spanish_dude »

Hi Jan,

Even if both interrupt flags are set at the same time, only one will get executed.
I think they have different priority (high/low).

I think priority is only checked if it's enabled in some register, but i'm not quite sure...

Can you tell us more about those curious results ?

BR,

Nicolas

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Using TRM0 and TRM2 at the same time

Post by Jan Lichtenbelt »

Hi Nicolas,

Thanks for your response. That is true, there will be a priority if there are two interrupts at the same time.

The problem has been found. If you use interrupts, the first rule is to use as less as possible steps in the interrupt macro. But I found out that you have to take care of the rest of the program also.

I used the results of the interrupt to measure the pulse time and found that time measured for short pulses gave wrong (to high) results. I wanted the duty time permillage, which needs the following calculation duty= (time_on*100)/(total_time/10), with time_on (int) about 75 interrupts and total_time (int) about 1500 interrupts. But this rather simple integer calculation with 1 multiplication and 2 divisions takes already a lot of time. When I replaced the multiplication by a roll left and the divisions by a roll right, like:
duty = (time_on<<7)/(total_time>>3) the problems were solved, due to a much shorter program. The duty time units are now 0.1024% instead of 0.1%, which is no problem for me.

Is it known what the time is necessary for an integer multiplication and division (with 19...MHz crystal)?

With kind regards

Jan

Post Reply