Skip to main content
gdiez
Associate III
August 31, 2010
Question

EOC ADC INTERRUPT

Posted on August 31, 2010 at 09:51

EOC ADC INTERRUPT

    This topic has been closed for replies.

    15 replies

    gdiez
    gdiezAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:04

    ISR

    void ADC_IRQHandler(void)

    {  

        IT_tick=1;

        ADC1ConvertedValue = ADC1->DR; 

        ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);

    }

    //====================================================

    MAIN

    while(1){     

            if(IT_tick){

              IT_tick=0;        

             }

           

        } /* END of WHILE */

    //====================================================

    The programm doesn´t enter never in main if. In debug mode in step by step mode, as soon as the ISR finishes, the program enters again. If it would works ok, it must enter in it.

    If i have

    ADC_CR2.CONT=0 Continuous mode OFF

    The programs enters once in the ISR and stop. It enters with out EOC flag(??)

    It works like it must to do. I tried to start ADC conversion on ISR then but i cant.

    How could do i that?

    ADC_SR.STRT=1 // Regular channel Start Flag

     

    ADC_CR1.EOCIE=1 // Interrupt enable for EOC

     

    ADC_CR1.SCAN=1 // Scan mode enabled

     

    ADC_CR2.ADON=1 // A/D Converter ON

    ADC_CR2.EXTSEL=111 // External Event select for regular group = SWSTART

    ADC_CR2.EXTRIG=1 // Conversion on external event enabled

    In this moment NVIC registers are: See RM0008 (Vector table for connectivity line devices) ADC1_2 is position 18

    NVIC_ISR0.SETENA[18] = 1 // Interrupt ADC1_2 enabled

    NVIC_ICR0.CLRENA[18] = 1 // Interrupt ADC1_2 enabled.

    NVIC_IABR0.ACTIVE[18] = 1 // Interrupt ADC1_2 actived

    NVIC_ICPR0.CLRPEND[18] = 0 // Interrupt ADC1_2 no pending

    If i have

    ADC_CR2.CONT=1 Continuous mode ON

    The programs never leaves the ISR (Even step by step in debug mode). It never enters in main If. In normal mode I think it must do it. It enters with EOC flag

    ADC_SR.STRT=1 // Regular channel Start Flag

    ADC_CR1.EOCIE=1 // Interrupt enable for EOC

     

    ADC_CR1.SCAN=1 // Scan mode enabled

     

    ADC_CR2.CONT=1 // Continuous mode

     

    ADC_CR2.ADON=1 // A/D Converter ON

     

    ADC_CR2.EXTSEL=111 // External Event select for regular group = SWSTART

    ADC_CR2.EXTRIG=1 // Conversion on external event enabled

    NVIC_ISR0.SETENA[18] = 1 // Interrupt ADC1_2 enabled

    NVIC_ICR0.CLRENA[18] = 1 // Interrupt ADC1_2 enabled.

    NVIC_IABR0.ACTIVE[18] = 1 // Interrupt ADC1_2 actived

    NVIC_ICPR0.CLRPEND[18] = 1 // Interrupt ADC1_2 pending

    I´ve tried to clear ADC_SR.EOC( I cant). I´ve tried to set NVIC_ICPR[0].CLRPEND[18]=1 to clear the ADC pending bit but I couldn´t.

    If i have ADC_CR2.CONT=1:

    I cant write on ADC_SR Register in any way of do it.

    ADC1->SR = 0x0000001D;

    ADC1->SR & = 0x0000001D;

    ADC1->SR &=~ 0x00000002;

    gdiez
    gdiezAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:04

    Thks Litom:

    I´ve just post the same question in another post hehehe. I will try it and I will tell you. Thks for the help dude

    lipin
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:04

    It's still only 56 cycles but you should be able toquit isr and jump to main loop. Did you set a trap in main loop to check if itsreally not going into there?.  Also try increasing conversion time tocheck if its not really I am to slow in ISR problem.

    If you want behavior like in diagram above.

    1.

    Configure ADC to continuousmode off

    2.

        

    Start periodic 20kHz timer

    3.

        

    On timer update event start manually conversion ADC_RegularChannelConfig(ADC1,ADC_Channel_15, 1, ADC_SampleTime_1Cycles5);

    4.

        

    Wait for conversion by using EOC ISR

    5.

    When done (ISRevent) setup output compare registers to get desired pulses shape.

    Regards

    Thomas

    lipin
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:04

    Now I see that beginning is just initial condition.

    1.

    Configure ADC to continuousmode off

    2.

        

    Start periodic 20kHz timer

    3.

        

    Setup compare registers to trigger interrupt close to end of timer periodand start adc conversion.

    4.

    On timer updateevent or EOC read analog value and do whatever you want with this probablysetup another compare register to get desired pulse shape.

    Even more easy if you don’t need sampling in exactperiods of time. Run ADC in continuous mode forget about EOC flag and readvalue at the beginning of timer update event.

    First scenario is also not time accurate too becauseyou need to fire up conversion. As for timers I know there can be made hardwaresynchronization and I bet ADC is able to be externally triggered read docs ifyou need this kind of accuracy.

    Regards

    Thomas

    gdiez
    gdiezAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:04

    The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6WP&d=%2Fa%2F0X0000000bpp%2F4CVByy4Rhx0LO1RD2iySxXvk18ZW0lVJk8kYuRVTGDg&asPdf=false