smeraj580
Newbie
Code:
int main(void)
{
Init_Prcs();
while(1)
{
ADC_StartOfConversion(ADC1);
while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_OVR));
}
}
void Init_Prcs(void)
{
SystemInit();
SystemCoreClockUpdate();
Hal_AdcInit();
}
void Hal_AdcInit(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
ADC_InitTypeDef ADC_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA,&GPIO_InitStruct);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_TRGO;
ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStruct.ADC_ScanDirection = ADC_ScanDirection_Upward;
ADC_Init(ADC1,&ADC_InitStruct);
for(i=0;i<adc_max;i++)
{
ADC_ChannelConfig(ADC1,CHANNELS,ADC_SampleTime_239_5Cycles);
}
ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE);
ADC_VrefintCmd(ENABLE);
ADC_Cmd(ADC1,ENABLE);
while (!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY));
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = ADC1_COMP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void ADC1_COMP_IRQHandler(void)
{
while(ADC_GetITStatus(ADC1,ADC_IT_EOC)==RESET);
if(adc_ctr<=adc_max)
{ ADC_VAL[adc_ctr++]=ADC_GetConversionValue(ADC1);
}
else
{
adc_ctr=0;
}
ADC_ClearITPendingBit(ADC1,ADC_IT_EOC);
}
help me out what am i doing wrong here ?? please
[Code tags added by moderator]
Last edited by a moderator: