完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
第一章 模拟看门狗简介
STM32F1中带有的模拟看门狗功能,允许应用程序检测输入电压是否超出事先定义的高低阈值。在编程环节,程序员可根据应用的需求来设置检测的高,低阈值(如上图所示HTR与LTR)。一旦采集到的电压超出该上下限,将会触发模拟看门狗中断。其典型的应用有,检测到电流过大时控制继电器断电,进而保护后续电路。注意,看门狗设置与数据对齐方式无关。 第二章 STM32F1模拟看门狗相关配置函数介绍 void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold, uint16_t LowThreshold); //阈值设置 void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel); //模拟看门狗通道配置 void ADC_TempSensorVrefintCmd(FunctionalState NewState);//温度通道,未使用 void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog); //配置ADC组与ADC的通道情况 ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef ADCx, uint16_t HighThreshold, uint16_t LowThreshold) @brief 配置模拟看门狗的高低阈值 @param ADCx: 选择ADC组,ADC1, ADC2, ADC3? @param HighThreshold: 模拟看门狗的高阈值,12bit @param LowThreshold: 模拟看门狗的低阈值,12bit @retval None ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef ADCx, uint8_t ADC_Channel) @brief 配置模拟看门狗与ADC通道对应 @param ADCx: 选择ADC组,ADC1, ADC2, ADC3? @param ADC_Channel: 配置给模拟看门狗的ADC通道 @retval None ADC_AnalogWatchdogCmd(ADC_TypeDef ADCx, uint32_t ADC_AnalogWatchdog) @brief 使能模拟看门狗,并配置模拟看门狗的所有/单个ADC通道 @param ADCx: 选择ADC组,ADC1, ADC2, ADC3? @param ADC_AnalogWatchdog: ADC模拟看门狗通道配置 This parameter can be one of the following values: @arg ADC_AnalogWatchdog_SingleRegEnable: 单规则通道的模拟看门狗 @arg ADC_AnalogWatchdog_SingleInjecEnable: 单注入通道的模拟看门狗 @arg ADC_AnalogWatchdog_SingleRegOrInjecEnable: 单注入通道/规则通道的模拟看门狗 @arg ADC_AnalogWatchdog_AllRegEnable: 所有规则通道的模拟看门狗 @arg ADC_AnalogWatchdog_AllInjecEnable: 所有注入通道的模拟看门狗 @arg ADC_AnalogWatchdog_AllRegAllInjecEnable: 所有注入/规则通道的模拟看门狗 @arg ADC_AnalogWatchdog_None: 关闭模拟看门狗 @retval None 第三章 电路原理图与库函数配置 3.1 程序逻辑 Created with Raphaël 2.2.0 开始 LED常亮 ADC采样 超出模拟看门狗阈值? 结束 LED闪烁一次(中断) yes no 3.2 硬件原理(LED灯) Vcc LED 限流电阻 PA1 3.3 ADC配置 void ADC_Configuration(void) { #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) /* ADCCLK = PCLK2/2 */ RCC_ADCCLKConfig(RCC_PCLK2_Div2); #else /* ADCCLK = PCLK2/4 */ RCC_ADCCLKConfig(RCC_PCLK2_Div4); #endif /* Enable ADC1 clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* ADC1 Configuration ------------------------------------------------------*/ ADC_InitTypeDef ADC_InitStructure; ADC_InitStructure.ADC_Mode=ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode=DISABLE; ADC_InitStructure.ADC_ContinuousConvMode=ENABLE; ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel=1; ADC_Init(ADC1,&ADC_InitStructure); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* ADC1 regular channel14 configuration */ ADC_RegularChannelConfig(ADC1,ADC_Channel_14,1,ADC_SampleTime_13Cycles5); /* Configure high and low analog watchdog thresholds */ ADC_AnalogWatchdogThresholdsConfig(ADC1, 0x0B00, 0x0300); /* Configure channel14 as the single analog watchdog guarded channel 正常范围0.62V~2.26V*/ ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_14); /* Enable analog watchdog on one regular channel */ ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable); /* Enable AWD interrupt */ ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE); /* Enable ADC1 reset calibration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); } 3.4 LED端口配置 #define LED_PIN GPIO_Pin_1 #define LED_GPIO_PORT GPIOA #define LED_GPIO_CLK RCC_APB2Periph_GPIOA void STM_EVAL_LEDInit(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable the GPIO_LED Clock */ RCC_APB2PeriphClockCmd(LED_GPIO_CLK, ENABLE); /* Configure the GPIO_LED pin */ GPIO_InitStructure.GPIO_Pin = LED_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(LED_GPIO_PORT, &GPIO_InitStructure); } 3.5 NVIC中断配置 void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Configure and enable ADC interrupt */ #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) NVIC_InitStructure.NVIC_IRQChannel = ADC1_IRQn; #else NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn; #endif NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } 3.6 ADC输入端口PC4配置 void GPIO_Configuration(void) { /* Enable ADC_In clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; /* Configure PC.04 (ADC Channel14) as analog input -------------------------*/ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOC,&GPIO_InitStructure); } 3.7 中断服务函数 /** * @brief This function handles ADC1 and ADC2 global interrupts requests. * @param None * @retval None */ #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) void ADC1_IRQHandler(void) #else void ADC1_2_IRQHandler(void) #endif { /* Toggle LED1 */ GPIO_SetBits(LED_GPIO_PORT,LED_PIN); delay_ms(500); GPIO_ResetBits(LED_GPIO_PORT,LED_PIN); delay_ms(500); /* Clear ADC1 AWD pending interrupt bit */ ADC_ClearITPendingBit(ADC1, ADC_IT_AWD); } 3.8 主函数 int main(void) { delay_init(); GPIO_Configuration(); ADC_Configuration(); NVIC_Configuration(); STM_EVAL_LEDInit(); while(1){ GPIO_ResetBits(LED_GPIO_PORT,LED_PIN); } return 0; } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1113 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1134 浏览 1 评论
569 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
424 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1020 浏览 2 评论
1612浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
280浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
290浏览 3评论
273浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
250浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-20 02:29 , Processed in 0.750604 second(s), Total 46, Slave 40 queries .
Powered by 电子发烧友网
© 2015 www.ws-dc.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号