2014-09-23 05:19 PM
Hello,
I'm implementing a high power buck converter using STM32F103C8. I need to measure voltage on 4 channels during each PWM period. I figured, that i will use ADC injected mode for this. Since PWM is being generated from TIM1, I'm triggering on TIM1-CH4 in an instant when I don't expect switching-related disturbances. What bothers me though, is that I'd like the ADC to convert all the selected channels as fast as it can and then wait for another trigger. Is there a way to do this? I have enabled scan mode, which I figured would do exactly that, but it seems that it only converts one channel and waits for another trigger event to happen before it converts another channel in sequence.2014-09-23 05:40 PM
Not sure why you'd need injected mode, scanning mode can be triggered to do multiple channels one after another, from a single trigger event. Scanning requires the use of DMA.
Scanning should be enabled, Continuous Mode should be disabled, and you should enumerate the channels/speed you wish the samples to be performed at.2015-05-06 01:47 AM
Good morning Clive,
1) I need to make continuous regular channel conversion in scan mode for two channels to read temperature and supply voltage of my board and to trigger two injected channel conversion using TIM4 update event. I need two conversions of the injected channels after a single T4 TRGO and to generate an interrupt when both conversions are finished.Unfortunately in scan mode the JEOC is generated after each conversion, but I need the interrupt when both two channels are converted. In discontinuous mode, instead, the interrupt is generated after two conversion are done, but unfortunately it is not possible to make two injected channel conversions per single T4 TRGO.ADC_DeInit(ADC1);
// ADC1 configuration // conversion time = sampling time + 12,5 cycles. ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 2; ADC_Init(ADC1, &ADC_InitStructure); // REGULAR CHANNEL // Vpow ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 1, ADC_SampleTime_1Cycles5); // Temperaure // The sampling time for temperature sensor analog input must be greater than 2.2 usec // 41,5 / 12 MHz = 3.5 usec ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 2, ADC_SampleTime_41Cycles5); ADC_TempSensorVrefintCmd(ENABLE); // Enable ADC1 DMA ADC_DMACmd(ADC1, ENABLE); // INJECTED CHANNEL // Configura la lunghezza della conversione ADC_InjectedSequencerLengthConfig(ADC1, 2); // Configura gli Injected channel ADC_InjectedChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_1Cycles5); ADC_InjectedChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_1Cycles5); // Configura il Trigger degli Injected channel ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T4_TRGO); // Abilita gli External Injected channel ADC_ExternalTrigInjectedConvCmd(ADC1, ENABLE); // Disabilita l'AUTOINJECTION ADC_AutoInjectedConvCmd(ADC1, DISABLE); // Abilita gli interrupt degli injected channels // Nota! essendo in scan mode, si generano due interrupt: uno per ogni canale ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE); // Enable ADC1 ADC_Cmd(ADC1, ENABLE); // Aspetto tstab di 1usec for(a=0; a < 72; ) {a++;} // Enable ADC1 ADC_Cmd(ADC1, ENABLE);2) TIM4 is configured in PWM mode CenterAligned. Is it possible to generate the output trigger TRGOonly
for counter overflow. At the moment it is generating the trigger at overflow and underflow.// Time Base configuration
TIM_TimeBaseStructure.TIM_Prescaler = 0; //Può essere 123 a seconda che gli Interupt Flags dei canali si vogliano abilitati quando si conta up, down od entrambi. TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned3; TIM_TimeBaseStructure.TIM_Period = T_PWM; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); // Channel 1, 2,3 and 4 Configuration in PWM mode //PWM mode 1 o 2 è solo una questione di segno. TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 0; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OC1Init(TIM4, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = 0; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC2Init(TIM4, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = 0; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC3Init(TIM4, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = 0; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC4Init(TIM4, &TIM_OCInitStructure); // Channel 1,2,3,4 Preload Config // Ci vuole oppure no? // TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable); // TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable); // TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable); // TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable); // Selects the update event as TRGO for TIM4 // Che farà campionare l'ADC TIM_SelectOutputTrigger(TIM4, TIM_TRGOSource_Update); TIM_Cmd(TIM4, ENABLE);2015-05-07 04:32 AM
I solved the problem of the ADC using dual mode.
It remains the problem of TIM4. How can I raise TRGO only for the upcounting overflow?Thanks,