在线时间0 小时
UID270939
ST金币0
蝴蝶豆0
注册时间2007-7-2
新手上路
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
*TIM2通道2作为ADC1转换的触发时钟200US转换一次--------------------------------- */
TIM_DeInit(TIM2); //重新将Timer设置为缺省值
TIM_TimeBaseStructure.TIM_Period = 200; //1US*200=200US设置计数溢出大小,
TIM_TimeBaseStructure.TIM_Prescaler = 20; //预分频系数为20 /20=1M(1US)
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //设置计数器模式为向上计数模式
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure); //将配置应用到TIM2中
//PWM设置
TIM_OCStructInit(&TIM_OCInitStructure); //设置缺省值
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //PWM模式1输出(PWM2也行)
TIM_OCInitStructure.TIM_Pulse = 15; //设置占空比
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //TIM输出比较极性高 (LOW也行)
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //使能输出状态
TIM_OC2Init(TIM2, &TIM_OCInitStructure); //初始化TIM2的2通道
TIM_ARRPreloadConfig(TIM2, ENABLE); //使能TIMx在ARR上的预装载寄存器
TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable); //使能TIMx在CCR2上的预装载寄存器
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 9;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 Regular Channel1 Configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_41Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_41Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_41Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 4, ADC_SampleTime_41Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 5, ADC_SampleTime_41Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 6, ADC_SampleTime_41Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 7, ADC_SampleTime_41Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 8, ADC_SampleTime_41Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 9, ADC_SampleTime_239Cycles5);
/* Enable ADC1 */
ADC_TempSensorVrefintCmd(ENABLE);//
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1's DMA interface */
ADC_Cmd (ADC1, ENABLE); /* Enable ADC1 */
ADC_ExternalTrigConvCmd(ADC1, ENABLE);
//ADC_SoftwareStartConvCmd(ADC1,ENABLE);/* Start ADC1 Software Conversion */
TIM_Cmd(TIM2,ENABLE);
TIM_CtrlPWMOutputs(TIM2,ENABLE); //设置TIM2的PWM输出为使能
程序下载后只能转换一次后就不再定时转换了,是不是上面配置有问题,(我是通过DMA传送ADC转换结果的,DMA配置经验证是对的)
|
|