Skip to main content
Visitor II
September 14, 2007
Question

No Debugging possible

  • September 14, 2007
  • 4 replies
  • 934 views
Posted on September 14, 2007 at 06:14

No Debugging possible

    This topic has been closed for replies.

    4 replies

    nikAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:46

    Hi,

    I am making myself familiar with the ADC as I will need it for a future project.

    Everything compiles fine and should work in my opinion. But when trying to debug (to see the ADC value), debugging is cancelled and after that I have to do an erase reset.

    As I am a beginner in uC programming, all information I got was the Software Library Doc and Reference Manual. It is not clear to me, whether I have to use a timer for the ADC.

    I am using MCBSTR9 from Keil with uVision.

    Any help is appreciated!

    Cheers

    Nik

    --- Code ---

    #include

    #include ''main.h''

    int main (void){

    u16 ADC_Conversion = 0;

    setup();

    ADC_ConversionCmd(ADC_Conversion_Start);

    wait(300);

    while(1){

    while(ADC_GetFlagStatus(ADC_FLAG_ECV)==RESET);

    ADC_Conversion = ADC_GetConversionValue(ADC_Channel_0);

    ADC_ClearFlag(ADC_FLAG_ECV);

    }

    return 0;

    }

    void setup(void){

    // Variables

    ADC_InitTypeDef ADC_Setup;

    GPIO_InitTypeDef GPIO_Setup;

    // Clocks

    SCU_MCLKSourceConfig(SCU_MCLK_OSC);

    SCU_PLLFactorsConfig(192,25,2);

    SCU_PLLCmd(ENABLE);

    SCU_MCLKSourceConfig(SCU_MCLK_PLL);

    SCU_PCLKDivisorConfig(SCU_PCLK_Div2);

    SCU_APBPeriphClockConfig(__ADC, ENABLE);

    SCU_APBPeriphClockConfig(__GPIO4, ENABLE);

    // Configuration

    ADC_DeInit();

    ADC_StructInit(&ADC_Setup);

    ADC_Setup.ADC_Channel_0_Mode = ADC_NoThreshold_Conversion;

    ADC_Setup.ADC_Conversion_Mode = ADC_Continuous_Mode;

    ADC_Cmd(ENABLE);

    ADC_PrescalerConfig(0x0);

    GPIO_DeInit(GPIO4);

    GPIO_StructInit(&GPIO_Setup);

    GPIO_Setup.GPIO_IPConnected = GPIO_IPConnected_Enable;

    GPIO_ANAPinConfig(GPIO_ANAChannel0, ENABLE);

    // Setup

    ADC_Init(&ADC_Setup);

    GPIO_Init(GPIO4, &GPIO_Setup);

    }

    void wait(int time){

    int count=0;

    time *= 100000; // time in ms

    while(count

    }

    [ This message was edited by: Liqnik on 13-09-2007 16:14 ]

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:46

    Your ADC clock might be running too fast. If I read the code correctly, it looks like your PLL is 96MHz, the PCLK is 48MHz, and ADC clock is 48MHz. The datasheets says the ADC is limited to 25MHz.

    [ This message was edited by: lakata on 14-09-2007 19:58 ]

    nikAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:46

    Hi,

    thanks for the hint. It solved part of the problem.

    I changed the prescaler to 0x2. As I am running the program now, it stucks in the while(ADC_GetFlagStatus(ADC_FLAG_ECV)==RESET)... I wonder why this flag does not get set. I do not need to configure an interrupt for it, do I?

    Cheers

    Nik

    nikAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:46

    Hi,

    to specify my question: is it possible at all to use the ADC without configuring interrupts? My understanding was, that the chip does produce some kind of hardware interrupt to set the ECV flag even when it is ''stuck'' in a software loop.

    --- pseudo code ---

    while(1){

    start_conversion();

    while(conversionflag not set) {wait}; // flag gets set in background when conversion is finished

    value = conversion(value);

    clear_flag(ECV);

    }

    --- end pseudo code ---

    Cheers

    Nik

    [ This message was edited by: Liqnik on 14-09-2007 09:45 ]

    2nd Edit:

    Never mind. I forgot to set the STR bit...

    [ This message was edited by: Liqnik on 14-09-2007 09:58 ]