2011-06-15 01:15 AM
Hi,
Using STM32F103. I want to use the external trigger mode of the ADC to start a regular group of channels (in dual, simultaneous mode) via the TIM4 CC4 Event. The examples that ST provide illustrate using TIM1 CC1 event using a pwm OUTPUT channel to trigger the ADC. I wish to trigger my regular channels via INPUT capture on TIM4 channel4. Is this possible? The documentation seems to suggest so. I have tried using a basic example, but to no avail. The TIMER4 input capture event occurs, but doesn't trigger the ADC. I can manually trigger the ADC via software, so am not sure what could be wrong. Is there some trick that I am missing here? Is there an example someone could send me? Also note that I am doing a full remapping TIMER 4 pins. I'm using my own code - not using the library, so have not got any code to fully illustrate this yet, sorry. Any ideas would be most welcome. Thanks, #adc-trig-in-dual-mode #poor-quality-of-documentation2011-06-15 07:44 AM
TIM4_CC4 should be viable (TIMER 4 CHANNEL 4)
You'll need to program ADC1->CR2, with EXTSEL[2:0] = 5 (101) /* TIM4 configuration ------------------------------------------------------*/ /* Time Base configuration */ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 0xFF; TIM_TimeBaseStructure.TIM_Prescaler = 0x4; TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); /* TIM4 channel4 configuration in PWM mode */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 0x7F; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC4Init(TIM4, &TIM_OCInitStructure); .. /* ADC1 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T4_CC4; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); ..2011-06-15 08:06 AM
Hi Clive,
Thanks for that. I've tried that and it works. However, the lines: /* TIM4 channel4 configuration in PWM mode */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 0x7F; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC4Init(TIM4, &TIM_OCInitStructure); set the timer into output compare mode. According to the ADC section in the reference manual, the event from the timer Capture/Compare triggers the ADC - which works in the example you posted. However, in input capture mode (which I need), the TIM4_CC4 event caused doesn't trigger the ADC. The input capture event definitely happens, because the timer count is latched. I think the timer can only externally trigger the ADC in output compare mode, not input capture. I am changing my hardware to trigger the ADC via EXTernal Interrupt 11, rather than TIM4_CC4. This should solve my problem - I hope!! Thanks, Stuart2011-06-15 10:44 AM
Without spending hours digging through the timer documentation/diagrams, I would imagine the following would a) get a time stamp in CCR4, b) initiate an ADC conversion, with a rising edge on the TIM4_CC4 pin.
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInit(TIM4, &TIM_ICInitStructure); /* TIM enable counter */ TIM_Cmd(TIM4, ENABLE); .. I'm not sure if the CC trigger on the ADC has an pulse width requirements, or what's generated in this case. Now that would also assume you have the IO pin configured, and remapped. GPIOD and AFIO clocks enabled too. /* TIM4 Full remapping pins */ GPIO_PinRemapConfig(GPIO_Remap_TIM4, ENABLE); /* TIM4 channel 4 pin (PD.15) configuration - remapped */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure);2014-02-09 08:43 PM
Hi stuart , I am facing the same issue. Can you help me if you got the solution
2014-02-10 12:04 AM
I wouldn't be surprised if the description of ADC triggers in RM0008 is wrong, and in fact it won't act upon a TIMx_CCy event as depicted on the timers' block diagram (i.e. which is generated from both capture and compare), rather, on the TIMx_OCy signal.
If this is the case, you still should be able to trigger an injected conversion on ADC1 and ADC2 from the TIM4_TRGO signal (ADC_CR2.JEXTSEL = 101), which in turn can be tied to TIM4_CH1 capture, if TIM4_CR2.MMS is set to 011 (Compare Pulse). I did not try any of these, though; this all is based entirely on manual reading. JW2014-02-10 01:57 AM
2014-02-10 04:30 AM
Sanjib, you are hereby awarded the Leon Tolstoy prize for the longest post. Let us say nothing of its contents.
2014-02-10 08:18 AM
2014-02-10 08:31 AM
TIM_TRGOSource_OC1
Now not only is ''Compare Pulse'' a confusing name for TRGO being driven from CC1IF (i.e. both capture and compare), it's even more confusing to name the related constant ''_OC1''.
Sorry, but this is why when it comes to the ''library'', I can't think of any other adjective than ''idiotic''.
JW