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-documentation2014-02-10 08:41 AM
The plumbing at least seems to work...
I could perhaps have gone the ADC_ExternalTrigConv_T2_CC2 route, of the EXTI via ADC_ExternalTrigConv_Ext_IT112015-02-21 09:14 AM
hi Mr. clive1
tanks of help you for ourI use stm32f103 serise mcuI want config adc1&2 in dual mode with tim4_cc triger mode without use an external pin.I want confirm it such as internal event. because i use all I/O pins and now has not extra pin. how can I do it?2015-02-21 03:46 PM
I've not used F1 parts in recent years. As I recall the External is name for all sources outside the ADC, I don't believe a TIM in timebase/output compare actually needs to get to the pins, but you might want to check the Remapping settings so as not to conflict with other uses. A port configured as a GPIO definitely wouldn't have an issue.
In your case using ADC_ExternalTrigConv_T4_CC4 ie TIM4 Channel 42015-03-04 11:34 AM
Hi Mr. Clive1
tanks of your answer. I want config ADC1&2 in dual mode with TIM4_CC4 Trig and Read result in ADC1_EOC. but it dont work. I copy my code here please help me about it. I use STM32F103 tanks void MyADC_Init(void) { NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; ADC_InitTypeDef ADC_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; /* Enable ADC1 and GPIOC clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_GPIOC, ENABLE); /* Enable TIM4 clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); /* Configure PC.04(ADC1 Channel4) & PC.05(ADC2 Channel5) as analog input -------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOC, &GPIO_InitStructure); /* PCLK2 is the APB2 clock */ /* ADCCLK = PCLK2/6 = 72/6 = 12MHz*/ RCC_ADCCLKConfig(RCC_PCLK2_Div6); /* TIM4 configuration for ADC Tigger------------------------------------------------------*/ /* Time Base configuration main CLK=72 MHz Timer Trig 200 Hz */ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 0x63; //=99 TIM_TimeBaseStructure.TIM_Prescaler = 0xE10; //=3600 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_Disable; TIM_OCInitStructure.TIM_Pulse = 0x30; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC4Init(TIM4, &TIM_OCInitStructure); /* ADC1 configuration ------------------------------------------------------*/ /* ADC1 and ADC2 operate in dual mode */ ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; /* Disable the scan conversion so we do one at a time */ ADC_InitStructure.ADC_ScanConvMode = DISABLE; // Single Channel /* Don't do contimuous conversions - do them on demand */ ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // Scan on Demand /* Start conversin T4_CC4 */ ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T4_CC4; /* Conversions are 12 bit - put them in the lower 12 bits of the result */ ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; /* Say how many channels would be used by the sequencer */ ADC_InitStructure.ADC_NbrOfChannel = 1; /* Now do the setup */ ADC_Init(ADC1, &ADC_InitStructure); /* ADC2 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T4_CC4; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC2, &ADC_InitStructure); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Enable ADC2 */ ADC_Cmd(ADC2, ENABLE); ADC_ResetCalibration(ADC2); while(ADC_GetResetCalibrationStatus(ADC2)); ADC_StartCalibration(ADC2); while(ADC_GetCalibrationStatus(ADC2)); //ADC1&2 regular channelx configuration ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_15, 1, ADC_SampleTime_55Cycles5); //ADC_DiscModeCmd(ADC1, ENABLE); // Configure and enable ADC interrupt NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); /* Enable ADC1 external trigger conversion */ ADC_ExternalTrigConvCmd(ADC1, ENABLE); ADC_ExternalTrigConvCmd(ADC2, ENABLE); TIM_Cmd(TIM4, ENABLE); } ________________ Attachments : TimTrigADC.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0dK&d=%2Fa%2F0X0000000bbd%2FbiDUj5vfexENz7MZT3vCzvrWfQMdEENIkknRvAepzfA&asPdf=false2015-03-04 12:26 PM
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable; // Pretty sure this needs to be enabled
2015-03-04 02:20 PM
But I do not want to be connected to the output port
In fact I have not Additional pins to assign to its port2015-03-04 02:23 PM
Is this command makes the link between the output port and OC1 signal
2015-03-04 03:28 PM
Ok, assume for a second I don't know exactly which part you're using, how many pins it has and which pins you are using in your design.
So if PB9 isn't usable you'll need to REMAP TIM4 so the outputs go into the D bank. TIM4_CH4 remaps to PD15. Enable the AFIO and remap the timer. If that's not workable, then you'll have to think about what other resources you have available in your design, and provide enough foundation in your question for me to work with.2015-03-05 12:44 AM
Hi Mr Clive1
Tanks of your answerI have used all of the I/O pins for ADC,DAC,PWM IN,PWM OUT, Graphical LCD ILI9325, Keyboard ,Quadrature Encoder, &... .I want control this system with the lowest interrupt and most existing hardware which can be linked together and control a sequence without software intervention as much as possible. because i have any other interrupt for key board & ... .Now I want read the output voltage and current simultaneously and periodic every 2 ms equal to 500 Hz. (keyboard Interrupt generate every push & release, RS232 generate interrupt in receive data unknown time, & quadrature encoder &... also )2015-05-24 09:07 AM