ST ARM Hardware Timers - Examples
Moderator: Benj
-
- Posts: 111
- Joined: Wed Mar 02, 2016 11:26 am
- Has thanked: 43 times
- Been thanked: 22 times
- Contact:
ST ARM Hardware Timers - Examples
Timers are essential hardware parts of STM32 .
Feature request: A couple of simple examples:
One example that uses ex. TIM1 to count external pulses on a pin
One example that uses ex. TIM2 to count internal clock of 10 us
How to read TIM1 and TIM2 in a programmed loop and how to reset them.
These two chips and development boards seem to have the best support in the present release of Flowcode 7
(at least what I have found ). Just a couple of suggestions
1. NUCLEO-F746ZG is a powerful and cheap board with all 144 pins accessable.
The chip STM32F746ZG has datasheet here http://www.st.com/resource/en/datasheet/stm32f746zg.pdf
2. STM32F407VGT6 Runs on this board
https://shop.mikroe.com/development-boa ... -pro-stm32
When searching I found relevant info here
http://www.stm32duino.com/viewtopic.php?t=1153
http://www.st.com/resource/en/applicati ... 236305.pdf
http://www.programering.com/a/MTM1kTMwATY.html
http://www.k-space.org/Class_Info/STM32_Lec5.pdf
Looking forward to comments and examples that makes it real easy to use Counters / Timers in STM32 !
Feature request: A couple of simple examples:
One example that uses ex. TIM1 to count external pulses on a pin
One example that uses ex. TIM2 to count internal clock of 10 us
How to read TIM1 and TIM2 in a programmed loop and how to reset them.
These two chips and development boards seem to have the best support in the present release of Flowcode 7
(at least what I have found ). Just a couple of suggestions
1. NUCLEO-F746ZG is a powerful and cheap board with all 144 pins accessable.
The chip STM32F746ZG has datasheet here http://www.st.com/resource/en/datasheet/stm32f746zg.pdf
2. STM32F407VGT6 Runs on this board
https://shop.mikroe.com/development-boa ... -pro-stm32
When searching I found relevant info here
http://www.stm32duino.com/viewtopic.php?t=1153
http://www.st.com/resource/en/applicati ... 236305.pdf
http://www.programering.com/a/MTM1kTMwATY.html
http://www.k-space.org/Class_Info/STM32_Lec5.pdf
Looking forward to comments and examples that makes it real easy to use Counters / Timers in STM32 !
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: ST ARM Hardware Timers - Examples
Hi,
I've attached a quick (and not so tidy) example of setting an internal interrupt timer and an external input counter.
It uses the STM32F469 Discovery kit.
The timer uses the Flowcode interrupt icon, although the period calculations need some work from us to get these correct, so you will need to trial and error the values yourself for now.
The counter is done with some C code, using TIMER3 and input TIM3 CH2 on pin PA7.
Hope it helps and gets you started.
Leigh
I've attached a quick (and not so tidy) example of setting an internal interrupt timer and an external input counter.
It uses the STM32F469 Discovery kit.
The timer uses the Flowcode interrupt icon, although the period calculations need some work from us to get these correct, so you will need to trial and error the values yourself for now.
The counter is done with some C code, using TIMER3 and input TIM3 CH2 on pin PA7.
Hope it helps and gets you started.
Leigh
- Attachments
-
- F469 Disco counter display.fcfx
- (18.44 KiB) Downloaded 489 times
-
- Posts: 111
- Joined: Wed Mar 02, 2016 11:26 am
- Has thanked: 43 times
- Been thanked: 22 times
- Contact:
Re: ST ARM Hardware Timers - Examples
Thanks - this will be interesting !
Unfortunately I don't have F469
But I have F769 at home
Maybe they are more or less compatible
What do you think ?
Best regards
BO
Unfortunately I don't have F469
But I have F769 at home
Maybe they are more or less compatible
What do you think ?
Best regards
BO
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: ST ARM Hardware Timers - Examples
Have a look at the examples, they show what needs to be done, and see if you can make adjustments for your target.
The timer interrupt icon and properties are similar across all STM32 targets.
The timer counter (C) code should be the same also, you might just need to change timer number and input port pin,
depending upon which pins you have available.
See how it goes and come back if you need any more help.
The timer interrupt icon and properties are similar across all STM32 targets.
The timer counter (C) code should be the same also, you might just need to change timer number and input port pin,
depending upon which pins you have available.
See how it goes and come back if you need any more help.
-
- Posts: 111
- Joined: Wed Mar 02, 2016 11:26 am
- Has thanked: 43 times
- Been thanked: 22 times
- Contact:
Re: ST ARM Hardware Timers - Examples
Hi
The F769 didn't work so I have ordered F469
Getting functionality directly would be a great starting point,
Quite an other question:
Is there an example where you have
graphics , UART (and internet ?? )
running simultaneously
on any of the discovery kits ?
This would also be very valuable as a starting point
STM32F429 Discovery kit
STM32F746G Discovery kit
STM32F469-Discovery-kit
STM32F769-Discovery-kit
The F769 didn't work so I have ordered F469
Getting functionality directly would be a great starting point,
Quite an other question:
Is there an example where you have
graphics , UART (and internet ?? )
running simultaneously
on any of the discovery kits ?
This would also be very valuable as a starting point
STM32F429 Discovery kit
STM32F746G Discovery kit
STM32F469-Discovery-kit
STM32F769-Discovery-kit
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: ST ARM Hardware Timers - Examples
I don't think we support the ethernet ports yet but this would be a great feature for the future.
As for the GLCD and UART these should work fine as long as there is a suitable GLCD component in the list.
As for the GLCD and UART these should work fine as long as there is a suitable GLCD component in the list.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 111
- Joined: Wed Mar 02, 2016 11:26 am
- Has thanked: 43 times
- Been thanked: 22 times
- Contact:
Re: ST ARM Hardware Timers - Examples
Thanks, this works
But I am getting short of digital outputs with F469.
16 dig oututs are needed.
Question:
1. Is this below a good approach or is there a far better way of doing it ?
2. Is it possible to write a macro Write_Dig_Out ( 15, 1 ) -> example output 15 is set log 1
My idea would be to add 2 x 74HCT259E
A 3 bit address
and a 1 bit Data bit goes to both 74HCT259E
Two Enable, one to each 74HCT259E
When Enable goes low data is transferred to a specified output,
all other outputs stay unchanged.
Then I need 6 pins to address 16 digital outputs
This would solve the pin shortage
The 74HCT259E can also take the 3.3V to 5V to drive darlington valve drivers
But I am getting short of digital outputs with F469.
16 dig oututs are needed.
Question:
1. Is this below a good approach or is there a far better way of doing it ?
2. Is it possible to write a macro Write_Dig_Out ( 15, 1 ) -> example output 15 is set log 1
My idea would be to add 2 x 74HCT259E
A 3 bit address
and a 1 bit Data bit goes to both 74HCT259E
Two Enable, one to each 74HCT259E
When Enable goes low data is transferred to a specified output,
all other outputs stay unchanged.
Then I need 6 pins to address 16 digital outputs
This would solve the pin shortage
The 74HCT259E can also take the 3.3V to 5V to drive darlington valve drivers
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: ST ARM Hardware Timers - Examples
Hello,
This certainly sounds like it should work and be fairly simple though you would have to keep track of the current outputs in your macros using variables. I use chips like this to drive the numerous output channels on my LED cube.
Another way which is probably a bit more expensive but also a bit easier to work with and supports input and output is to use an dedicated I/O expander IC such as the MCP23017.
This certainly sounds like it should work and be fairly simple though you would have to keep track of the current outputs in your macros using variables. I use chips like this to drive the numerous output channels on my LED cube.
Another way which is probably a bit more expensive but also a bit easier to work with and supports input and output is to use an dedicated I/O expander IC such as the MCP23017.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 111
- Joined: Wed Mar 02, 2016 11:26 am
- Has thanked: 43 times
- Been thanked: 22 times
- Contact:
Re: ST ARM Hardware Timers - Examples
Back to the original question
One example that uses ex. TIMx to count external pulses on a pin
One example that uses ex. TIMy to count internal clock of 10 us
How to read TIMx and TIMy in a programmed loop and how to reset them ?
I understand that the F469 Disco counter display.fcfx does exactly this, and menu and some counts can be seen .
Questions
It seems that TIM2 and TIM3 are used
Which of them is used to count external pulses, what pin is used as count up input, and how is the counter addressed and read in the code ?
Which of them is used to count internal clock, which is the input frequency, and how is the counter addressed and read in the code ?
What pin is used as external reset for both counters ?
It seems that the ZeroCounter Macro resets TIM3 with TIM3->CNT = 0;
It is my guess that the external pulses go to TIM3 and that they are read with this line of code
FCL_TEMP = TIM3->CNT
It seems that the time counter only uses tick=tick+1;
and is read by .temp = tick / 1000
Will this be an accurate timebase ?
The sample is much about the GLCD, but it seems that PrintCounter() and PrintTick() might refer to reading the two counters.
It would be great to have additional info that allows me to apply an external count up signal and read it on display, and
to read the elapsed time from the reset pulse.
Is the reset supported by an interrupt in this example or is it not needed?
Thanks & Best regards
One example that uses ex. TIMx to count external pulses on a pin
One example that uses ex. TIMy to count internal clock of 10 us
How to read TIMx and TIMy in a programmed loop and how to reset them ?
I understand that the F469 Disco counter display.fcfx does exactly this, and menu and some counts can be seen .
Questions
It seems that TIM2 and TIM3 are used
Which of them is used to count external pulses, what pin is used as count up input, and how is the counter addressed and read in the code ?
Which of them is used to count internal clock, which is the input frequency, and how is the counter addressed and read in the code ?
What pin is used as external reset for both counters ?
It seems that the ZeroCounter Macro resets TIM3 with TIM3->CNT = 0;
It is my guess that the external pulses go to TIM3 and that they are read with this line of code
FCL_TEMP = TIM3->CNT
It seems that the time counter only uses tick=tick+1;
and is read by .temp = tick / 1000
Will this be an accurate timebase ?
The sample is much about the GLCD, but it seems that PrintCounter() and PrintTick() might refer to reading the two counters.
It would be great to have additional info that allows me to apply an external count up signal and read it on display, and
to read the elapsed time from the reset pulse.
Is the reset supported by an interrupt in this example or is it not needed?
Thanks & Best regards
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: ST ARM Hardware Timers - Examples
The C code in Main() sets up TIM3 to count pulses on port A pin 7.Which of them is used to count external pulses, what pin is used as count up input, and how is the counter addressed and read in the code ?
PrintCounter() uses C code to get the counter value into a Flowcode variable called temp ...
Code: Select all
FCL_TEMP = TIM3->CNT;
As you noticed, the actual counter can be reset with the C code ...
Code: Select all
TIM3->CNT = 0;
The Interrupt icon in Main() sets up TMR2 to interrupt regularly and call TimerInt().Which of them is used to count internal clock, which is the input frequency, and how is the counter addressed and read in the code ?
TimerInt() increments a Flowcode global variable named tick.
You will need to set and check the properties yourself to get the correct interrupt frequency that you desire.
You could use the tick variable to count elapsed time, reset it to zero and also display its value whenever you want in your program.
-
- Posts: 111
- Joined: Wed Mar 02, 2016 11:26 am
- Has thanked: 43 times
- Been thanked: 22 times
- Contact:
Re: ST ARM Hardware Timers - Examples
Regarding INT Single Pin Interrupt with ARM
Hi
As you indicated the TIM3 can be reset with
TIM3->CNT = 0;
The reset pulse is external and in my case very short.
I have tried to use pin A6 to start an interrupt that calls a macro
doing just this
TIM3->CNT = 0;
I have been looking at the
INT Single Pin Interrupt example for PIC https://www.matrixtsl.com/wikiv7/index. ... Interrupts
but this example doesn't work with ARM
Could you give me a hint ?
Thanks and best regards
Hi
As you indicated the TIM3 can be reset with
TIM3->CNT = 0;
The reset pulse is external and in my case very short.
I have tried to use pin A6 to start an interrupt that calls a macro
doing just this
TIM3->CNT = 0;
I have been looking at the
INT Single Pin Interrupt example for PIC https://www.matrixtsl.com/wikiv7/index. ... Interrupts
but this example doesn't work with ARM
Could you give me a hint ?
Thanks and best regards
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: ST ARM Hardware Timers - Examples
Hi
Use an Interrupt icon to setup an External Interrupt
Here is an example of setting up EXTI0 which interrupts on Bit 0
And use the properties to select Port A
Use an Interrupt icon to setup an External Interrupt
Here is an example of setting up EXTI0 which interrupts on Bit 0
And use the properties to select Port A