2010-09-06 04:07 AM
EXTERNAL TRIGGER ADC
2011-05-17 05:05 AM
Don't see code setting up the base vector address.
Don't see code setting up the NVIC priority group. See code using the same sub/priority more than once.2011-05-17 05:05 AM
I don’treally understand why do you want measure conversion time it is deterministic.I guess you are looking for TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE).
From wantI remember you want to create pwm signal based on analog value. Use one of CCmode flags to fire ADC at the end of pwm cycle then compute duty either by theend of conversion or at tim update event and use other CC register to generatepwm signal. There is going to be a bit of cycles lost for calculations. If youwant to make it precise use CYCCNT register to measure execution time andadjust CC accordingly. Personally I would use adc continuous mode and stop worryingabout triggering etc for the sake of simplicity.
Regards
Thomas
2011-05-17 05:05 AM
2011-05-17 05:05 AM
Hi my friend:
That´s my next target. Get in oscilloscope, the ADC conversion time, with a led toggle. I´ve achieved my old target like that:Configure TIM1 like PWM1 and like the trigger of adcvoid TIMER_configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TIM1 y TIM3 CLK ~~~ */ /* TIM 1 CAPTURE-COMPARE-PWM MODE */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 ,ENABLE); /* RCC_APB2ENR.TIM1EN ENABLE CLK TIM1 */ RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1 ,DISABLE); /* RCC_APB2RSTR.TIM1RST RESET TIM1 */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION TIM3 PARA TRIGGER ADC ~~ */ /* ~~~~~~~ CONFIGURACION PARA 20KHz ~~~~~~~~~~~~~~~~~~~~ */ #define Prescala 1 /* Maximo 65536 */ #define Periodo 2799 /* Maximo 65536 */ TIM_TimeBaseStructure.TIM_Prescaler = Prescala-1; /* DIVIDE EL CK_CNT=CK_PSC/(TIMx_PSC+1) - TIMx_PSC */ TIM_TimeBaseStructure.TIM_Period = Periodo; /* NUMERO DE PULSOS A CONTAR DE CK_CNT - PERIODO TIMx_ARR */ TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down; /* MODO DE CONTADOR - TIM_CR1.DIR */ TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; /* PARA FILTROS DIGITALES - TIM_CR1.CKD */ TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; /* TIM_RCR */ TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION TIM1 TRGO TRIGGER ~~ */ TIM_SelectOutputTrigger(TIM1,TIM_TRGOSource_Update); TIM1_ClearITPendingBit(TIM1_FLAG_Trigger); /* BORRA UPDATE INTERRUPT BIT TIMx_SR.UIF */ TIM_ITConfig(TIM1, TIM_IT_COM, ENABLE); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PWM1 Mode configuration: Channel2 ~~ */ /* PWM1 Mode configuration: Channel2 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; /* ELIGE EL MODO PWM */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 0; /* Duty Cycle */ TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC2Init(TIM1, &TIM_OCInitStructure); TIM_CtrlPWMOutputs(TIM1, ENABLE); /* TIM1 Main Output Enable */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ TIM_Cmd(TIM1,ENABLE); /* ENCENDIDO TIM1 */ }
Configure the ADC with a external trigger
void ADC_configuration(void) { ADC_InitTypeDef ADC_InitStructure; ADC_DeInit(ADC1); /* Inicializa los registros */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ADC1 clock ~~~~~~~~~~~ */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION DEL ADC1 ~~ */ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; /* ELIGE EL MODO DE OPERACION - ADC_CR1.DUALMOD */ ADC_InitStructure.ADC_ScanConvMode = ENABLE; /* HABILITA MODO SCAN (GRUPO DE CANALES) - ADC_CR1.SCAN */ ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; /* DESHABILITA EL MODO CONTINUO - ADC_CR2.CONT */ ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigInjecConv_T1_TRGO; /* HABILITA TRIGGER POR TIMER3 - ADC_CR2.EXTSEL */ ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; /* ALINEACION A LA DERECHA - ADC_CR2.ALIGN */ ADC_InitStructure.ADC_NbrOfChannel = 1; /* NUMERO DE CANALES DEL GRUPO */ ADC_Init(ADC1, &ADC_InitStructure); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION DEL ADC1 ~~ */ /* SELECCION DEL SAMPLE TIME - ADC_SMPR2.SMPx, SELECCION SECUENCIA INJECTED - ADC_SQR1 */ /* ~~~~~~~~~~~~~~~~~~ ADC conversion Time = Sampling Time + 12,5 cycles ~~~~~ */ ADC_InjectedChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_1Cycles5); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HABILITACION DEL ADC1 DMA */ // ADC_DMACmd(ADC1, ENABLE); /* HABILITACION DIRECT MEMORY ACCESS MODE - ADC_CR2.DMA */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HABILITACION DEL ADC1 ~~~ */ ADC_Cmd(ADC1, ENABLE); /* DESPIERTA AL ADC - ADC_CR2.ADON */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RESETEO DEL ADC1 ~~~~~~~ */ ADC_ResetCalibration(ADC1); /* INICIALIZA REGS. CALIBRACION - ADC_CR2.RSTCAL */ while(ADC_GetResetCalibrationStatus(ADC1)); /* FIN CALIBRACION REGS. - ADC_CR2.RSTCAL=0 */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CALIBRACION DEL ADC1 ~~~ */ ADC_StartCalibration(ADC1); /* COMIENZA LA CALIBRACION SELECCIONADA */ while(ADC_GetCalibrationStatus(ADC1)); /* CALIBRACION COMPLETADA - ADC_CR2.CAL=0 */ /* ~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION DE LA INTERRUPCION EOC DEL ADC1 ~~~ */ ADC_ClearITPendingBit(ADC1,ADC_IT_JEOC); /* BORRA JEOC bit ADC1_SR.EOC */ ADC_ITConfig(ADC1,ADC_IT_JEOC,ENABLE); /* HABILITA LA INTERRUPCION EOC */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ ADC_ExternalTrigInjectedConvCmd(ADC1, ENABLE); }
2011-05-17 05:05 AM
My next target is the follow. I want to be able to see in oscilloscope the ADC Time conversion
1.- Start the ADC conversion, and toggle one pin (I think watching the TIM1 ISR (I cant at this moment)).2.- Toggle this pin another time when the conversion finishes (Watching ADC ISR, I can do this).3.- Get the time with the oscilloscope. By this way i will have the ADC TiME conversion. My boss told me that he wants to see it in my oscilloscope.