need help with ADC conversion on timer one channel 4 capture compare

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

kaustubh_cds
Posts: 2
Joined: Fri Jun 30, 2023 9:58 am
Been thanked: 1 time

need help with ADC conversion on timer one channel 4 capture compare

Postby kaustubh_cds » Fri Sep 15, 2023 1:24 pm

Hello I'm new to ChibiOS. For a bldc motor control application I need to read the current values on timer 4 CC4 event (I am trying to reproduce https://community.st.com/t5/stm32-mcus-products/how-to-trigger-adc1-with-tim1-ch4/td-p/121581). My adc config group is as follows

Code: Select all

              static const ADCConversionGroup ADC_config_channel1 = {
                FALSE,                                                                                  /*NOT CIRCULAR*/
                NUM_CH,                                                                                 /*NUMB OF CHANNELS*/
                adc_callback,                                                                           /*ADC CALLBACK*/
                adc_callback_error,                                                             /*ADC ERROR CALLBACK*/
               ADC_CR1_JEOCIE ,                                                                         /* CR1 */
                ADC_CR2_JEXTEN_0 | (0b1001 << ADC_CR2_JEXTSEL_Pos) | ADC_CR2_ADON | ADC_CR2_DMA,        /* CR2 */
                0,                                                                                      /* SMPR1 */
                0,                                                                                      /* SMPR2 */
                0,                                                                                      /* SQR1 */
                0,                                                                                      /* SQR2 */
                0,                                                                                      /* SQR3 */
                ( 0x01 << ADC_JSQR_JSQ4_Pos)                                                              /* JSQR */
               
              };

and I have configured my timer 1 as follows

Code: Select all

    tim1 = STM32_TIM1;  /* gives direct access to the tim1 registers */
    tim1->CR1 |= STM32_TIM_CR1_CMS(3);
    TIM1->DIER = TIM_DIER_CC4IE;
    tim1->CCMR2 |= TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_0 | TIM_CCMR2_OC4PE;
    tim1->CCER |= (TIM_CCER_CC4E);
    tim1->BDTR |= ( TIM_BDTR_MOE );
    tim1->CCR[3] = tim1->ARR - 1;


I am calling the function adcStartConversion(&PHASE_B, &ADC_config_channel1, sample_buff_channel_1, NUM_SAMPLES) at regular intervals
but I keep receiving the ADC_ERR_DMAFAILURE in my error callback. How can I properly trigger the ADC read on the timer event? Also am I required to configure the DMA for the same?

User avatar
Giovanni
Site Admin
Posts: 14458
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: need help with ADC conversion on timer one channel 4 capture compare

Postby Giovanni » Fri Sep 15, 2023 2:06 pm

Hi,

Look at the example in /testhal/STM32/multi/ADC, you may start from the configurations under ./cfg/xxxxxxxxxx/portab.c

Giovanni

kaustubh_cds
Posts: 2
Joined: Fri Jun 30, 2023 9:58 am
Been thanked: 1 time

Re: need help with ADC conversion on timer one channel 4 capture compare

Postby kaustubh_cds » Tue Sep 19, 2023 10:09 am

Hello thanks for the reference,

I ended up using regular channels and had not enabled circular buffer.
Final adc configuration i was able to get working was

Code: Select all

static const ADCConversionGroup ADC_config_channel = {
                TRUE,                                                                                                   /*NOT CIRCULAR*/
                NUM_CH,                                                                                                 /*NUMB OF CHANNELS*/
                adc_callback,                                                                                           /*ADC CALLBACK*/
                adc_callback_error,                                                                                     /*ADC ERROR CALLBACK*/
                ADC_CR1_SCAN | ADC_CR1_EOCIE,                                                                           /* CR1 */
                ADC_CR2_ADON | ADC_CR2_SWSTART |ADC_CR2_CONT |ADC_CR2_EXTEN_0 | (0b1001 << ADC_CR2_EXTSEL_Pos) ,        /* CR2 */
                0,                                                                                                      /* HTR */
                0,                                                                                                      /* LTR */
                0,                                                                                                      /* SMPR1 */
                ADC_SMPR2_SMP_AN0(ADC_SAMPLE_15) | ADC_SMPR2_SMP_AN1(ADC_SAMPLE_15) | ADC_SMPR2_SMP_AN2(ADC_SAMPLE_15), /* SMPR2 */
                  (NUM_CH-1)<<20,                                                                                       /* SQR1 */
                0,                                                                                                      /* SQR2 */
                ADC_SQR3_SQ1_N(ADC_CHANNEL_IN0) | ADC_SQR3_SQ2_N(ADC_CHANNEL_IN1) | ADC_SQR3_SQ3_N(ADC_CHANNEL_IN2) ,   /* SQR3 */
                };


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 5 guests