AnsweredAssumed Answered

stm32f103 - minimize delay due to usart transfer

Question asked by anton.bogdan on Feb 4, 2017
Latest reply on Feb 4, 2017 by anton.bogdan

Hello all,

 

i am using a stm32f103c8t6 device, clocked at 72 MHZ,   the periph clock for adc is 12MHZ  ( 72/6).   

 

Using  adc injected function with  sample time configured  at ADC_SampleTime_1Cycles5

 

Timer 1 is generating a pwm wave on channel 4 ( CC4), and the cc4 signal is feed out trough TRGO and onto the ADC injection trigger input.

 

Till here everything works as expected, i have the correct voltage when reading the injection.

 

 

My "without USART"  ADC interrupt handler.... looks like this ,   on the logic analyzer judging by the gpio toogle time, this routine runtime takes arround 1us to run.

 

void ADC1_2_IRQHandler(void)
{
if(ADC_GetITStatus(ADC1,ADC_IT_JEOC)){ /* Set PC.06 pin */

GPIOB->BRR = GPIO_Pin_11; // reset
GPIOB->BSRR = GPIO_Pin_11;// set
myadc = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1);
ADC_ClearITPendingBit(ADC1, ADC_IT_JEOC);

GPIOB->BRR = GPIO_Pin_11; // reset

}
}

 

 

But... i want to send the ADC value to my pc using usart connection... so i had some usart function inserted into the adc jeoc event.... 

So after each injection end of conversion... i  send the data via usart at a baudrate of 460800bps... but i want the full 16bit value to be sent to the pc...

Ok said and done,   the adc channel is tied to a 3.3v signal,   on the usart i have 4093 decimal which is corect if i do the math...

But the problem which occures is the increase of adc irq handler runtime from 1us to 100us which is huge.... and its screwing up my pwm signals ( see screenshot bellow)

 

 

The adc channel is reading a shunt resistor which is coming from a 3 phase FET stage for a bldc, so i need feedback to the pc as fast as posible....

 

For example if i send usart to the pc which  takes 100us... in this time  i will have many pwm pulses where i can have overcurrent fault....

 

So i need to send feedback as fast as posible when reading the first pwm pulse on each of the 3 phases (or 3 pwm high side signals)

 

Is it posible to send usart data faster? without afecting the adc irq timing?  Some ideas would be wellcomed

 

Thanks

Outcomes