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来输出一个特定波形. 首先确定工作方法,由于我目前在做的简易示波器在输出波形的同时还需要显示输入信号,所以不能占用 ...
随机推荐
- 20155217 2016-2017-2 《Java程序设计》第5周学习总结
20155217 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 第八章 java中所有错误都会被包装为对象,可以尝试(try)执行程序并捕捉(catch)代 ...
- 第11月第20天 sqlite3_open xcode mysql connector
1. sqlite3_open 死锁 * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP frame ...
- MongoDB 之 $关键字 及 $修改器 $set $inc $push $pull $pop MongoDB - 4
我们在之前的 MongoDB 之 手把手教你增删改查 MongoDB - 2 中提到过 $set 这个系统关键字,用来修改值的对吧 但是MongoDB中类似这样的关键字有很多, $lt $gt $lt ...
- Java内存模型-final域的内存语义
一 引言 说到final你肯定知道它是Java中的关键字,那么它所在Java中的作用你知道吗?不知道的话,请前往这篇了解下https://www.cnblogs.com/yuanfy008/p/802 ...
- ASP.NET程序发布
详细流程请参考文章:https://www.cnblogs.com/wangjiming/p/6286045.html 主要补充个人操作过程中遇到的问题: 1)网站发布完成后,站点下没有aspnet_ ...
- SqlMapConfig.xml全局配置文件介绍——(四)
----------mybatis的全局配置文件SqlMapConfig.xml,配置内容如下:----------- properties(属性) settings(全局配置参数) typeAlia ...
- springboot日志框架
Spring Boot日志框架Spring Boot支持Java Util Logging,Log4j2,Lockback作为日志框架,如果你使用starters启动器,Spring Boot将使用L ...
- SpringMVC_HelloWorld_01
通过配置文件的方式实现一个简单的HelloWorld. 源码 一.新建项目 1.新建动态web项目 2.命名工程springmvc-01 3.勾选"Generate web.xml depl ...
- Android 5.0 行为变更
Android 5.0 除了提供诸多新特性和功能外,还对系统和 API 行为做出了各种变更.本文重点介绍您应该了解并在开发应用时加以考虑的一些主要变更. 如果您之前发布过 Android 应用,请注意 ...
- laravel 打印sql语句
public function getCurrencyOrder($user_id=70,$pid=252,$register=['register:first']) { DB::connection ...