OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3621|回复: 7

用STM32内部自带ADC 进行转换 STM32和转换电路在一块电路板上被检测电路电压40V左右 在转换的过程ADC会停止转换 这是.为...

[复制链接]

28

主题

74

帖子

0

精华

初级会员

Rank: 2

积分
158
金钱
158
注册时间
2016-1-18
在线时间
21 小时
发表于 2016-5-27 19:35:14 | 显示全部楼层 |阅读模式
1金钱
本帖最后由 编程菜鸟 于 2016-5-27 19:36 编辑

电压在40V波动的  时候  会停止ADC转换

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2016-5-28 20:14:46 | 显示全部楼层
ADC测量40V电压?降压了么
回复

使用道具 举报

28

主题

74

帖子

0

精华

初级会员

Rank: 2

积分
158
金钱
158
注册时间
2016-1-18
在线时间
21 小时
 楼主| 发表于 2016-5-30 11:45:47 | 显示全部楼层
电压  降过了  要不然AD早烧坏了   大家有遇到过AD停止转换吗
回复

使用道具 举报

3

主题

2178

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
3323
金钱
3323
注册时间
2013-7-19
在线时间
195 小时
发表于 2016-5-30 12:04:19 | 显示全部楼层
是AD功能停止了还是屏幕或是串口不输出了
回复

使用道具 举报

28

主题

74

帖子

0

精华

初级会员

Rank: 2

积分
158
金钱
158
注册时间
2016-1-18
在线时间
21 小时
 楼主| 发表于 2016-5-30 13:07:43 | 显示全部楼层
AD停止转换了
回复

使用道具 举报

28

主题

74

帖子

0

精华

初级会员

Rank: 2

积分
158
金钱
158
注册时间
2016-1-18
在线时间
21 小时
 楼主| 发表于 2016-5-30 13:09:45 | 显示全部楼层
本帖最后由 编程菜鸟 于 2016-5-30 13:12 编辑

void ADC_Configuration(void)
{

        ADC_InitTypeDef ADC_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        GPIO_InitTypeDef GPIO_InitStructure;
         
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);                                                                        // Enable ADC1 clock (12MHz)

        // Initialize pins
        RCC_ADCCLKConfig(RCC_PCLK2_Div6);
         
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;                                                                                        // Select input pull-down mode
       
        GPIO_InitStructure.GPIO_Pin = Pin_SMPL1 | Pin_SMPL2;                                                                        // Select pin
        GPIO_Init(Port_SMPL1, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin =  Pin_SMPL3 | Pin_SMPL4 | Pin_SMPL10
                                                                | Pin_SMPL11 | Pin_SMPL12 | Pin_SMPL13;                                                // Select pin
        GPIO_Init(Port_SMPL3, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_SMPL5 | Pin_SMPL6 | Pin_SMPL7
                                                                | Pin_SMPL8 | Pin_SMPL9;                                                                        // Select pin
        GPIO_Init(Port_SMPL5, &GPIO_InitStructure);

        ADC_DeInit(ADC1);
        // ADC1 module
        ADC_InitStructure.ADC_Mode = ADC_Mode_Independent ;
        ADC_InitStructure.ADC_ScanConvMode = DISABLE;
        ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
        //ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
        ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO;
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStructure.ADC_NbrOfChannel = 1;                                                                                                // All 13 Channels
        ADC_Init(ADC1, &ADC_InitStructure);

        //ADC_RegularChannelConfig(ADC1, (u8)Channel_number_Group[Testing_data.Conversion_Channel], 1, ADC_SampleTime_13Cycles5 );
                       

        ADC_Cmd(ADC1, ENABLE);
       
        ADC_ResetCalibration(ADC1);
       
        while(ADC_GetResetCalibrationStatus(ADC1));
       
        ADC_StartCalibration(ADC1);
        //ADC_SoftwareStartConvCmd(ADC1, DISABLE);
       
        while(ADC_GetCalibrationStatus(ADC1));

        ADC_ExternalTrigConvCmd(ADC1, ENABLE);                                           //使能ADC经外部触发启动转换功能
        ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE);
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
        NVIC_InitStructure.NVIC_IRQChannel  = ADC1_2_IRQChannel;                                                         //ADC1,ADC2全局中断
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;                                                        //先占优先级0
        NVIC_InitStructure.NVIC_IRQChannelSubPriority   = 3;                                                           //从优先级
        NVIC_InitStructure.NVIC_IRQChannelCmd   = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
       

}
void TIM_Configuration(void)
{

        GPIO_InitTypeDef GPIO_InitStructure;
        TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
        TIM_OCInitTypeDef TIM_OCInitStructure;
        //RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3|RCC_APB1Periph_TIM4|RCC_APB2Periph_TIM1,ENABLE);
       
        //TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        TIM_TypeDef* TIMx[3];
        u8 i;

        TIMx[0] = TIM1;
        TIMx[1] = TIM3;
        TIMx[2] = TIM4;

        // PWM pins
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;                                                                // Set mode
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH0;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH0, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH1;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH1, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH2;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH2, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH3;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH3, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH4;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH4, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH5;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH5, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH6;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH6, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH7;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH7, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH8;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH8, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH9;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH9, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH10;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH10, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = Pin_PWM_CH11;                                                                        // Select pin
        GPIO_Init(Port_PWM_CH11, &GPIO_InitStructure);TIMx[0] = TIM1;
       


        // Enable APB clock for TIMx
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);                                                // Enable timer 1 clock
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);                                                // Enable timer 3 clock
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);                                                // Enable timer 4 clock

        // Remap required pins - consult STM32F1 TRM Section 8.3.7 Timer alternate function remapping
        GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE);


        // Initialize all timers
        for(i=0; i<3; i++)
        {
                //Initialize TIM Base settings
                TIM_TimeBaseInitStructure.TIM_Prescaler = PWM_PRESCALER1;                                // TIM running at frequency= TIMxCLK / (Prescaler + 1)
                TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;                // Count down from 4095 to 0
                TIM_TimeBaseInitStructure.TIM_Period = PWM_PERIOD;                                                // 72MHz / 8 = 9MHz; 9000000Hz/4095 = 35.156KHz 's period
                TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;                                // Division of the system clock frequency, 72MHz/2 = 36MHz
                TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;                                        // Reserved only for TIM1_RCR register
                TIM_TimeBaseInit(TIMx, &TIM_TimeBaseInitStructure);                                        // Initialize base register
               
               
                //Initialize TIM output pins
                TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;                                                // Use PWM mode 1
                TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;                        // Positive output pin enable/disable
                TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;                // Negative output pin enable/disable

                // Pulse (PWM duty) for each channel
                // Channel 1
                TIM_OCInitStructure.TIM_Pulse = PWM_OCP_DEFAULT;                                                // Initial duty
                TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
                TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
                TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
                TIM_OCInitStructure.TIM_OCNIdleState =TIM_OCNIdleState_Reset ;
                TIM_OC1Init(TIMx, &TIM_OCInitStructure);
                TIM_OC1PreloadConfig(TIMx, TIM_OCPreload_Enable);                                        // Enable current channel output compare preload shadow register

                // Channel 2
                TIM_OCInitStructure.TIM_Pulse = PWM_OCP_DEFAULT;                                                // Initial duty
                TIM_OC2Init(TIMx, &TIM_OCInitStructure);
                TIM_OC2PreloadConfig(TIMx, TIM_OCPreload_Enable);
               
                // Channel 3
                TIM_OCInitStructure.TIM_Pulse = PWM_OCP_DEFAULT;                                                // Initial duty
                TIM_OC3Init(TIMx, &TIM_OCInitStructure);
                TIM_OC3PreloadConfig(TIMx, TIM_OCPreload_Enable);
               
                // Channel 4
                TIM_OCInitStructure.TIM_Pulse = PWM_OCP_DEFAULT;                                                // Initial duty
                TIM_OC4Init(TIMx, &TIM_OCInitStructure);
                TIM_OC4PreloadConfig(TIMx, TIM_OCPreload_Enable);
               
                TIM_ARRPreloadConfig(TIMx, ENABLE);                                                                        // Enable shadow register for Timer2

                //Start TIM2 module
                TIM_Cmd(TIMx, ENABLE);

                //Enable TIM2 PWM output peripheral
                TIM_CtrlPWMOutputs(TIMx, ENABLE);
        }

        TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);                                //Set the TIM3 master mode
        TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update);                                                 // timer 3 TRGO as trigger output
       
        TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Reset);                                                                //Set the TIM1 from the pattern
        TIM_SelectInputTrigger(TIM1, TIM_TS_ITR2);                                                                         //The timer 3 TRGO timer trigger output as a trigger reset timer 1
       
        TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Reset);                                                         //Set the TIM4 from the pattern
        TIM_SelectInputTrigger(TIM4, TIM_TS_ITR2);                                                                  //The timer 3  TRGO timer trigger output as a trigger reset timer 4

}


          而且  是PWM工作的时候  AD就停止转换了
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2016-6-1 22:07:36 | 显示全部楼层
是不是IO冲突了?
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

28

主题

74

帖子

0

精华

初级会员

Rank: 2

积分
158
金钱
158
注册时间
2016-1-18
在线时间
21 小时
 楼主| 发表于 2016-6-2 09:57:02 | 显示全部楼层
不可能啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-10 09:02

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表