Processor Expert, FreeCntr(s) and TimerOverflow

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Processor Expert, FreeCntr(s) and TimerOverflow

Jump to solution
2,100 Views
robertp
Contributor II

I have a project using CW IDE 5.7.0 and PE v2.98, I'm developing on an MC9S12C64 @ 32Mhz (timer is running at 1Mhz, 1uSec per tick)

 

I have been working fine using FreeCntr and TimerInt beans.  All of my time beans operate in free run mode (do NOT reset on compare).  

 

Now I want (need) to start counting timer overflows.  I have some calculations that are triggered by an external interrupt and use the TCNT value and it is possible in some cases that I can have MORE than 65ms pass between the external interrupts.  So I now want to process the overflow as an interrupt and simply count the number of overflows between my two external triggers.  See explanation below.

 

The problem is that there does not seem to be, in any of the FreeCntr or TimerInt beans a way to specify an overflow handler.  I DID find the low level Init_TIM bean - however, when I add it, I get conflicts with my current counter beans, even though the way I'm using the timer beans does NOT conflict (and I have no TIMER modules enabled in the Init_TIM bean).  ALL I WANT TO DO IS ADD AN OVERFLOW INTERRUPT HANDLER and ENABLE OVERFLOW INTERRUPTS.

 

I really don't want to throw away all my FreeCntr and TimerInt beans and start from scratch with the Init_TIM bean.  Not only does that mean rewriting code, but I also loose the higher level access functions (e.g. GetCounterValue).  I can still do all the stuff, but with the Init_TIM bean I have to do ALL of the stuff.

 

Bottom line - if I am using FreeCntr and TimerInt beans, is there ANY WAY to add a timer overflow handler.

 

Here is the reason I need this: 

 

I have an external item that causes an interrupt, then based on internal calculations, using the FreeCntr, I have to create pulses relative to the interrupts.  At some times, the time between the external interrupts can be greater than 65535uSec so I need to count the overflows, then add the difference between the original counter value and the current.  At the same time, I use the TCNT value, plus some calculations to setup an OutputCompare on the timer so I can trigger the start, or end of a pulse.

 

             pulse

            |-----|

   trig1   |      |   ovfl1                                 ovfl2         trig2

----|-----------------|--------------------------------|-------------|

 

 

In this case, I would store TCNT at trig1.  At trig2, I get the time and I need to check if any overflows have occurred...

 

For just one overflow, elapsed time is (65535 - trig1) + trig2 

for each additional overflow, I must add a multiple of 65535, in this example the multiplier is 1.

 

HELP PLEASE 

Labels (1)
Tags (1)
0 Kudos
1 Solution
624 Views
robertp
Contributor II

The answer was actually answered in response to my other question:

http://forums.freescale.com/freescale/board/message?board.id=CW816COMM&thread.id=5651

 

FAQ-27742

http://www.freescale.com/webapp/sps/utils/SingleFaq.jsp?FAQ-27742.xml

 

I simply create an ISR bean for the overflow and mark it as used per the instructions in the FAQ 

View solution in original post

0 Kudos
4 Replies
624 Views
kef
Specialist I

I can't help you with PE, but regarding measuring long time periods, algorithm is not as simple as you describe. The problem is, overflow ISR can occur close to IC event, maybe before you service IC event, maybe bit later. I highly recommend you to read M68HC11 Reference Manual section 10.5.5. Measuring long time periods with overflow and input capture interrupts. Unfortunately this document seems to be not available at FSL site already, but fortunately it is still available here:

 

http://www.engr.usask.ca/classes/EE/331/design/m68hc11rm.pdf

 

 

Also, free running timer counter overflows each 65536 timer counts, not each 65535.

0 Kudos
624 Views
robertp
Contributor II

Thank you for the response. I appreciate the document reference and will certainly review it to make sure I didn't miss something in my algorithm.  

 

The question was focused on the PE, I only gave the algorithm so I didn't get a "well, you're using the wrong bean" type of response.  As such, I didn't give the full details of the algorithm, just the rough outline.  Yep, you're correct about the 65536, thanks for catching that. 

0 Kudos
625 Views
robertp
Contributor II

The answer was actually answered in response to my other question:

http://forums.freescale.com/freescale/board/message?board.id=CW816COMM&thread.id=5651

 

FAQ-27742

http://www.freescale.com/webapp/sps/utils/SingleFaq.jsp?FAQ-27742.xml

 

I simply create an ISR bean for the overflow and mark it as used per the instructions in the FAQ 

0 Kudos
624 Views
ProcessorExpert
Senior Contributor III

 

Hello,

 

regarding to your request to an overflow interupt handler - there is possible to use OnInterrupt event of FreeCntr bean invoked at each overflow.

 

Use the folllowing steps:
- select the "TIMfree" device in "Device" property in FreeCntr bean.
- Enable "Interrupt  service/event" property
- Select value of "Period" property
- Enable OnInterrupt event on Events tab

best regards
Vojtech Filip
Processor Expert Support Team

 

0 Kudos