cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with the ADC TIME CONVERSION

gdiez
Associate II
Posted on September 15, 2010 at 09:14

Problems with the ADC TIME CONVERSION

5 REPLIES 5
gdiez
Associate II
Posted on May 17, 2011 at 14:07

The CODE is...

STM32f10xx_it.c

void TIM1_UP_IRQHandler(void)

{

GPIOA->BSRR = GPIO_Pin_4; /* Toggle PIN */

TIM1_ClearITPendingBit(TIM1_FLAG_Update); /* Clear UPDATE interrupt bit */

}

void ADC_IRQHandler(void)

{

GPIOA->BRR = GPIO_Pin_4; /* Toggle PIN */

ADC1->SR = ~((u16)0x0004); /* Clear ADC interrupt bit */

}

I code the main features like that.

main.c

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); /* Sin Group Priority, PRI-n[7:4] Subpriority */

NVIC_SETPRIMASK(); /* DESHABILITA las interrupciones para configuracion */

/* Configure and enable ADC interrupt */

NVIC_InitStructure.NVIC_IRQChannel =

ADC1_2_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannel =

TIM1_UP_IRQChannel; /* TIM1 Update Interrupt */

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; /* Valor de prioridad [0~15] */

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; /* Valor de subprioridad */

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /* Habilita la interupción elegida */

NVIC_Init(&NVIC_InitStructure);

NVIC_RESETPRIMASK(); /* HABILITA las interrupciones despues de configuracion */

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_7); /* SYSCLK=56MHZ*/

RCC_ADCCLKConfig(RCC_PCLK2_Div4); /* ADC PCLK2/4=14MHz - CONFIGURE RCC_CFGR.ADCPRE */

RCC_PCLK2Config(RCC_HCLK_Div1); /* APB2 PCLK2 = 56MHz */

RCC_HCLKConfig(RCC_SYSCLK_Div1); /* AHB HCLK = 56MHz CONFIGURE RCC_CFGR.HPRE */

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

ADC_InjectedChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_1Cycles5);

lowpowermcu
Associate II
Posted on May 17, 2011 at 14:07

Hi Gerardo,

Why you don't use systick timer. I think it is useful for time measurement and perhaps it is more accurate than using GPIO.

Herzlich,

MCU Lüfter

gdiez
Associate II
Posted on May 17, 2011 at 14:07

Anyone knows the answer?

Can it be the time lost going to the ISR?

I´ve somo doubts with the TIM1 overflow interrupt, because i have to enable it only to see the exact time that ADC starts, not to work the ADC, only to know this time.

May i doing it bad?

gdiez
Associate II
Posted on May 17, 2011 at 14:07

I´ve tried it to see it in oscilloscope. I will investigate your way to do it and I will tell you if I get a solution.

Thks for replying!!

gdiez
Associate II
Posted on May 17, 2011 at 14:07

Hi lowpower:

I tried what you say but i couldn´t achive any thing.

I configure the systick with 3us time, to ensure that it nevers downflows.MI strategie is turn ON the systick system when the TIM1 overflows (like i did with toggle pin, but with systick timer).

when the ADC finishes, I enter in its ISR, and then I turn OFF the systick timer. Then with a breakpoint and a debugger, I saw the register STK_VAL(Value of systick).

I thought that this time of systick must be 1us but, when I enable the systick, my code never leaves the TIM ISR. If I delete the code it alternates TIM and ADC ISR.

I´m getting a little bit confused.

My configuration is the following:

void TIM1_UP_IRQHandler(void)

{

  SysTick_CounterCmd(SysTick_Counter_Enable); 

  TIM1->SR &= ~ 1;                               /* Clears TIM1 FLAG */

}

void ADC_IRQHandler(void)

{     

      SysTick_CounterCmd(SysTick_Counter_Disable);

      SysTick_CounterCmd(SysTick_Counter_Clear);

      ADC1->SR = ~((u16)0x0004);                               /* Clears ADC FLAG */

}

Main.c

SysTick_SetReload(168);   /* A frecuencia de 56MHz 3uS */