Timer program for 1us and 1 ms
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-11-26 6:54 AM
Posted on November 26, 2014 at 15:54
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 #timer
This discussion is locked. Please start a new topic to ask your question.
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-11-26 7:25 AM
Posted on November 26, 2014 at 16:25 And? What the problem? Just declare global variable and increment it every 1 us in interrupt. So there is System timer. Or I did'nt understand you?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-11-26 7:41 AM
Posted on November 26, 2014 at 16:41 Thanks brother, i really don't know how to configure timer as a 1us or 1ms delay. I am using coocox , there are few sample programs and that programs are PWM configuration. Those programs are confusing me. i need sample program for timer based interrupt program.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-11-26 8:00 AM
Posted on November 26, 2014 at 17:00
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-11-26 8:27 AM
Posted on November 26, 2014 at 17:27
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
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
