Example description
6Steps
Example Description
This example shows how to configure the TIM1 peripheral to generate 6 Steps.
The STM32F10x TIM1 peripheral offers the possibility to program in advance the
configuration for the next TIM1 outputs behaviour (step) and change the configuration
of all the channels at the same time. This operation is possible when the COM
(commutation) event is used.
The COM event can be generated by software by setting the COM bit in the TIM1_EGR
register or by hardware (on TRC rising edge).
In this example, a software COM event is generated each 100 ms: using the SysTick
interrupt.
The TIM1 is configured in Timing Mode, each time a COM event occurs, a new TIM1
configuration will be set in advance.
The break Polarity is used at High level.
The following Table describes the TIM1 Channels states:
-----------------------------------------------
| Step1 | Step2 | Step3 | Step4 | Step5 | Step6 |
----------------------------------------------------------
|Channel1 | 1 | 0 | 0 | 0 | 0 | 1 |
----------------------------------------------------------
|Channel1N | 0 | 0 | 1 | 1 | 0 | 0 |
----------------------------------------------------------
|Channel2 | 0 | 0 | 0 | 1 | 1 | 0 |
----------------------------------------------------------
|Channel2N | 1 | 1 | 0 | 0 | 0 | 0 |
----------------------------------------------------------
|Channel3 | 0 | 1 | 1 | 0 | 0 | 0 |
----------------------------------------------------------
|Channel3N | 0 | 0 | 0 | 0 | 1 | 1 |
----------------------------------------------------------
Directory contents
- TIM/6Steps/stm32f10x_conf.h Library Configuration file
- TIM/6Steps/stm32f10x_it.c Interrupt handlers
- TIM/6Steps/stm32f10x_it.h Interrupt handlers header file
- TIM/6Steps/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect the TIM1 pins(TIM1 full remapped pins) to an oscilloscope to monitor the different waveforms:
- TIM1_CH3 pin (PE.13)
- TIM1_CH1N pin (PE.08)
- TIM1_CH2 pin (PE.11)
- TIM1_CH3N pin (PE.12)
- TIM1_CH1 pin (PE.09)
- TIM1_CH2N pin (PE.10)
- Connect the TIM1 break pin TIM1_BKIN pin (PE.15) to the GND. To generate a
break event, switch this pin level from 0V to 3.3V.
- STM3210E-EVAL and STM3210B-EVAL Set-up
- Connect the TIM1 pins to an oscilloscope to monitor the different waveforms:
- TIM1_CH3 pin (PA.10)
- TIM1_CH1N pin (PB.13)
- TIM1_CH2 pin (PA.09)
- TIM1_CH3N pin (PB.15)
- TIM1_CH1 pin (PA.08)
- TIM1_CH2N pin (PB.14)
- Connect the TIM1 break pin TIM1_BKIN pin (PB.12) to the GND. To generate a
break event, switch this pin level from 0V to 3.3V.
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- misc.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
7PWM_Output
Example Description
This example shows how to configure the TIM1 peripheral to generate 7 PWM signals
with 4 different duty cycles.
TIM1CLK is fixed to 72 MHz, the TIM1 Prescaler is equal to 0 so the TIM1 counter
clock used is 72 MHz.
TIM1 frequency is defined as follow:
TIM1 frequency = TIM1CLK/(TIM1_Period + 1) = 17.57 KHz.
The TIM1 CCR1 register value is equal to 0x7FF, so the TIM1 Channel 1 and TIM1
Channel 1N generate a PWM signal with a frequency equal to 17.57 KHz
and a duty cycle equal to:
TIM1 Channel1 duty cycle = TIM1_CCR1 /( TIM1_Period + 1) = 50%.
The TIM1 CCR2 register value is equal to 0x5FF, so the TIM1 Channel 2 and TIM1
Channel 2N generate a PWM signal with a frequency equal to 17.57 KHz
and a duty cycle equal to:
TIM1 Channel2 duty cycle = TIM1_CCR2 / ( TIM1_Period + 1)= 37.5%.
The TIM1 CCR3 register value is equal to 0x3FF, so the TIM1 Channel 3 and TIM1
Channel 3N generate a PWM signal with a frequency equal to 17.57 KHz
and a duty cycle equal to:
TIM1 Channel3 duty cycle = TIM1_CCR3 / ( TIM1_Period + 1) = 25%.
The TIM1 CCR4 register value is equal to 0x1FF, so the TIM1 Channel 4
generate a PWM signal with a frequency equal to 17.57 KHz
and a duty cycle equal to:
TIM1 Channel4 duty cycle = TIM1_CCR4 / ( TIM1_Period + 1) = 12.5%.
The TIM1 waveform can be displayed using an oscilloscope.
Directory contents
- TIM/7PWM_Output/stm32f10x_conf.h Library Configuration file
- TIM/7PWM_Output/stm32f10x_it.c Interrupt handlers
- TIM/7PWM_Output/stm32f10x_it.h Interrupt handlers header file
- TIM/7PWM_Output/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect the TIM1 pins(TIM1 full remapped pins) to an oscilloscope to monitor the different waveforms:
- TIM1_CH1 pin (PE.08)
- TIM1_CH1N pin (PE.09)
- TIM1_CH2 pin (PE.10)
- TIM1_CH2N pin (PE.11)
- TIM1_CH3 pin (PE.12)
- TIM1_CH3N pin (PE.13)
- TIM1_CH4 pin (PE.14)
- STM3210E-EVAL and STM3210B-EVAL Set-up
- Connect the TIM1 pins to an oscilloscope to monitor the different waveforms:
- TIM1_CH1 pin (PA.08)
- TIM1_CH1N pin (PB.13)
- TIM1_CH2 pin (PA.09)
- TIM1_CH2N pin (PB.14)
- TIM1_CH3 pin (PA.10)
- TIM1_CH3N pin (PB.15)
- TIM1_CH4 pin (PA.11)
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
Cascade_Synchro
Example Description
This example shows how to synchronize TIM peripherals in cascade mode.
In this example three timers are used:
Timers synchronisation in cascade mode:
1/TIM2 is configured as Master Timer:
- PWM Mode is used
- The TIM2 Update event is used as Trigger Output
2/TIM3 is slave for TIM2 and Master for TIM4,
- PWM Mode is used
- The ITR1(TIM2) is used as input trigger
- Gated mode is used, so start and stop of slave counter
are controlled by the Master trigger output signal(TIM2 update event).
- The TIM3 Update event is used as Trigger Output.
3/TIM4 is slave for TIM3,
- PWM Mode is used
- The ITR2(TIM3) is used as input trigger
- Gated mode is used, so start and stop of slave counter are controlled by the
Master trigger output signal(TIM3 update event).
The TIMxCLK is fixed to 72 MHz, the TIM2 counter clock is 72 MHz.
The Master Timer TIM2 is running at TIM2 frequency :
TIM2 frequency = (TIM2 counter clock)/ (TIM2 period + 1) = 281.250 KHz
and the duty cycle = TIM2_CCR1/(TIM2_ARR + 1) = 25%.
The TIM3 is running at:
(TIM2 frequency)/ (TIM3 period + 1) = 70.312 KHz and a duty cycle equal
to TIM3_CCR1/(TIM3_ARR + 1) = 25%
The TIM4 is running at:
(TIM3 frequency)/ (TIM4 period + 1) = 17.578 Hz and a duty cycle equal
to TIM4_CCR1/(TIM4_ARR + 1) = 25%
Directory contents
- TIM/Cascade_Synchro/stm32f10x_conf.h Library Configuration file
- TIM/Cascade_Synchro/stm32f10x_it.c Interrupt handlers
- TIM/Cascade_Synchro/stm32f10x_it.h Interrupt handlers header file
- TIM/Cascade_Synchro/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect the following pins to an oscilloscope to monitor the different
waveforms:
- TIM2 CH1 (PA.00)
- TIM3 CH1 (PC.06) Remapped pin
- TIM4 CH1 (PB.06)
- STM3210E-EVAL and STM3210B-EVAL Set-up
- Connect the following pins to an oscilloscope to monitor the different
waveforms:
- TIM2 CH1 (PA.00)
- TIM3 CH1 (PA.06)
- TIM4 CH1 (PB.06)
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_tim.c
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
ComplementarySignals
Example Description
This example shows how to configure the TIM1 peripheral to generate three
complementary TIM1 signals, to insert a defined dead time value, to use the break
feature and to lock the desired parameters.
TIM1CLK is fixed to 72 MHz, the TIM1 Prescaler is equal to 0 so the TIM1 counter
clock used is 72 MHz.
TIM1 frequency is defined as follow:
TIM1 frequency = TIM1 counter clock / (TIM1_Period + 1) = 1.098 KHz.
The Three Duty cycles are computed as the following description:
- TIM1 Channel1 duty cycle = TIM1_CCR1 / (TIM1_Period + 1) = 50%
- TIM1 Channel1N duty cycle = (TIM1_Period - TIM1_CCR1) / (TIM1_Period + 1) = 50%
- TIM1 Channel2 duty cycle = TIM1_CCR2 / (TIM1_Period + 1) = 25%
- TIM1 Channel2N duty cycle = (TIM1_Period - TIM1_CCR1) / (TIM1_Period + 1) = 75%
- TIM1 Channel3 duty cycle = TIM1_CCR3 / TIM1_Period = 12.5%
- TIM1 Channel3N duty cycle = (TIM1_Period - TIM1_CCR3) / (TIM1_Period + 1) = 87.5%
A dead time of 1.62 us is inserted between the different complementary signals,
and the Lock level 1 is selected.
The break Polarity is used at High level.
The TIM1 waveform can be displayed using an oscilloscope.
Directory contents
- TIM/ComplementarySignals/stm32f10x_conf.h Library Configuration file
- TIM/ComplementarySignals/stm32f10x_it.c Interrupt handlers
- TIM/ComplementarySignals/stm32f10x_it.h Interrupt handlers header file
- TIM/ComplementarySignals/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect the TIM1 pins(TIM1 full remapped pins) to an oscilloscope to monitor the different waveforms:
- TIM1_CH1 pin (PE.09)
- TIM1_CH1N pin (PE.08)
- TIM1_CH2 pin (PE.11)
- TIM1_CH1N pin (PE.10)
- TIM1_CH3 pin (PE.13)
- TIM1_CH3N pin (PE.12)
- Connect the TIM1 break pin TIM1_BKIN pin (PE.15) to the GND. To generate a
break event, switch this pin level from 0V to 3.3V.
- STM3210E-EVAL and STM3210B-EVAL Set-up
- Connect the TIM1 pins to an oscilloscope to monitor the different waveforms:
- TIM1_CH1 pin (PA.08)
- TIM1_CH1N pin (PB.13)
- TIM1_CH2 pin (PA.09)
- TIM1_CH2N pin (PB.14)
- TIM1_CH3 pin (PA.10)
- TIM1_CH3N pin (PB.15)
- Connect the TIM1 break pin TIM1_BKIN pin (PB.12) to the GND. To generate a
break event, switch this pin level from 0V to 3.3V.
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_tim.c
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
DMA
Example Description
This example provides a description of how to use DMA with TIM1 Update request
to transfer Data from memory to TIM1 Capture Compare Register3.
TIM1CLK = 72 MHz, Prescaler = 0, TIM1 counter clock = 72 MHz
The TIM1 Channel3 is configured to generate a complementary PWM signal with
a frequency equal to: TIM1 counter clock / (TIM1_Period + 1) = 17.57 KHz
The TIM1 Channel3 is configured to generate a complementary PWM signal with
a frequency equal to 17.578 KHz and a variable duty cycle that is changed
by the DMA after a specific number of Update event.
The number of this repetitive requests is defined by the TIM1 Repetion counter,
each 3 Update Requests, the TIM1 Channel3 Duty Cycle changes to the next new value
defined by the SRC_Buffer.
Directory contents
- TIM/DMA/stm32f10x_conf.h Library Configuration file
- TIM/DMA/stm32f10x_it.c Interrupt handlers
- TIM/DMA/stm32f10x_it.h Interrupt handlers header file
- TIM/DMA/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210E-EVAL, STM3210B-EVAL and STM3210C-EVAL Set-up
- Connect the following pins to an oscilloscope to monitor the different
waveforms:
- TIM1 CH3 (PA.10)
- TIM1 CH3N (PB.15)
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32F10x_dma.c
- stm32F10x_flash.c
- stm32F10x_gpio.c
- stm32F10x_rcc.c
- stm32F10x_tim.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
ExtTrigger_Synchro
Example Description
This example shows how to synchronize TIM peripherals in cascade mode with an
external trigger.
In this example three timers are used:
1/TIM1 is configured as Master Timer:
- Toggle Mode is used
- The TIM1 Enable event is used as Trigger Output
2/TIM1 is configured as Slave Timer for an external Trigger connected to TIM1 TI2 pin
(TIM1 CH2 configured as input pin):
- The TIM1 TI2FP2 is used as Trigger Input
- Rising edge is used to enable and stop the TIM1: Gated Mode.
3/TIM3 is slave for TIM1 and Master for TIM4,
- Toggle Mode is used
- The ITR1(TIM1) is used as input trigger
- Gated mode is used, so start and stop of slave counter are controlled by the Master
trigger output signal(TIM1 enable event).
- The TIM3 enable event is used as Trigger Output.
4/TIM4 is slave for TIM3,
- Toggle Mode is used
- The ITR2(TIM3) is used as input trigger
- Gated mode is used, so start and stop of slave counter are controlled by the Master
trigger output signal(TIM3 enable event).
The TIMxCLK is fixed to 72 MHZ, the Prescaler is equal to 2 so the TIMx clock counter
is equal to 24 MHz.
The Three Timers are running at:
TIMx frequency = TIMx clock counter/ 2*(TIMx_Period + 1) = 162.1 KHz.
The starts and stops of the TIM1 counter are controlled by the external trigger.
The TIM3 starts and stops are controlled by the TIM1, and the TIM4 starts and stops
are controlled by the TIM3.
Directory contents
- TIM/ExtTrigger_Synchro/stm32f10x_conf.h Library Configuration file
- TIM/ExtTrigger_Synchro/stm32f10x_it.c Interrupt handlers
- TIM/ExtTrigger_Synchro/stm32f10x_it.h Interrupt handlers header file
- TIM/ExtTrigger_Synchro/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect an external trigger, with a frequency <= 40KHz, to the TIM1 CH2
pin (PE.11). In this example the frequency is equal to 5 KHz.
- Connect the following pins to an oscilloscope to monitor the different waveforms:
- TIM1 CH1 (PE.09)
- TIM3 CH1 (PC.06)
- TIM4 CH1 (PB.06)
- STM3210E-EVAL and STM3210B-EVAL Set-up
- Connect an external trigger, with a frequency <= 40KHz, to the TIM1 CH2
pin (PA.09). In this example the frequency is equal to 5 KHz.
- Connect the following pins to an oscilloscope to monitor the different waveforms:
- TIM1 CH1 (PA.08)
- TIM3 CH1 (PA.06)
- TIM4 CH1 (PB.06)
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_tim.c
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
InputCapture
Example Description
This example shows how to use the TIM peripheral to measure the frequency of an external signal.
The TIMxCLK frequency is set to 72 MHz, the Prescaler is 0 so the TIM3 counter
clock is 72 MHz. so the minimum frequency value to measure is 1100 Hz.
TIM3 is configured in Input Capture Mode: the external signal is connected to
TIM3 Channel2 used as input pin.
To measure the frequency we use the TIM3 CC2 interrupt request,
so In the TIM3_IRQHandler routine, the frequency of the external signal is computed.
The "Frequency" variable contains the external signal frequency:
Frequency = TIM3 counter clock / CAPTURE in Hz,
where the CAPTURE is the difference between two consecutive TIM3 captures.
Directory contents
- TIM/InputCapture/stm32f10x_conf.h Library Configuration file
- TIM/InputCapture/stm32f10x_it.c Interrupt handlers
- TIM/InputCapture/stm32f10x_it.h Interrupt handlers header file
- TIM/InputCapture/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210E-EVAL, STM3210B-EVAL and STM3210C-EVAL Set-up
- Connect the external signal to measure to the TIM3 CH2 pin (PA.07).
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- misc.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
OCActive
Example Description
This example shows how to configure the TIM peripheral to generate four different
signals with four different delays.
The TIMxCLK frequency is set to 36 MHz, the Prescaler is set to 35999 and used in
Output Compare Active Mode.
TIM3 counter clock = TIMxCLK / (Prescaler +1) = 1 KHz
The TIM3 CCR1 register value is equal to 1000:
TIM3_CH1 delay = CCR1_Val/TIM3 counter clock = 1000 ms
so the TIM3 Channel 1 generates a signal with a delay equal to 1000 ms.
The TIM3 CCR2 register value is equal to 500:
TIM3_CH2 delay = CCR2_Val/TIM3 counter clock = 500 ms
so the TIM3 Channel 2 generates a signal with a delay equal to 500 ms.
The TIM3 CCR3 register value is equal to 250:
TIM3_CH3 delay = CCR3_Val/TIM3 counter clock = 250 ms
so the TIM3 Channel 3 generates a signal with a delay equal to 250 ms.
The TIM3 CCR4 register value is equal to 125:
TIM3_CH4 delay = CCR4_Val/TIM3 counter clock = 125 ms
so the TIM3 Channel 4 generates a signal with a delay equal to 125 ms.
The delay correspond to the time difference between PC.06 and
TIM3_CHx signal rising edges in case of STM3210E-EVAL and STM3210B-EVAL
The delay correspond to the time difference between PD.07 and
TIM3_CHx signal rising edges in case of STM3210C-EVAL
Directory contents
- TIM/OCActive/stm32f10x_conf.h Library Configuration file
- TIM/OCActive/stm32f10x_it.c Interrupt handlers
- TIM/OCActive/stm32f10x_it.h Interrupt handlers header file
- TIM/OCActive/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect the TIM3 pins(TIM3 full remapped pins) to an oscilloscope to monitor the different waveforms:
- PD.07
- PC.06 (TIM3_CH1)
- PC.07 (TIM3_CH2)
- PC.08 (TIM3_CH3)
- PC.09 (TIM3_CH4)
- STM3210E-EVAL and STM3210B-EVAL Set-up
- Connect the following pins to an oscilloscope to monitor the different
waveforms:
- PC.06
- PA.00 (TIM3_CH1)
- PA.01 (TIM3_CH2)
- PA.02 (TIM3_CH3)
- PA.03 (TIM3_CH4)
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_flash.c
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
OCInactive
Example Description
This example shows how to configure the TIM peripheral in Output Compare Inactive
mode with the corresponding Interrupt requests for each channel.
The TIMxCLK frequency is set to 36 MHz, the Prescaler is set to 35999 and used in
Output Compare Inactive Mode.
TIM2 counter clock = TIMxCLK / (Prescaler +1) = 1 KHz
The TIM2 CCR1 register value is equal to 1000:
TIM2_CC1 delay = CCR1_Val/TIM2 counter clock = 1000 ms
so the PC.06 is reset after a delay equal to 1000 ms.
The TIM2 CCR2 register value is equal to 500:
TIM2_CC2 delay = CCR2_Val/TIM2 counter clock = 500 ms
so the PC.07 is reset after a delay equal to 500 ms.
The TIM2 CCR3 register value is equal to 250:
TIM2_CC3 delay = CCR3_Val/TIM2 counter clock = 250 ms
so the PC.08 is reset after a delay equal to 250 ms.
The TIM2 CCR4 register value is equal to 125:
TIM2_CC4 delay = CCR4_Val/TIM2 counter clock = 125 ms
so the PC.09 is reset after a delay equal to 125 ms.
While the counter is lower than the Output compare registers values, which
determines the Output delay, the PC.06, PC.07, PC.08 and PC.09 pin are turned on.
When the counter value reaches the Output compare registers values, the Output
Compare interrupts are generated and, in the handler routine, these pins are turned off.
Directory contents
- TIM/OCInactive/stm32f10x_conf.h Library Configuration file
- TIM/OCInactive/stm32f10x_it.c Interrupt handlers
- TIM/OCInactive/stm32f10x_it.h Interrupt handlers header file
- TIM/OCInactive/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210E-EVAL, STM3210B-EVAL and STM3210C-EVAL Set-up
- Connect the following pins to an oscilloscope to monitor the different
waveforms:
- PC.06
- PC.07
- PC.08
- PC.09
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_flash.c
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- misc.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
OCToggle
Example Description
This example shows how to configure the TIM3 peripheral to generate four different
signals with four different frequencies.
The TIM3CLK frequency is set to 36 MHz, the Prescaler is set to 2, and used in
Output Compare Toggle Mode.
TIM3 counter clock = TIMxCLK / (Prescaler +1) = 12 MHz
The TIM3 CCR1 register value is equal to 32768:
CC1 update rate = TIM3 counter clock / CCR1_Val = 366.2 Hz,
so the TIM3 Channel 1 generates a periodic signal with a frequency equal to 183.1 Hz.
The TIM3 CCR2 register is equal to 16384:
CC2 update rate = TIM3 counter clock / CCR2_Val = 732.4 Hz
so the TIM3 channel 2 generates a periodic signal with a frequency equal to 366.3 Hz.
The TIM3 CCR3 register is equal to 8192:
CC3 update rate = TIM3 counter clock / CCR3_Val = 1464.8 Hz
so the TIM3 channel 3 generates a periodic signal with a frequency equal to 732.4 Hz.
The TIM3 CCR4 register is equal to 4096:
CC4 update rate = TIM3 counter clock / CCR4_Val = 2929.6 Hz
so the TIM3 channel 4 generates a periodic signal with a frequency equal to 1464.8 Hz.
Directory contents
- TIM/OCToggle/stm32f10x_conf.h Library Configuration file
- TIM/OCToggle/stm32f10x_it.c Interrupt handlers
- TIM/OCToggle/stm32f10x_it.h Interrupt handlers header file
- TIM/OCToggle/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect the TIM1 pins(TIM3 full remapped pins) to an oscilloscope to monitor the different waveforms:
- PC.06 (TIM3_CH1)
- PC.07 (TIM3_CH2)
- PC.08 (TIM3_CH3)
- PC.09 (TIM3_CH4)
- STM3210E-EVAL and STM3210B-EVAL Set-up
- Connect the following pins to an oscilloscope to monitor the different
waveforms:
- PA.06 (TIM3_CH1)
- PA.07 (TIM3_CH2)
- PB.00 (TIM3_CH3)
- PB.01 (TIM3_CH4)
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_flash.c
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- misc.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
OnePulse
Example Description
This example shows how to use the TIM peripheral to generate a One pulse Mode
after a Rising edge of an external signal is received in Timer Input pin.
The TIM4CLK frequency is set to 72 MHz, the Prescaler is 1 so the TIM4 counter
clock is 36 MHz.
The Autoreload value is 65535 (TIM4->ARR), so the maximum frequency value to trigger
the TIM4 input is 500 Hz.
The TIM4 is configured as follows:
The One Pulse mode is used, the external signal is connected to TIM4 CH2 pin (PA.01),
the Rising edge is used as active edge, the One Pulse signal is output
on TIM4_CH1 (PA.00).
The TIM_Pulse defines the delay value, the delay value is fixed to 455.08 us:
delay = CCR1/TIM4 counter clock = 455.08 us.
The (TIM_Period - TIM_Pulse) defines the One Pulse value, the pulse value is fixed to 1.365ms:
One Pulse value = (TIM_Period - TIM_Pulse)/TIM4 counter clock = 1.365 ms.
Directory contents
- TIM/OnePulse/stm32f10x_conf.h Library Configuration file
- TIM/OnePulse/stm32f10x_it.c Interrupt handlers
- TIM/OnePulse/stm32f10x_it.h Interrupt handlers header file
- TIM/OnePulse/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210E-EVAL, STM3210B-EVAL and STM3210C-EVAL Set-up
- Connect the external signal to the TIM4_CH2 pin (PB.07)
- Connect the TIM4_CH1 (PB.06) pin to an oscilloscope to monitor the waveform.
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
Parallel_Synchro
Example Description
This example shows how to synchronize TIM peripherals in parallel mode.
In this example three timers are used:
Timers synchronisation in parallel mode:
1/TIM2 is configured as Master Timer:
- PWM Mode is used
- The TIM2 Update event is used as Trigger Output
2/TIM3 and TIM4 are slaves for TIM2,
- PWM Mode is used
- The ITR1(TIM2) is used as input trigger for both slaves
- Gated mode is used, so starts and stops of slaves counters are controlled
by the Master trigger output signal(update event).
The TIMxCLK is fixed to 72 MHz, the TIM2 counter clock is 72 MHz.
The Master Timer TIM2 is running at TIM2 frequency:
TIM2 frequency = TIM2 counter clock/ (TIM2 period + 1) = 281.250 KHz
and the duty cycle is equal to TIM2_CCR1/(TIM2_ARR + 1) = 25%.
The TIM3 is running at:
(TIM2 frequency)/ (TIM3 period + 1) = 28.1250 KHz and a duty cycle equal to
TIM3_CCR1/(TIM3_ARR + 1) = 30%
The TIM4 is running at:
(TIM2 frequency)/ (TIM4 period + 1) = 56.250 KHz and a duty cycle equal to
TIM4_CCR1/(TIM4_ARR + 1) = 60%
Directory contents
- TIM/Parallel_Synchro/stm32f10x_conf.h Library Configuration file
- TIM/Parallel_Synchro/stm32f10x_it.c Interrupt handlers
- TIM/Parallel_Synchro/stm32f10x_it.h Interrupt handlers header file
- TIM/Parallel_Synchro/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect the pins to an oscilloscope to monitor the different waveforms:
- TIM2 CH1 (PA.00)
- TIM3 CH1 (PC.06) Remapped pin
- TIM4 CH1 (PB.06)
- STM3210E-EVAL and STM3210B-EVAL Set-up
- Connect the pins to an oscilloscope to monitor the different waveforms:
- TIM2 CH1 (PA.00)
- TIM3 CH1 (PA.06)
- TIM4 CH1 (PB.06)
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
PWM_Input
Example Description
This example shows how to use the TIM peripheral to measure the frequency and
duty cycle of an external signal.
The TIMxCLK frequency is set to 72 MHz, the Prescaler is 0 so the TIM3 counter
clock is 72 MHz. so the minimum frequency value to measure is 1100 Hz.
TIM3 is configured in PWM Input Mode: the external signal is connected to
TIM3 Channel2 used as input pin.
To measure the frequency and the duty cycle we use the TIM3 CC2 interrupt request,
so In the TIM3_IRQHandler routine, the frequency and the duty cycle of the external
signal are computed.
The "Frequency" variable contains the external signal frequency:
Frequency = TIM3 counter clock / TIM3_CCR2 in Hz,
The "DutyCycle" variable contains the external signal duty cycle:
DutyCycle = (TIM3_CCR1*100)/(TIM3_CCR2) in %.
Directory contents
- TIM/PWM_Input/stm32f10x_conf.h Library Configuration file
- TIM/PWM_Input/stm32f10x_it.c Interrupt handlers
- TIM/PWM_Input/stm32f10x_it.h Interrupt handlers header file
- TIM/PWM_Input/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210E-EVAL, STM3210B-EVAL and STM3210C-EVAL Set-up
- Connect the external signal to measure to the TIM3 CH2 pin (PA.07).
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- misc.c
- system_stm32f10x.c
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
PWM_Output
Example Description
This example shows how to configure the TIM peripheral in PWM (Pulse Width Modulation)
mode.
The TIMxCLK frequency is set to 36 MHz, the Prescaler is 0 so the TIM3 counter clock is
36 MHz.
The TIM3 is running at 36 KHz: TIM3 Frequency = TIM3 counter clock/(ARR + 1)
The TIM3 CCR1 register value is equal to 500, so the TIM3 Channel 1 generates a
PWM signal with a frequency equal to 36 KHz and a duty cycle equal to 50%:
TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR + 1)* 100 = 50%
The TIM3 CCR2 register value is equal to 375, so the TIM3 Channel 2 generates a
PWM signal with a frequency equal to 36 KHz and a duty cycle equal to 37.5%:
TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR + 1)* 100 = 37.5%
The TIM3 CCR3 register value is equal to 250, so the TIM3 Channel 3 generates a
PWM signal with a frequency equal to 36 KHz and a duty cycle equal to 25%:
TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR + 1)* 100 = 25%
The TIM3 CCR4 register value is equal to 125, so the TIM3 Channel 4 generates a
PWM signal with a frequency equal to 36 KHz and a duty cycle equal to 12.5%:
TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR + 1)* 100 = 12.5%
The PWM waveform can be displayed using an oscilloscope.
Directory contents
- TIM/PWM_Output/stm32f10x_conf.h Library Configuration file
- TIM/PWM_Output/stm32f10x_it.c Interrupt handlers
- TIM/PWM_Output/stm32f10x_it.h Interrupt handlers header file
- TIM/PWM_Output/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect the following pins(TIM3 full remapping pins) to an oscilloscope to monitor the different
waveforms:
- PC.06: (TIM3_CH1)
- PC.07: (TIM3_CH2)
- PC.08: (TIM3_CH3)
- PC.09: (TIM3_CH4)
- STM3210E-EVAL and STM3210B-EVAL Set-up
- Connect the following pins to an oscilloscope to monitor the different
waveforms:
- PA.06: (TIM3_CH1)
- PA.07: (TIM3_CH2)
- PB.00: (TIM3_CH3)
- PB.01: (TIM3_CH4)
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_flash.c
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
TIM1_Synchro
Example Description
This example shows how to synchronize TIM1 and Timers (TIM3 and TIM4) in parallel mode.
Timers synchronisation in parallel mode:
1/ TIM1 is configured as Master Timer:
- PWM Mode is used
- The TIM1 Update event is used as Trigger Output
2/ TIM3 and TIM4 are slaves for TIM1,
- PWM Mode is used
- The ITR0(TIM1) is used as input trigger for both slaves
- Gated mode is used, so starts and stops of slaves counters
are controlled by the Master trigger output signal(update event).
TIM1CLK = 72 MHz, Prescaler = 0, TIM1 counter clock = 72 MHz
The Master Timer TIM1 is running at:
TIM1 frequency = TIM1 counter clock / (TIM1_Period + 1) = 281.250 KHz
and the duty cycle is equal to: TIM1_CCR1/(TIM1_ARR + 1) = 50%
The TIM3 is running at:
(TIM1 frequency)/ ((TIM3 period +1)* (Repetion_Counter+1)) = 18.750 KHz and
a duty cycle equal to TIM3_CCR1/(TIM3_ARR + 1) = 33.3%
The TIM4 is running at:
(TIM1 frequency)/ ((TIM4 period +1)* (Repetion_Counter+1)) = 28.125 KHz and
a duty cycle equal to TIM4_CCR1/(TIM4_ARR + 1) = 50%
Directory contents
- TIM/TIM1_Synchro/stm32f10x_conf.h Library Configuration file
- TIM/TIM1_Synchro/stm32f10x_it.c Interrupt handlers
- TIM/TIM1_Synchro/stm32f10x_it.h Interrupt handlers header file
- TIM/TIM1_Synchro/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210C-EVAL Set-up
- Connect the following pins to an oscilloscope to monitor the different waveforms:
- TIM1 CH1 (PE.08) Remapped pin
- TIM3 CH1 (PC.06) Remapped pin
- TIM4 CH1 (PB.06)
- STM3210E-EVAL and STM3210B-EVAL Set-up
- Connect the following pins to an oscilloscope to monitor the different waveforms:
- TIM1 CH1 (PA.08)
- TIM3 CH1 (PA.06)
- TIM4 CH1 (PB.06)
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_flash.c
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
--------------------------------------------------------------------------------
TimeBase
Example Description
This example shows how to configure the TIM peripheral in Output Compare Timing
mode with the corresponding Interrupt requests for each channel in order to generate
4 different time bases.
The TIMxCLK frequency is set to 36 MHz, the Prescaler is 4 so the TIM2 counter
clock is 7.2 MHz.
The TIM2 CC1 register value is equal to 49152,
CC1 update rate = TIM2 counter clock / CCR1_Val = 146.48 Hz,
so the TIM2 Channel 1 generates an interrupt each 6.8ms
The TIM2 CC2 register is equal to 32768,
CC2 update rate = TIM2 counter clock / CCR2_Val = 219.7 HzHz
so the TIM2 Channel 2 generates an interrupt each 4.55ms
The TIM2 CC3 register is equal to 16384,
CC3 update rate = TIM2 counter clock / CCR3_Val = 439.4Hz
so the TIM2 Channel 3 generates an interrupt each 2.27ms
The TIM2 CC4 register is equal to 8192,
CC4 update rate = TIM2 counter clock / CCR4_Val = 878.9 Hz
so the TIM2 Channel 4 generates an interrupt each 1.13ms.
When the counter value reaches the Output compare registers values, the Output
Compare interrupts are generated and, in the handler routine, 4 pins(PC.06, PC.07,
PC.08 and PC.09) are toggled with the following frequencies:
- PC.06: 73.24Hz (CC1)
- PC.07: 109.8Hz (CC2)
- PC.08: 219.7Hz (CC3)
- PC.09: 439.4Hz (CC4)
Directory contents
- TIM/TimeBase/stm32f10x_conf.h Library Configuration file
- TIM/TimeBase/stm32f10x_it.c Interrupt handlers
- TIM/TimeBase/stm32f10x_it.h Interrupt handlers header file
- TIM/TimeBase/main.c Main program
Hardware and Software environment
- This example runs on STM32F10x Connectivity line, High-Density, Medium-Density
and Low-Density Devices.
- This example has been tested with STMicroelectronics STM3210C-EVAL (STM32F10x
Connectivity line), STM3210E-EVAL (STM32F10x High-Density) and STM3210B-EVAL
(STM32F10x Medium-Density) evaluation boards and can be easily tailored to
any other supported device and development board.
- STM3210E-EVAL, STM3210B-EVAL and STM3210C-EVAL Set-up
- Connect an oscilloscope on PC.06, PC.07, PC.08 and PC.09 to show the
different Time Base signals.
How to use it ?
In order to make the program work, you must do the following:
- Create a project and setup all project configuration
- Add the required Library files:
- stm32f10x_flash.c
- stm32f10x_gpio.c
- stm32f10x_rcc.c
- stm32f10x_tim.c
- misc.c
- system_stm32f10x.c (under Libraries\CMSIS\Core\CM3)
- Edit stm32f10x.h file to select the device you are working on.
Tip: You can tailor the provided project template to run this example, for
more details please refer to "stm32f10x_stdperiph_lib_um.chm" user
manual; select "Peripheral Examples" then follow the instructions
provided in "How to proceed" section.
- Link all compiled files and load your image into target memory
- Run the example
note
- Low-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 16 and 32 Kbytes.
- Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes.
- High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
- Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.