free running counter question.

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

free running counter question.

ソリューションへジャンプ
2,280件の閲覧回数
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

ラベル(1)
0 件の賞賛
返信
1 解決策
1,842件の閲覧回数
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 件の賞賛
返信
4 返答(返信)
1,842件の閲覧回数
lunminliang
NXP Employee
NXP Employee

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

0 件の賞賛
返信
1,842件の閲覧回数
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 件の賞賛
返信
1,842件の閲覧回数
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 件の賞賛
返信
1,843件の閲覧回数
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 件の賞賛
返信