stuck in the while(One_ms_tick>0) instruction

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

stuck in the while(One_ms_tick>0) instruction

527件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by PoolCop on Thu Jan 30 11:27:45 MST 2014
Hi guys,

I'm using timer0 IRQ handler to build delay.
I use a global static integer called "One_ms_tick" which is preset when entering the Delay_ms routine.
Then Delay_ms routine is waiting for "One_ms_tick" to be back to zero in a while statment.
Timer0 IRQ handler is in charge to decrease "One_ms_tick" every milli-seconds until zero.

As shown is the attached pict, even if "One_ms_tick" is decreased back to zero (I can see the value decreasing in debug mode), the Delay_ms routine stays stuck in the while instruction.

Any clue ?

Thanks
René

0 件の賞賛
返信
4 返答(返信)

520件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Sat Feb 01 17:49:28 MST 2014

Quote: PoolCop
Adding some dumy statement such as writing something on the UART port makes the routine to work ????
Can not understand ....
Anyone has an idea ?


This probably due to the compiler making optimizations.  Like LabRat said Post your code.

Also are you sure that you have One_ms_tick as a global variable declared as
volatile int One_ms_tick;
?

Actually, to be more consistent with what you are using in the function Delay_ms(unsigned int count) I would declare it as
volatile unsigned int One_ms_tick;


either way One_ms_tick must be global and "volatile".
0 件の賞賛
返信

520件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Sat Feb 01 11:58:20 MST 2014

Quote: PoolCop
Anyone has an idea ?



Just a crazy idea: post this astonishing project ???
0 件の賞賛
返信

520件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by PoolCop on Sat Feb 01 11:18:27 MST 2014
Thanks Capiman, but this has no effect...

Adding some dumy statement such as writing something on the UART port makes the routine to work ????
Can not understand ....
Anyone has an idea ?
0 件の賞賛
返信

520件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Thu Jan 30 11:32:03 MST 2014
Have you used "volatile" for your global variable?
0 件の賞賛
返信