STM32 System and Timer Clock Configurations
STM32 System and Timer Clock Configurations
I've started writing some software to drive a series of TLC5940 16 Channel LED Driver chips on an ST STM32F407 Microcontroller.
I previously had code working on an Atmel microcontroller, but obviously with the change of hardware comes
the need for re-writing some of the lower peripheral configuration and application code.
The two main requirements for driving the TLC5940 chip from a microcontroller are:
- The grayscale clock
- A serial data bus
- system_stm32f4xx.c - the PLL register value #DEFINEs and initialisation code is found here
- stm32f4xx.h - the HSE frequency is defined at the start
- f(VCO clock) = f(PLL clock input) × (PLLN / PLLM)
- f(PLL general clock output) = f(VCO clock) / PLLP
These equations describe what is happening in the hardware.
My initial setup used the following configuration:
stm32f4xx.h:
- #define HSE_VALUE ((uint32_t)8000000)
- #define PLL_M 8
- #define PLL_N 336
- #define PLL_P 2
However after noticing the mention of increased clock jitter, I decided to change PLL_M to '4', PLL_N to '168'.
Using the peripheral library commands below, I've selected the HSE for MCO1, and SYSCLK divided by 5 for MCO2.
- RCC_MCO1Config(RCC_MCO1Source_HSE, RCC_MCO1Div_1);
- RCC_MCO2Config(RCC_MCO2Source_SYSCLK, RCC_MCO2Div_5);
And viewing these signals in the images below we can see that this is roughly the case.

UPDATE:
I've taken some measurements with the scopes at work and they appear to agree with the 8MHz result,




Now that I've verified my system's core clock is functioning as expected,
I can move onto configuring the clock modules to produce the desired BLANK and GSCLK signals to control the TLC5940 chips.
Using the SYSCLK signal, the 'Advanced High-performance Bus' (AHB) clock frequency is set via a prescaler.
In this case I am using the maximum frequency of the AHB by setting the prescaler to divide by 1.
The two 'Advanced Peripheral Bus' clocks (APB1 and APB2) are generated from the AHB via their associated prescalers.
They have maximum frequencies of 42 and 84MHz respectively,
so my APB1 prescaler is set to '4' and APB2 prescaler is set to '2'.
The internal signal that can be selected as the timer peripherals' clock is the APB1 clock.
HOWEVER...
and this is an important part to take note of:
While the APB1 signal provides the clock for numerous peripherals including the timer modules,
the timers can receive a faster clock if the APB1 prescaler is set to anything other than '1'. The manual states:
- If the APB prescaler is 1, the timer clock frequencies are set to the same frequency as that of the APB domain to which the timers are connected.
- Otherwise, they are set to twice (×2) the frequency of the APB domain to which the timers are connected.
Since the APB1 prescaler I am using is '4' and the AHB clock is 168MHz, the internal clock presented to the timer modules is actually (168/4) * 2 = 84MHz.
Inside the TIMx modules there are three main clock signals:
- CK_INT - The internal clock before prescaling
- CK_PSC - The clock signal after being divided by the prescaler
- CK_CNT - The counter clock, which generates pulses every time the prescaler counter overflows
Note that while there are different clock signals (internal clock, external clock, internal triggers, etc)
that can be used as the main input to each timer module, since I don't need to synchronise to external signals,
I will use the default internal clock, APB1.
The internal clock signal APB1 is fed into my main timer module TIM3.
This module will be used to provide both the GSCLK signal on an external GPIO pin,
and also to trigger/clock the slave TIM4 module which will provide the BLANK pulses.
Initially I intend to have the TIM3 setup for its fastest possible rate,
and then configure the output for the desired GSCLK frequency once both signals are synchronised correctly.
I am using a prescaler divide factor of 1 (TIM3_PSC = 0), so CK_PSC = CK_INT = APB1 * 2 = 84MHz.
This trigger is passed into TIM4 on the Internal Trigger network, which, when these two specific timers are used, is the Internal Trigger 2 signal (ITR2).
Returning to the original task of providing grayscale clock and blanking pulse signals for the TLC5940,
For the GSCLK signal, the TIM3 Output Compare Channel 1 (OC1) signal is configured to toggle its output
For the BLANK signal, we need to be able to synchronise the signals with a phase shift so that the desired number of GSCLK pulses are generated
so that it counts up to the ARR value and then counts down to zero and repeats.
- CCR1 = GSCLK_COUNT + 1
The timing for each timer module, and the resulting signals seen by the TLC5940 chip are shown below in Fig.1.



STM32 System and Timer Clock Configurations的更多相关文章
- STM32 Timer Clock sources -- External Clock Both Edge
Timers get their clock source from External pins or Internal timer sources. External External = pins ...
- STM32F10xxx 之 System tick Timer(SYSTICK Timer)
背景 研究STM32F10xxx定时器的时候,无意间看到了System tick Timer,于是比较深入的了解下,在此做个记录. 正文 System tick Timer是Cotex-M内核的24位 ...
- System.Threading.Timer 定时器的用法
System.Threading.Timer 是C# 中的一个定时器,可以定时(不断循环)执行一个任务.它是在线程上执行的,具有很好的安全性.为此 .Net Framework 提供了5个重载的构造 ...
- C# System.Timers.Timer的一些小问题?
比如设置间隔时间是 1000msSystem.Timers.Timer mytimer = new System.Timers.Timer(1000);问题若响应函数执行的时间超过了 1000 ms, ...
- C# System.Threading.Timer 使用方法
public class TimerHelper { System.Threading.Timer timer; public TaskSendMMS tasksendmms { get; set; ...
- [C#]System.Timers.Timer
摘要 在.Net中有几种定时器,最喜欢用的是System.Timers命名空间下的定时器,使用起来比较简单,作为定时任务,有Quartz.net,但有时候,一个非常简单的任务,不想引入这个定时任务框架 ...
- C# --System.Timers.Timer 定时方法
注意Start() 注意要等Interval 时间间隔 static void Main(string[] args) { System.Timers.Timer t = new System.Tim ...
- System.Threading.Timer使用心得
System.Threading.Timer 是一个使用回调方法的计时器,而且由线程池线程服务,简单且对资源要求不高. "只要在使用 Timer,就必须保留对它的引用."对于任何托 ...
- System.Windows.Forms.Timer与System.Timers.Timer的区别(zz)
.NET Framework里面提供了三种Timer: System.Windows.Forms.Timer System.Timers.Timer System.Threading.Timer VS ...
随机推荐
- 【转】在Mac OS X 10.8中配置Apache + PHP + MySQL
CHENYILONG Blog 在Mac OS X 10.8中配置Apache + PHP + MySQL 在Mac OS X 10.8中配置Apache+PHP+MySQL的内容包括: 配置Apac ...
- 002_CentOS-6.4-x86_64安装包的说明
http://mirrors.sohu.com/centos/6.6/isos/x86_64/?qq-pf-to=pcqq.group //souhu镜像下载地址 0_README.txt 25-Oc ...
- Visual C++中最常用的类与API函数
这篇文章能让初学者快速了解visual C++ MFC中常见的核心的类与函数,虽然全部看下来有点枯燥,但对初学者快速了解MFC的框架结构很有好处. 常用类 CArchive类:用于二进制保存档案 CB ...
- printf 字符串格式
摘自:http://www.cppblog.com/API/archive/2013/07/18/201923.html 首先 long long是C99标准新规定的.不少编译器还不支持,Micros ...
- 启动DELPHI2010出现 EditorLineEnds.ttr 错误的解决方法
在网上找到了很多方法.其实解决这个问题的方法, 最简单的就是把 EditorLineEnds.ttr 改名为 EditorLineEnds.ttf 然后,安装它, 安装完成后就OK了.
- 【BZOJ】4380: [POI2015]Myjnie
题解 区间dp,先离散化所有价值 \(f[i][j][k]\)表示\([i,j]\)区间里最小值为\(k\)的价值最大是多少 只考虑\(i <= a <= b <= j\)的区间,枚 ...
- 2018年湘潭大学程序设计竞赛 G- 又见斐波那契
推一推矩阵直接快速幂. #include<bits/stdc++.h> #define LL long long #define pii pair<int,int> #defi ...
- 007 @CookieValue绑定请求中的cookie
1.介绍 2.使用的cookie 3.index.jsp <%@ page language="java" contentType="text/html; char ...
- 洛谷P3398 仓鼠找sugar [LCA]
题目传送门 仓鼠找sugar 题目描述 小仓鼠的和他的基(mei)友(zi)sugar住在地下洞穴中,每个节点的编号为1~n.地下洞穴是一个树形结构.这一天小仓鼠打算从从他的卧室(a)到餐厅(b),而 ...
- Parcel极速零配置Web应用打包工具
当听到极速零配置打包,我不经兴奋起来,零配置!!!想起在webpack打包的配置,这个零配置着实让我好奇不已,迅速学习一波. Parcel(parcel 英[ˈpɑ:sl] 美[ˈpɑ:rsl])有以 ...