2014-11-26 06:54 AM
Hi All,
I am having stm32f4discovery board with stm32f407vg processor and i am new to stm32f4 & also embedded programming. i tried delay using normal delay loop function calling method but i need to check timer interrupt for every 1us and also time delay for 1ms using timer. Can anyone help me to provide sample code for 1us delay using timer. #stm32f4-timer-interrupt #timer2014-11-26 07:25 AM
2014-11-26 07:41 AM
2014-11-26 08:00 AM
For C laguage something like:
uint32_t timeCounter = 0;
int
main (
void
)
{
uint32_t previousTime;
// ...
if
( (timeCounter - previousTime) < x) {
// do what you want
}
previousTime = timeCount;
///
}
void
isrTimer(
void
)
{
//... your code if need
counter++;
}
Or
colored
2014-11-26 08:27 AM
Interrupting at 1 us (1MHz) is a fools errand.
For 1 ms consider looking at the SysTick examples in the firmware library. If you want a timer to tick at 1MHz, you'd set the prescaler to (SystemCoreClock / 1000000)-1, for APB2 based timers. With a period of 1000 ticks at 1 MHz, you'd have an update interrupt at 1 ms [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Delay%20with%20timers%20on%20stm32F107&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=71]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FDelay%20with%20timers%20on%20stm32F107&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=71 [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F4%20Delay&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=46]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSTM32F4%20Delay&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=46