Counting pulses over a certain time period
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-11-30 8:00 AM
Hi,
I am using STM32F1 and want to count the number of times a digital input is high, over a period of 5 seconds. Can anyone please help me with this query? Thanks in advance.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-11-30 8:53 AM
You'd want to pick a timer, and external pins for either CH1 or CH2, and configure the timer in external counter mode. Set the timebase up for maximal mode, and then use another timer to handle the 5 second periodicity you need.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-12-03 2:37 AM
Thanks a lot clive1 for replying. Can you please tell me what you mean by time base in maximal mode? Can you give me an example code of how to count over a 5 second period?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-12-03 4:18 AM
It means that the timer/counter are set to count to there maximum count, be it 16-bit or 32-bit.
The timer is configured to count on ''External Counter'' mode, I've posted dozen of examples to the forum, please use Search/Google. First hit for ''STM32 External Count Mode'' On the first page, an App Note for timershttp://www.st.com/web/en/resource/technical/document/application_note/DM000425pdf
Configure another timer to interrupt/sample on a 5 second period, and delta the starting and ending counts to see the count over the period. I'm not looking to do your homework/job here.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-12-06 4:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-12-10 12:19 PM
Hi clive,
I configured timer2 and interupts to count over a 5 second period. Even though I am able to count with the interrupts, I am not being able to reset the count after 5 second period. I am also not sure if I have got the period and prescaler values right. Can you please take a look and let me know? Thanks in advance. /* Configure the basic Timer TIM2 */ TIM_TimeBaseStructure.TIM_Period = 5000; // Timer overflow value (overflow after 5s) TIM_TimeBaseStructure.TIM_Prescaler = 36000 - 1; // TIMClk/36000= 36MHz/36000= 1kHz TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_Cmd(TIM2, ENABLE);