free running counter question.

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

free running counter question.

Jump to solution
1,095 Views
unclemike
Contributor III

I am trying to use the free running counter component, but I can't get it working right.  I am trying to get an interrupt every 1 msec.  The component sets to counter for a 3.277 msec. period and sets the compare register to 0x4e1b.  it takes the counter 1 msec. to go from 0 to 0x4e1b, but nothing changes the compare register,   So I get a compare interrupt when the counter equals 0x4e1b, which is every 3.277 msec, the same as the overflow period.  Is anybody else having this problem?

 

Thanks

Mike

Labels (1)
0 Kudos
1 Solution
657 Views
unclemike
Contributor III

Hi All:

I have found a workaround.  If you add the following to FC1_OnInterrupt() you will get a 1 msec. interrupt.

static word CompTime = 0;
TPM1C0V = (FC1_TTimerValue)(CompTime);
CompTime += 0x4e1b;

Carlos, I have used the free running counter many times with no problems.  Don't know what happened here.

Thanks to those that tried to help.

Michael

View solution in original post

0 Kudos
4 Replies
657 Views
lunminliang
NXP Employee
NXP Employee

May I ask what's the target part number regarding this?

0 Kudos
657 Views
unclemike
Contributor III

Hi Lun Min Liang.  the MCU is a MC9S08AC16.  The internal bus clock is set to 19.995 MHz.

Thanks,

Mike

0 Kudos
657 Views
Carlos_Mendoza
NXP Employee
NXP Employee

Hi Michael,

As you mention, only the first interrupt happens after 1 ms because that is the time it takes the counter to go from 0x0000 to 0x4E1B, after this the next interrupts will happen every 3.27ms, this is because that is the time it takes the TPM to count from 0x4E1B to 0xFFFF and then from 0x0000 to 0x4E1B again:

1/19995000 (bus clock) = 5.001e-8

5.001e-8 * 65535 (0xFFFF) = 3.2777ms

If you want to generate an interrupt every 1 ms I would recommend you to use the Timer interrupt component instead of the free counter component.

I can upload an example that uses the Timer interrupt to generate an interrupt every 1 ms for your reference, just let me know the CodeWarrior version you are using.

Best regards!

Carlos Mendoza

0 Kudos
658 Views
unclemike
Contributor III

Hi All:

I have found a workaround.  If you add the following to FC1_OnInterrupt() you will get a 1 msec. interrupt.

static word CompTime = 0;
TPM1C0V = (FC1_TTimerValue)(CompTime);
CompTime += 0x4e1b;

Carlos, I have used the free running counter many times with no problems.  Don't know what happened here.

Thanks to those that tried to help.

Michael

0 Kudos