2011-11-15 05:39 AM
I programmed the systick timer in order to get 1ms delay but I seem to get a 10us delay instead.
From the reference manual RM0008''The SysTick calibration value is set to 9000, which gives a reference time base of 1 ms with the SysTick clock set to 9 MHz (max HCLK/8).''I configured the system clock at 72Mhz and the AHB prescaler at 1. The clock source of the systick is also set to 1, thus clock core. Although I don't understand what it means by ''external reference clock''. I loaded up 9000 into the systick reload value.I wrote this simple routine to get a delaystatic uint32_t gCounter = 0;void sys_tick_timer(){ if (gCounter) gCounter--;}static void delayms(uint32_t millisecond){ gCounter = millisecond; while (gCounter > 0);}but the interrupt seems to be fired much faster then 1ms. I have to load 100*1000 valueto get a delay of about 1 second.Any suggestions would be appreciated.S.2011-11-15 07:33 AM
There is an example under STM32F10x standard peripheral library: the systick programmed in order to get 1ms delay:
http://www.st.com/internet/mcu/product/221026.jsp2011-11-15 01:46 PM
Well SysTick certainly should work, without seeing exactly how you're setting it, and building the project, I can't see an obvious reason why it would be so fast.
One thing you definitely want to do is have the counter stored in a volatile, not a static, otherwise the delay loop might compile into something unusable.2011-11-16 02:18 AM
I totally missed the volatile keyword there. Thanks for pointing it out.
The systick is simply enabled by placing 9000 into the reload register value (that's also what is into the calibration register) and enabling the timer by writing 3 to the control status register, as follow*gkSysTickReloadValue = (*gkSysTickCalibrationValue & 0x00FFFFFF); *gkSysTickControlStatus |= 0x03;The clock of the system is at 72mhz and the AHB prescaler is at 1. Clock should then divided by 8. I checked and the values are correctly written.2011-11-16 12:48 PM
The reload counter was incorrectly set.
Those were uint8_t* pointers and I forgot to cast them.Thanks for the help.