本帖最后由 xiaotime 于 2017-1-12 18:40 编辑
各位朋友,我用ADC的模拟看门狗检测设备的输出电压,函数filter(3)的返回值是设备的输出电压,要求当输出电压大于40V时就关断占空比,保护设备不受损坏。现在现象是无论输出电压是多少,都会进入中断函数关断占空比。
我的问题如下:
1、ADC_AnalogWatchdogThresholdsConfig(ADC1,1985,0);高低门限寄存器里的值1985是和哪个变量或哪个寄存器做比较?如何触发中断函数?
2、ARM满量程时的AD值是4095,对应3.3V,1985对应的是40V的输出电压,我使用的运放放大倍数是1/25,4095*40/(3.3*25)=1985,我理解1985就对应输出40V,不知道ADC_AnalogWatchdogThresholdsConfig这个函数中的门限值是否是这么设置?
我的问题是:
1、
代码如下:
void ADC_Configure(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->DR;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&AD_Value;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = N*M;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel1, ENABLE);
ADC_DeInit(ADC1);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode =ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; /
ADC_InitStructure.ADC_NbrOfChannel = M;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_239Cycles5 );
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_239Cycles5 );
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 3, ADC_SampleTime_239Cycles5 );
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 4, ADC_SampleTime_239Cycles5 );
ADC_DMACmd(ADC1, ENABLE);
AnalogWatchDog_Set();
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCmd(ADC1,ENABLE) ;
}
u16 filter(u32 channel)
{
int i=0;
After_filter[channel]=0;
for(i=0;i<N;i++)
After_filter[channel]+=AD_Value[channel] ;
return After_filter[channel]/N;
}
void AnalogWatchDog_Set(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
ADC_AnalogWatchdogSingleChannelConfig(ADC1,ADC_Channel_3);
ADC_AnalogWatchdogThresholdsConfig(ADC1,1985,0);
ADC_AnalogWatchdogCmd(ADC1,ADC_AnalogWatchdog_SingleRegEnable);
ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);
}
void ADC1_2_IRQHandler(void)
{
if(ADC_GetITStatus(ADC1, ADC_IT_AWD) == SET)
PWM_DutyCycle_Control(0);//关断占空比
ADC_ClearFlag(ADC1, ADC_FLAG_AWD);
ADC_ClearITPendingBit(ADC1, ADC_IT_AWD);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>