AnsweredAssumed Answered

STM32F0 Series Hardware Timers

Question asked by Sid P on Jul 26, 2017
Latest reply on Aug 17, 2017 by Sid P

Hi All,


A brief background:

I'm a hardware guy and new to all things ARM and STM32 MCUs. I've now jumped on board because ST has an agreement with Keil for STs Cortex M0/M0+ MCUs. I've programmed before but only 8-bit MCUs in Arduino and the CCS PIC C compiler from Custom Computer Services for the Microchip PIC line of MCUs.


For my very first project, I’ve begun work on phase angle control of the T1235 TRIAC also from ST. The processor I’m using is a Cortex M0 from the STM32F0 series. I’ve used STM32CubeMX (again for the first time ever) to generate the initialization code and have written some code in Keil uVision 5 (using this for the first time too). I’m using an opto-TRIAC in between the MCU and the T1235. I also have a zero-crossing detector (ZCD) that gives a pulse to the MCU every 10ms (50Hz mains).


So far, I’ve been able to trigger the TRIAC into a fully ON state and implement some crude dimming. Crude because the dimming does not work properly as the incandescent lamp flickers annoyingly even though.


The code implemented is something along the lines of this:


The ZCD signal is fed to the external (EXTI) interrupt. Now, to stabilize this and get smooth control with no flicker, I need to use one or perhaps more timers.


So far, I’ve referred to the MCU datasheet, errata sheet for device limitations and the following resources:



UM1785 – HAL user manual

RM0360 – Reference manual

AN4776 – General purpose timer cookbook

PM0215 – Cortex M0 programming manual

Technical ref manual for the ARM-CortexM0

AN4013 - STM32 cross-series timer overview

A whole bunch of YouTube videos

A search for ready-made drivers


Now, I will admit that I’ve not read all the above pdfs in great detail but I simply have not been able to find or understand (whatever I have found) how the timer hardware within my processor functions. Furthermore, STs documentation leaves a lot to be desired.


I was thinking of implementing the following logic which needs a good understanding of how timers function. An interrupt starts the timer that’s being clocked and it gives a small (100usec) pulse to fire the TRIAC at very regular intervals.


My questions are:


Can someone please explain (or point me in the right direction) in detail how the STM32F0 timers work since I apparently can’t seem to follow what’s written in RM0360 and AN4776.


Are there any other resources / videos that will explain how to better use the HAL.


Thanks in advance