DMA/TIM capture
This is a more free standing example measuring the LSI (TIM5_CH4 internally)
and demonstrating DMA/TIM capture with granularity of APB1 * 2
// STM32F4-Discovery LSI Bench using DMA/TIM - sourcer32@gmail.com // SWV code redacted #include "stm32f4_discovery.h" #include <stdio.h>
#include <string.h> /**************************************************************************/ #define DELTA_SAMPLES 16 volatile uint32_t DeltaBuffer[DELTA_SAMPLES]; // TIM5 is 32-bit void TimerCapture(void)
{
DMA_InitTypeDef DMA_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure; /* Enable the LSI source, as an available built in asych source */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE); /* Enable the LSI OSC */
RCC_LSICmd(ENABLE); /* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET); /* TIM5 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE); /* DMA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); // TIM5_CH4 DMA1 Stream1 or 3, Channel 6, per RM0090
DMA_DeInit(DMA1_Stream1); DMA_StructInit(&DMA_InitStructure); /* not required - fully qualified below */ DMA_InitStructure.DMA_Channel = DMA_Channel_6;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&TIM5->CCR4);
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&DeltaBuffer[];
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = DELTA_SAMPLES;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; // 32-bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream1, &DMA_InitStructure); TIM_DeInit(TIM5); /* not required? */ /* Connect internally the TIM5_CH4 Input Capture to the LSI clock output */
TIM_RemapConfig(TIM5, TIM5_LSI); /* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF; // 32-bit maximal
TIM_TimeBaseStructure.TIM_Prescaler = ; // Highest Rate (DIV4 on APB1, DIV2 on TIMCLK5, 84 MHz?)
TIM_TimeBaseStructure.TIM_ClockDivision = ;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure); /* Channel configuration */
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x00;
TIM_ICInit(TIM5, &TIM_ICInitStructure); /* Enable the TIM Capture/Compare DMA requests */
// TIM_SelectCCDMA(TIM5, ENABLE); /* not required - Output Compare, want CCDS=0 (DISABLED) for CC rather than Update? */ TIM_DMACmd(TIM5, TIM_DMA_CC4, ENABLE); /* TIM enable counter */
TIM_Cmd(TIM5, ENABLE); /* Main Output Enable, and Input - TIM1/8 */
//TIM_CtrlPWMOutputs(TIMx, ENABLE);
} /**************************************************************************/ int main(void)
{
int i; memset((void *)DeltaBuffer, 0xCD, sizeof(DeltaBuffer)); // Flood buffer to prove it fills TimerCapture(); /* Clear DMA1_Stream1 Terminal Count */
DMA_ClearFlag(DMA1_Stream1, DMA_FLAG_TCIF1); /* Enable DMA1_Stream1 */
DMA_Cmd(DMA1_Stream1, ENABLE); /* Wait on DMA1 Stream1 Terminal Count */
while(DMA_GetFlagStatus(DMA1_Stream1, DMA_FLAG_TCIF1) == RESET); for(i=; i<DELTA_SAMPLES; i++)
printf("#%03d - Abs:%10d Delta:%10d\n",i,DeltaBuffer[i],DeltaBuffer[i] - DeltaBuffer[i-]); // Delta for 40 KHz measured at 84 MHz is 2100 cycle, or 1050 cycles for half period (both edges) // Measuring 1300/1315, 32.122 KHz not quite 50/50 duty while(); // Do not exit
}
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
# - Abs: Delta:
DMA/TIM capture的更多相关文章
- 重学STM32---(六)DAC+DMA+TIM
这两天复习了DAC,DMA再加上把基本定时器TIM6和TIM7看了一下,打算写一个综合点的程序,,,就在网上找了一些关于DAC,DMA和定时器相关的程序,最终打算写了输出正弦波的程序... 由于没有示 ...
- 【STM32H7教程】第32章 STM32H7的TIM定时器基础知识和HAL库API
完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第32章 STM32H7的TIM定时器基础知识和H ...
- stm32f103_高级定时器——输入捕获/输出比较中断+pwm=spwm生成
****************************首选我们了解一下它们的功能吧********************************************************** ...
- Data transfer from GPIO port to RAM buffer using DMA upon receiving a trigger signal on the timer capture input channel.
Data transfer from GPIO port to RAM buffer using DMA upon receiving a trigger signal on the timer ca ...
- STM32F103ZET6 之 ADC+TIM+DMA+USART 综合实验
1.实验目的 1)使用 TIM1 触发 ADC,ADC 采集的数据通过DMA 传至内存,然后通过串口打印出采集的数据: 2)学会 DMA 传输数据并将数据进行保存: 3)验证ADC 的采样率与实际设置 ...
- stm32之TIM+ADC+DMA采集50HZ交流信号
http://cache.baiducontent.com/c?m=9d78d513d98207f04fece47f0d01d7174a02d1743ca6c76409c3e03984145b5637 ...
- 16Khz音频定时触发采样DMA存储过程
一.AD Setting 1.Calibration (ADCAL) 2.设定ADC Chennel与SCANDIR等,在低功耗应用方案,选择PCLK/4,并设置SMP(tCONV = Samplin ...
- stm32 DMA数据搬运 [操作寄存器+库函数](转)
源:stm32 DMA数据搬运 [操作寄存器+库函数] DMA(Direct Memory Access)常译为“存储器直接存取”.早在Intel的8086平台上就有了DMA应用了. ...
- STM32 基DMA的DAC波形发生器
DAC是STM32系列的一个基本外设,可以将数字信号转化成模拟信号,这次我将使用DAC来输出一个特定波形. 首先确定工作方法,由于我目前在做的简易示波器在输出波形的同时还需要显示输入信号,所以不能占用 ...
随机推荐
- HDU 1176 免费馅饼 DP类似数塔题
解题报告: 小明走在一条小路上,这条小路的长度是10米,从左到右依次是0到10一共十个点,现在天上会掉馅饼,给出馅饼掉落的坐标和时间,一开始小明的位置是在坐标为5的位置, 他每秒钟只能移动一米的距离, ...
- redhat7配置本地yum源
1.首先是要有一个iso文件,并将这个文件挂载到某个目录 挂载: 配置: 检验: yum list 现在你就可以在没有网的情况下,安装软件了~~~
- ZeroMQ安装说明
ZeroMQ安装说明 1. 安装 1.1.Linux zmq安装 安装过程参考地址:http://zeromq.org/intro:get-the-software的说明 安装步骤如下(在安装时参 ...
- Linux下USB suspend/resume源码分析【转】
转自:http://blog.csdn.net/aaronychen/article/details/3928479 Linux下USB suspend/resume源码分析 Author:aaron ...
- usb_control_msg函数用法和说明
usb_control_msg是没有用到urb的在USB中简单进行发送和接收的一种机制,用于少量的数据通信.原型为: 程序代码 linux+v2.6.35/drivers/usb/core/mess ...
- Ansible Tower系列 四(使用tower执行一个命令)【转】
在主机清单页面中,选择一个主机清单,进入后,选择hosts里的主机 Paste_Image.png 点击 RUN COMMANDS MODULE 选择 commandARGUMENTS 填写 ifco ...
- springcloud使用使用Feign-Ribbon做负载均衡实现声明式REST调用
什么是Feign Feign是一个声明式的伪Http客户端,它使得写Http客户端变得更简单.使用Feign,只需要创建一个接口并注解.它具有可插拔的注解特性,可使用Feign 注解和JAX-RS注解 ...
- System.Web.Routing入门及进阶 上篇
System.Web.Routing已经作为一个程序集包含在.net3.5sp1中发布了.虽然我们并没有在3.5sp1中发现Asp.net Mvc的踪迹,但是亦以感觉到它离我们不远了. System. ...
- springmvc接收jquery提交的数组数据
var selectedUsers = $('#users').tagbox('getValues'); if (selectedUsers.length > 0) { $.post(appPa ...
- tab切换webuploader失效的解决方法
<script type="text/javascript"> $(document).ready(function () { $('#tt').tabs({ bord ...