Menu

EOC ADC FLAG

2010-09-01
2013-04-06
  • Nobody/Anonymous

    Hi Guys:

    I know that it isn´t the apropiate forum to ask that but I´m getting a bit frustrated about it. Maybe someone knows about it.

    I enter in ADC1 IRQ in EOC. I´m trying to clear this flag in the ISR, but I can´t, and my program stays allways in the ISR. My code is the follow and my micro is STM32f103

    void ADC_IRQHandler(void)
    {
       ADC1ConvertedValue = ADC1->DR;   /* Dato convertido */
    ADC_ClearITPendingBit(ADC1, ADC_IT_EOC); /* Clear ADC1 EOC pending interrupt bit */  
    }
    

    Must I have to write another Register??

     
  • Giovanni Di Sirio

    Reading the DR should clear that bit, it is possible you also have enabled the JEOC and AWD interrupts and you have to clear those too.

    Also, if you programmed a continuous conversion then the ADC continues to generate interrupts at high rate, you have to stop the ADC too or program the single conversion mode.

    Giovanni

     
  • Gerardo Diez

    Gerardo Diez - 2010-09-02

    Hi Giovanni:
    First of all, thanks for replying.

    Your answer is completly true. The RM0008 says that there are 2 ways os clearing EOC flag.

    1.- Reading the ADCx_DR
    2.- Or clearing directly ADCx_SR.EOC

    In my programm there arn´t any other flag set in the moment that enters in the ISR.

    void ADC_configuration(void)
    {
      ADC_InitTypeDef ADC_InitStructure;
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE); 
      ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;                    
      ADC_InitStructure.ADC_ScanConvMode = ENABLE;                           
      ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;                   
      ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;   
      ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;                 
      ADC_InitStructure.ADC_NbrOfChannel = 1; 
      ADC_Init(ADC1, &ADC_InitStructure);
      ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_1Cycles5);  
      ADC_Cmd(ADC1, ENABLE);                   
      ADC_ResetCalibration(ADC1);              
      while(ADC_GetResetCalibrationStatus(ADC1));    
      ADC_StartCalibration(ADC1);                   
      while(ADC_GetCalibrationStatus(ADC1));      
      ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE);         
      ADC_SoftwareStartConvCmd(ADC1, ENABLE);       
    }
    
     
  • Gerardo Diez

    Gerardo Diez - 2010-09-02

    MAIN.C
    /******************** (C) COPYRIGHT 2010 IKOR Technology centre ****************
    * File Name          : main.c
    * Author             : Gerardo Díez del Campo
    * Version            : V1.0
    * Date               : 13/07/2010
    * Description        : Define main module.
    *******************************************************************************/
    #include <intrinsics.h>
    #include "stm32f10x_lib.h"

    extern void Peripheral_configuration(void);
    void Refresco_PWM(TIM_TypeDef* TIMx, TIM_TypeDef* TIMx2, unsigned int);
    extern vu16 ADC1ConvertedValue;                             /* Valores entre  */
    extern vu8 IT_tick;
    /* =============================================================================
    * Function Name  : Main
    * Description    :
    ============================================================================= */
    void main(void)
    {

      Peripheral_configuration();
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WHILE ~~~~ */
        while(1){

         
            if(IT_tick){
              IT_tick=0;
             }
           
        } /* END of WHILE */
       /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    }
    /*************** (C) COPYRIGHT 2010 IKOR Technology centre *****END OF FILE****/

    TOOLS.C

    /******************** (C) COPYRIGHT 2010 IKOR Technology centre ****************
    * File Name          : TOOLS.c
    * Author             : Gerardo Díez del Campo
    * Version            : V1.0
    * Date               : 13/07/2010
    * Description        : Libreria funciones de configuración de periféricos.
    *******************************************************************************/
    /* Includes ------------------------------------------------------------------*/
    #include "TOOLS.h"
    //extern u16 DutyCycle_TIM3_Channel1;  /* Define el duty cycle en el main */
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : Peripheral_configuration
    * Description    : Agrupamiento de las distintas funciones de configuración.
    ============================================================================= */
    /* ====================================================================================================================================== */
    void Peripheral_configuration(void)
    {
      CLK_configuration();  
      NVIC_configuration();  
      GPIO_configuration();
      TIMER_configuration(); 
      ADC_configuration();   
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : GPIO_configuration
    * Description    : Configuración del GPIO.
    ============================================================================= */
    /* ====================================================================================================================================== */
    void GPIO_configuration(void)
    {
      GPIO_InitTypeDef GPIO_InitStructure;  
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */   
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~ OUTPUT PWM PINS ~~~~~ */
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);   /* ENABLE CLK PORTS */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, DISABLE);    /* NO RESET PORTS */  
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;      /* MAX VEL ESCRITURA */
      GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_AF_PP;           /* OUT PUSH-PULL */
      GPIO_InitStructure.GPIO_Pin =   GPIO_Pin_7 | GPIO_Pin_9;        
      GPIO_Init(GPIOA, &GPIO_InitStructure); 
      GPIO_InitStructure.GPIO_Pin =   GPIO_Pin_7;
      GPIO_Init(GPIOC, &GPIO_InitStructure);  
      /* ~~~~~ OUTPUT DIGITAL PINS ~~~~~ */
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;           /* OUT PUSH-PULL */
      GPIO_InitStructure.GPIO_Pin =   GPIO_Pin_4;
      GPIO_Init(GPIOA, &GPIO_InitStructure);  
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~ INPUTS ADC PINS ~~~~~ */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
      GPIO_Init(GPIOC, &GPIO_InitStructure);
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : ADC_configuration
    * Description    : Configuración del ADC.
    ============================================================================= */
    /* ====================================================================================================================================== */
    void ADC_configuration(void)
    {
      ADC_InitTypeDef ADC_InitStructure;
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE); /* HABILITA ADC1 clock */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION DEL ADC1 ~~ */  
      ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;                     /* ELIGE EL MODO DE OPERACION - ADC_CR1.DUALMOD */
      ADC_InitStructure.ADC_ScanConvMode = ENABLE;                           /* HABILITA MODO SCAN (GRUPO DE CANALES) - ADC_CR1.SCAN */
      ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;                     /* DESHABILITA EL MODO CONTINUO - ADC_CR2.CONT */
      ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;    /* HABILITA TRIGGER POR SOFTWARE - ADC_CR2.EXTSEL */
      ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;                 /* ALINEACION A LA DERECHA - ADC_CR2.ALIGN */
      ADC_InitStructure.ADC_NbrOfChannel = 1;                                /* NUMERO DE CANALES DEL GRUPO */
      ADC_Init(ADC1, &ADC_InitStructure);
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION DEL ADC1 ~~ */  
    /* SELECCION DEL SAMPLE TIME - ADC_SMPR2.SMPx, SELECCION SECUENCIA REGULAR - ADC_SQR1 */
    /* ~~~~~~~~~~~~~~~~~~ ADC conversion Time = Sampling Time + 12,5 cycles ~~~~~ */  
      ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_1Cycles5);  
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HABILITACION DEL ADC1 DMA */
    //  ADC_DMACmd(ADC1, ENABLE);                      /* HABILITACION DIRECT MEMORY ACCESS MODE - ADC_CR2.DMA */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HABILITACION DEL ADC1 ~~~ */
      ADC_Cmd(ADC1, ENABLE);                         /* HABILITA CONVERSION/CALIBRACION Y DESPIERTA AL ADC - ADC_CR2.ADON */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RESETEO DEL ADC1 ~~~~~~~ */
      ADC_ResetCalibration(ADC1);                    /* INICIALIZA LOS REGISTROS DE CALIBRACION - ADC_CR2.RSTCAL */         
      while(ADC_GetResetCalibrationStatus(ADC1));    /* CALIBRACION REGISTROS COMPLETADA - ADC_CR2.RSTCAL=0 */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CALIBRACION DEL ADC1 ~~~ */
      ADC_StartCalibration(ADC1);                    /* COMIENZA LA CALIBRACION SELECCIONADA */
      while(ADC_GetCalibrationStatus(ADC1));         /* CALIBRACION COMPLETADA - ADC_CR2.CAL=0 */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION DE LA INTERRUPCION EOC DEL ADC1 ~~~ */  
      ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE);          /* HABILITA LA INTERRUPCION EOC */
      
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */   
      ADC_SoftwareStartConvCmd(ADC1, ENABLE);        /* START CONVERSION DEL ADC1 - ADC_CR2.SWSTART y ADC_CR2.EXTTRIG */
    
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : TIMER_configuration
    * Description    : Configuración del TIMER.
    ============================================================================= */
    /* ====================================================================================================================================== */
    void TIMER_configuration(void)
    {  
      TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
      TIM_OCInitTypeDef  TIM_OCInitStructure;  
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TIM1 INIT ~~~ */   
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);   /* RCC_APB2ENR.TIM8EN ENABLE CLK TIM8 */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3,DISABLE);  /* RCC_APB2RSTR.TIM3RST RESET TIM8 */  
      
      
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_TIM8,ENABLE);   /* RCC_APB2ENR.TIM8EN ENABLE CLK TIM8 */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_TIM8,DISABLE);  /* RCC_APB2RSTR.TIM3RST RESET TIM8 */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */  
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION TIM8 20kHz ~~ */ 
      #define Prescala 1      /* Maximo 65536 */
      #define Periodo 2799    /* Maximo 65536 */
      TIM_TimeBaseStructure.TIM_Prescaler = Prescala-1;           /* DIVIDE EL CK_CNT=CK_PSC/(TIMx_PSC+1) - TIMx_PSC */
      TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down; /* MODO DE CONTADOR - TIM_CR1.DIR */
      TIM_TimeBaseStructure.TIM_Period = Periodo;                 /* NUMERO DE PULSOS A CONTAR DE CK_CNT - PERIODO TIMx_ARR */
      TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;     /* PARA FILTROS DIGITALES - TIM_CR1.CKD */
      TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;         /* TIM_RCR */ 
      TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);   
      TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
      TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ 
     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PWM1 Mode configuration: Channel2 ~~ */
      /* PWM1 Mode configuration: Channel2 */
      TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;   /* ELIGE EL MODO PWM */
      TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
      TIM_OCInitStructure.TIM_Pulse = 0;                            /* Duty Cycle */
      TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
      
     // TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
      
    //  TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
    //  TIM_ARRPreloadConfig(TIM3, ENABLE);
      TIM_OC2Init(TIM3, &TIM_OCInitStructure);
      TIM_OC2Init(TIM1, &TIM_OCInitStructure);
      TIM_OC2Init(TIM8, &TIM_OCInitStructure);
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ 
      
      TIM_Cmd(TIM3,ENABLE);                                     /* ENCENDIDO TIM1 */
      TIM_Cmd(TIM1,ENABLE);                                     /* ENCENDIDO TIM1 */
       TIM_Cmd(TIM8,ENABLE);                                     /* ENCENDIDO TIM1 */
      TIM_CtrlPWMOutputs(TIM1, ENABLE);                /* TIM1 Main Output Enable */
      TIM_CtrlPWMOutputs(TIM8, ENABLE);                /* TIM1 Main Output Enable */
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : CLK_configuration
    * Description    : Configuración del Nested vectored interrupt.
    ============================================================================= */
    /* ====================================================================================================================================== */
    void CLK_configuration (void)
    {
      /* RCC system reset(for debug purpose) */
      RCC_DeInit();
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HSI RC (8 MHz) ~~~~ */
      RCC_HSICmd(ENABLE);                                 /* ENABLE/DISABLE RCC_CR.HSION - INTERNAL 8MHz OSCILLATOR ON */
      while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET); /* WAIT TO HARDWARE OFF */
      RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);             /* MODIFICA RCC_CFGR.SW - ELIGE EL HSI COMO SYSCLK SOURCE */
      
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HSE_Value (8 MHz) stm32f10x_conf.h ~~~~ */
      RCC_HSEConfig(RCC_HSE_ON);                           /* ON/OFF RCC_CR.HSEON - EXTERNAL 8MHz OSCILLATOR ON */
      while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET); /* WAIT TO HARDWARE OFF */
      
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PHASE LOOP LOCKED PLLCLK->56MHz ~~~~ */ 
    /* ~~~~~~~~~~~~~~~~~~ Se elige 56MHz para tener ADC CONVERSION TIME=1uS ~~~~~ */
      RCC_PLLCmd(DISABLE);                                   /* ENABLE/DISABLE RCC_CR.PLLON */
      RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_7);   /* SYSCLK=56MHZ- RCC_CFGR.PLLSRC=1, RCC_CFGR.PLLXRPRE=0 y RCC_CFGR.PLLMULL=0101 */ 
      RCC_PLLCmd(ENABLE);                                   /* ENABLE/DISABLE RCC_CR.PLLON */
      while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* WAIT TO HARDWARE OFF */
      
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SYSTEM CLOCK SYSCLK=56MHZ HCLK=56MHZ ~~~~ */
      RCC_ADCCLKConfig(RCC_PCLK2_Div4);   /* RELOJ DEL ADC PCLK2/2=14MHz - CONFIGURE RCC_CFGR.ADCPRE */
      RCC_PCLK2Config(RCC_HCLK_Div1);     /* APB2 PCLK2 = 56MHz CONFIGURE RCC_CFGR.PPRE2 */
      RCC_PCLK1Config(RCC_HCLK_Div2);     /* APB1 PCLK1 = 28MHz CONFIGURE RCC_CFGR.PPRE1 */
      RCC_HCLKConfig(RCC_SYSCLK_Div1);    /* AHB  HCLK  = 56MHz CONFIGURE RCC_CFGR.HPRE  */
      
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ 
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EMB_FLASH ~~~~ */ 
    #ifdef EMB_FLASH
      // 5. Init Embedded Flash
      // Zero wait state, if 0 < HCLK 24 MHz
      // One wait state, if 24 MHz < HCLK 56 MHz
      // Two wait states, if 56 MHz < HCLK 72 MHz
      // Flash wait state
      FLASH_SetLatency(FLASH_Latency_2);
      // Half cycle access
      FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable);
      // Prefetch buffer
      FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
    #endif // EMB_FLASH
      
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      // 5. Clock system from PLL
      RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);  /* SELECCIONA EL CLOCK DEL PLL - MODIFICA RCC_CFGR.SW */ 
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : NVIC_configuration
    * Description    : Configuración del Nested vectored interrupt.
    ============================================================================= */
    /* ====================================================================================================================================== */
    void NVIC_configuration(void)
    {
       NVIC_InitTypeDef NVIC_InitStructure;
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */   
    #ifndef  EMB_FLASH
      NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);      /* Set the Vector Table base location at 0x20000000 */
    #else    
      NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);    /* Set the Vector Table base location at 0x08000000 */
    #endif
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ 
     /* Configure and enable ADC interrupt */
      NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQChannel;
      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
      NVIC_Init(&NVIC_InitStructure);  
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : DMA_configuration
    * Description    : Configuración del DMA.
    ============================================================================= */
    /* ====================================================================================================================================== */
    void DMA_configuration(void)
    {  
    }
    /*************** (C) COPYRIGHT 2010 IKOR Technology centre *****END OF FILE****/
    
     
  • Gerardo Diez

    Gerardo Diez - 2010-09-02

    When the program finishes of executing Peripheral_configuration() the ADC Registers are like it follows:

    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
    EDC_CR2.EXTRIG=1           // Conversion on external event enabled

    Then the program enters in the ISQ without setting the EOC flag (A great mistery). I think that is because
    ADC1_CR2.CONT=0

     
  • Gerardo Diez

    Gerardo Diez - 2010-09-02

    In this moment NVIC registers are:

    See RM0008 (Vector table for connectivity line devices)
    ADC1_2 is position 18

    NVIC_ISR0.SETENA = 1       // Interrupt ADC1_2 enabled
    NVIC_ICR0.CLRENA = 1      // Interrupt ADC1_2 enabled.
    NVIC_IABR0.ACTIVE = 1      // Interrupt ADC1_2 actived
    NVIC_ICPR0:CLRPEND = 0   // Interrupt ADC1_2 no pending

     
  • Gerardo Diez

    Gerardo Diez - 2010-09-02

    If my ADC configuration is different it works like follows:
    NOW I start the ADC with ADC_CR2.CONT=1

    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

    Then the program enters in the ISQ with setting the EOC flag (That´s the difference with the other configuration).

    Now NVIC is:

    NVIC_ISR0.SETENA = 1 // Interrupt ADC1_2 enabled
    NVIC_ICR0.CLRENA = 1 // Interrupt ADC1_2 enabled.
    NVIC_IABR0.ACTIVE = 1 // Interrupt ADC1_2 actived
    NVIC_ICPR0:CLRPEND = 1 // Interrupt ADC1_2 no pending

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

    My programm don´t go out from ISR and stills there all time. I do it in DEBUG mode, and stills without going out from there.

     
  • Giovanni Di Sirio

    Too big for an accurate analysis but I don't see the AFIO clock setup, are you sure it is not needed?

     
  • Giovanni Di Sirio

    You could also not use any interrupt, just make the ADC DMA write samples in a memory location continuously and without any interruption (select a low sample rate).
    Your PWM can simply read the latest value in memory and don't even bother to synchronize.

     
  • Gerardo Diez

    Gerardo Diez - 2010-09-02

    Ok. I will do it. I´ve to speak with my overhead.
    My target is the follow:

    1.- Take ADC values with 1uS conversion time with an 20KHz frecuency.
    2.- Launch the PWM with the same frecuency, but with the obviously Time conversion delay.
    3.- My boss want 1 ADC value, 1 Completly PWM period. He says that the project needs this synchro.

     
  • Gerardo Diez

    Gerardo Diez - 2010-09-03

    I´ve solve the problem. I have triggered the ADC with Tim3, and then it works ok, my programs leaves the ADC DIABOLIC ISR. Thks for your hel Giovanni. Here goes the code.

    MAIN.C

    main.c
    /******************** (C) COPYRIGHT 2010 IKOR Technology centre ****************
    * File Name          : main.c
    * Author             : Gerardo Díez del Campo
    * Version            : V1.0
    * Date               : 13/07/2010
    * Description        : Define main module.
    *******************************************************************************/
    /* Includes ------------------------------------------------------------------*/
    #include <intrinsics.h>
    #include "stm32f10x_lib.h"
    #include "TOOLS.h"
    /* Imported variables --------------------------------------------------------*/
    extern vu16 ADC1ConvertedValue;                     /* Valores entre [0~4095] */
    extern vu8 IT_ADC_tick;                             /* Flag ejecucion ISR ADC */
    /* Imported functions --------------------------------------------------------*/
    /* =============================================================================
    * Function Name  : Main
    * Description    : Enciende 1 Led por PWM [PA.09] mediante el ADC1 [PC.05].
    ============================================================================= */
    [b]void main(void)[/b]
    { 
      Peripheral_configuration();
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WHILE ~~~~ */
        while(1){     
            if(IT_ADC_tick){
              IT_ADC_tick=0;
    //          Chequeo_frecuencia(GPIOA,GPIO_Pin_4,1); // ONLY TO CHECK THE CORRECT LEAVE OF ISR
              } /* END of if(IT_ADC_tick) */
          
        } /* END of WHILE */
       /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    } /* END of MAIN */
    /* =============================================================================
    ============================================================================= */
    /*************** (C) COPYRIGHT 2010 IKOR Technology centre *****END OF FILE****/
    

    TOOLS.C

    /******************** (C) COPYRIGHT 2010 IKOR Technology centre ****************
    * File Name          : TOOLS.c
    * Author             : Gerardo Díez del Campo
    * Version            : V1.0
    * Date               : 13/07/2010
    * Description        : Libreria funciones de configuración de periféricos.
    *******************************************************************************/
    /* Includes ------------------------------------------------------------------*/
    #include "TOOLS.h"
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : Peripheral_configuration
    * Description    : Agrupamiento de las distintas funciones de configuración.
    ============================================================================= */
    /* ====================================================================================================================================== */
    [b]void Peripheral_configuration(void)[/b]
    {
      CLK_configuration(); 
      NVIC_configuration(); 
      GPIO_configuration();
      TIMER_configuration();
      ADC_configuration();  
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : GPIO_configuration
    * Description    : Configuración del GPIO.
    ============================================================================= */
    /* ====================================================================================================================================== */
    [b]void GPIO_configuration(void)[/b]
    {
      GPIO_InitTypeDef GPIO_InitStructure; 
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */  
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GPIO CLKS ~~~~~~~~~~~ */ 
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);   /* ENABLE CLK PORTS */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, DISABLE);    /* NO RESET PORTS */ 
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OUTPUTS ~~~~~~~~~~~~ */
      /* ~~~~~ PWM OUTPUT PINS ~~~~ [PA.09] ~~~~~~~~~~~~~~  */
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;      /* MAX VEL ESCRITURA */
      GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_AF_PP;       /* OUT PUSH-PULL */
      GPIO_InitStructure.GPIO_Pin =   GPIO_Pin_9;           
      GPIO_Init(GPIOA, &GPIO_InitStructure);
    
      /* ~~~~~ DIGITAL OUTPUT PINS ~~~~ [PA.04~PA.05] ~~~~~ */
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;           /* OUT PUSH-PULL */
      GPIO_InitStructure.GPIO_Pin =   GPIO_Pin_4 | GPIO_Pin_5;
      GPIO_Init(GPIOA, &GPIO_InitStructure);
    
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INPUTS ~~~~~~~~~~~~ */
      /* ~~~~~ DIGITAL INPUTS PINS ~~~~ [PC.04] ~~~~~~~~~~ */
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;           /* IN PULL-DOWN */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;           /* CONFIGURACIÓN PIN 4 */ 
      GPIO_Init(GPIOC, &GPIO_InitStructure);                /* CONFIGURACION PC.4 */
    
      /* ~~~~~ ADC INPUTS PINS ~~~~ [PC.05] ~~~~~~~~~~~~~  */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;           /* PC.05 ADC CHANNEL 15 */
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;       /* ANALOG INPUT */
      GPIO_Init(GPIOC, &GPIO_InitStructure);
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : ADC_configuration
    * Description    : Configuración del ADC.
    ============================================================================= */
    /* ====================================================================================================================================== */
    [b]void ADC_configuration(void)[/b]
    {
      ADC_InitTypeDef ADC_InitStructure;
      ADC_DeInit(ADC1);               /* Inicializa los registros */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */  
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ADC1 clock ~~~~~~~~~~~ */ 
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION DEL ADC1 ~~ */ 
      ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;                     /* ELIGE EL MODO DE OPERACION - ADC_CR1.DUALMOD */
      ADC_InitStructure.ADC_ScanConvMode = ENABLE;                           /* HABILITA MODO SCAN (GRUPO DE CANALES) - ADC_CR1.SCAN */
      ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;                     /* DESHABILITA EL MODO CONTINUO - ADC_CR2.CONT */
      ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO; /* HABILITA TRIGGER POR TIMER3 - ADC_CR2.EXTSEL */
      ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;                 /* ALINEACION A LA DERECHA - ADC_CR2.ALIGN */
      ADC_InitStructure.ADC_NbrOfChannel = 1;                                /* NUMERO DE CANALES DEL GRUPO */
      ADC_Init(ADC1, &ADC_InitStructure);
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION DEL ADC1 ~~ */
    /* SELECCION DEL SAMPLE TIME - ADC_SMPR2.SMPx, SELECCION SECUENCIA REGULAR - ADC_SQR1 */
    /* ~~~~~~~~~~~~~~~~~~ ADC conversion Time = Sampling Time + 12,5 cycles ~~~~~ */ 
      ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_1Cycles5); 
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HABILITACION DEL ADC1 DMA */
    //  ADC_DMACmd(ADC1, ENABLE);                      /* HABILITACION DIRECT MEMORY ACCESS MODE - ADC_CR2.DMA */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HABILITACION DEL ADC1 ~~~ */
      ADC_Cmd(ADC1, ENABLE);                   /* DESPIERTA AL ADC - ADC_CR2.ADON */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RESETEO DEL ADC1 ~~~~~~~ */
      ADC_ResetCalibration(ADC1);     /* INICIALIZA REGS. CALIBRACION - ADC_CR2.RSTCAL */        
      while(ADC_GetResetCalibrationStatus(ADC1)); /* FIN CALIBRACION REGS. - ADC_CR2.RSTCAL=0 */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CALIBRACION DEL ADC1 ~~~ */
      ADC_StartCalibration(ADC1);         /* COMIENZA LA CALIBRACION SELECCIONADA */
      while(ADC_GetCalibrationStatus(ADC1));    /* CALIBRACION COMPLETADA - ADC_CR2.CAL=0 */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION DE LA INTERRUPCION EOC DEL ADC1 ~~~ */ 
      ADC_ClearITPendingBit(ADC1,ADC_IT_EOC);        /* BORRA EOC bit ADC1_SR.EOC */ 
      ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE);       /* HABILITA LA INTERRUPCION EOC */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */  
      ADC_ExternalTrigConvCmd(ADC1, ENABLE);           /* START CONVERSION DEL ADC1 -  ADC_CR2.EXTTRIG */
    //  ADC_SoftwareStartConvCmd(ADC1, ENABLE);        /* START CONVERSION DEL ADC1 - ADC_CR2.SWSTART y ADC_CR2.EXTTRIG */
    
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : TIMER_configuration
    * Description    : Configuración del TIMER.
    ============================================================================= */
    /* ====================================================================================================================================== */
    [b]void TIMER_configuration(void)[/b]
    { 
      TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
      TIM_OCInitTypeDef  TIM_OCInitStructure; 
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TIM1 y TIM3 CLK ~~~ */ 
      /* TIM 1 CAPTURE-COMPARE-PWM MODE */
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 ,ENABLE);   /* RCC_APB2ENR.TIM1EN ENABLE CLK TIM1 */
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1 ,DISABLE);  /* RCC_APB2RSTR.TIM1RST RESET TIM1 */
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);   /* RCC_APB1ENR.TIM3EN ENABLE CLK TIM3 */
      RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3,DISABLE);  /* RCC_APB1RSTR.TIM3RST RESET TIM3 */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ 
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION TIM3 PARA TRIGGER ADC ~~ */
      /* ~~~~~~~ CONFIGURACION PARA 20KHz ~~~~~~~~~~~~~~~~~~~~ */
      #define Prescala 1      /* Maximo 65536 */
      #define Periodo 2799    /* Maximo 65536 */
      TIM_TimeBaseStructure.TIM_Prescaler = Prescala-1;             /* DIVIDE EL CK_CNT=CK_PSC/(TIMx_PSC+1) - TIMx_PSC */
      TIM_TimeBaseStructure.TIM_Period = Periodo;                   /* NUMERO DE PULSOS A CONTAR DE CK_CNT - PERIODO TIMx_ARR */
      TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down; /* MODO DE CONTADOR - TIM_CR1.DIR */
      TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;       /* PARA FILTROS DIGITALES - TIM_CR1.CKD */
      TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;              /* TIM_RCR */
      TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
    
      TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);              /* HABILITA ISR TIM3 */
      TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_Update); 
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    
      TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
      TIM1_ClearITPendingBit(TIM1_FLAG_Update);            /* BORRA UPDATE INTERRUPT BIT TIMx_SR.UIF */ 
      TIM1_ITConfig(TIM1_FLAG_Update,ENABLE);              /* HABILITA ISR TIM1 */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PWM1 Mode configuration: Channel2 ~~ */
      /* PWM1 Mode configuration: Channel2 */
      TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;   /* ELIGE EL MODO PWM */
      TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
      TIM_OCInitStructure.TIM_Pulse = 0;                            /* Duty Cycle */
      TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
      TIM_OC2Init(TIM1, &TIM_OCInitStructure);
      TIM_CtrlPWMOutputs(TIM1, ENABLE);                /* TIM1 Main Output Enable */
    
    // /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIGURACION TIM3 TRGO TRIGGER ~~ */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ 
      TIM_Cmd(TIM3,ENABLE);                                     /* ENCENDIDO TIM1 */
      TIM_Cmd(TIM1,ENABLE);                                     /* ENCENDIDO TIM1 */ 
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : CLK_configuration
    * Description    : Configuración del Nested vectored interrupt.
    ============================================================================= */
    /* ====================================================================================================================================== */
    [b]void CLK_configuration (void)[/b]
    {
      /* RCC system reset(for debug purpose) */
      RCC_DeInit();
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HSI RC (8 MHz) ~~~~ */
      RCC_HSICmd(ENABLE);                                 /* ENABLE/DISABLE RCC_CR.HSION - INTERNAL 8MHz OSCILLATOR ON */
      while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET); /* WAIT TO HARDWARE OFF */
      RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);             /* MODIFICA RCC_CFGR.SW - ELIGE EL HSI COMO SYSCLK SOURCE */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HSE_Value (8 MHz) stm32f10x_conf.h ~~~~ */
      RCC_HSEConfig(RCC_HSE_ON);                           /* ON/OFF RCC_CR.HSEON - EXTERNAL 8MHz OSCILLATOR ON */
      while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET); /* WAIT TO HARDWARE OFF */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PHASE LOOP LOCKED PLLCLK->56MHz ~~~~ */
    /* ~~~~~~~~~~~~~~~~~~ Se elige 56MHz para tener ADC CONVERSION TIME=1uS ~~~~~ */
      RCC_PLLCmd(DISABLE);                                   /* ENABLE/DISABLE RCC_CR.PLLON */
      RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_7);   /* SYSCLK=56MHZ- RCC_CFGR.PLLSRC=1, RCC_CFGR.PLLXRPRE=0 y RCC_CFGR.PLLMULL=0101 */
      RCC_PLLCmd(ENABLE);                                   /* ENABLE/DISABLE RCC_CR.PLLON */
      while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* WAIT TO HARDWARE OFF */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SYSTEM CLOCK SYSCLK=56MHZ HCLK=56MHZ ~~~~ */
      RCC_ADCCLKConfig(RCC_PCLK2_Div4);   /* RELOJ DEL ADC PCLK2/2=14MHz - CONFIGURE RCC_CFGR.ADCPRE */
      RCC_PCLK2Config(RCC_HCLK_Div1);     /* APB2 PCLK2 = 56MHz CONFIGURE RCC_CFGR.PPRE2 */
      RCC_PCLK1Config(RCC_HCLK_Div2);     /* APB1 PCLK1 = 28MHz CONFIGURE RCC_CFGR.PPRE1 */
      RCC_HCLKConfig(RCC_SYSCLK_Div1);    /* AHB  HCLK  = 56MHz CONFIGURE RCC_CFGR.HPRE  */
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EMB_FLASH ~~~~ */
    #ifdef EMB_FLASH
      // 5. Init Embedded Flash
      // Zero wait state, if 0 < HCLK 24 MHz
      // One wait state, if 24 MHz < HCLK 56 MHz
      // Two wait states, if 56 MHz < HCLK 72 MHz
      // Flash wait state
      FLASH_SetLatency(FLASH_Latency_2);
      // Half cycle access
      FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable);
      // Prefetch buffer
      FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
    #endif // EMB_FLASH
    
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      // 5. Clock system from PLL
      RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);  /* SELECCIONA EL CLOCK DEL PLL - MODIFICA RCC_CFGR.SW */
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : NVIC_configuration
    * Description    : Configuración del Nested vectored interrupt.
    ============================================================================= */
    /* ====================================================================================================================================== */
    [b]void NVIC_configuration(void)[/b]
    {
       NVIC_InitTypeDef NVIC_InitStructure;
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */  
    #ifndef  EMB_FLASH
      NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);      /* Set the Vector Table base location at 0x20000000 */
    #else   
      NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);    /* Set the Vector Table base location at 0x08000000 */
    #endif
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);         /* Sin Group Priority, PRI-n[7:4] Subpriority */
      NVIC_SETPRIMASK();                               /* DESHABILITA las interrupciones para configuracion */
     /* Configure and enable ADC interrupt */
      NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQChannel;
      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
      NVIC_Init(&NVIC_InitStructure); 
      
      NVIC_RESETPRIMASK();  /* HABILITA las interrupciones despues de configuracion */
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : DMA_configuration
    * Description    : Configuración del DMA.
    ============================================================================= */
    /* ====================================================================================================================================== */
    [b]void DMA_configuration(void)[/b]
    { 
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : Refresco_PWM
    * Description    : Refresca el duty cycle
    ============================================================================= */
    /* ====================================================================================================================================== */
    void Refresco_PWM(TIM_TypeDef* TIMx1,unsigned int ADC_Val)
    {
      u16 DutyCycle;
      DutyCycle=(ADC_Val*(TIMx1->ARR+1))/4095;    /* TIM8 Channel1 duty cycle = (TIMx_CCR1/ TIMx_ARR)* 100 */
      
      TIMx1->CCR2 =DutyCycle;  /* Escribe en el registro duty cycle del channel 2 del TIM1 PA.9 */   
    }
    /* ====================================================================================================================================== */
    /* =============================================================================
    * Function Name  : Chequeo_frecuencia
    * Description    : Chequea cada vez que entra en esta funcion
    * Entradas       : GPIOx[PORT],GPIO_Pin[Pin] que hay que mirar en el oscilo  
    ============================================================================= */
    /* ====================================================================================================================================== */
    [b]void Chequeo_frecuencia(GPIO_TypeDef* GPIOx, u16 GPIO_Pin,u8 index)[/b]
    {
    static short LEDState[2];
       LEDState[index-1]^= 0x01; /*Asignación con XOR binario.Q=1 si son diferentes */
                if(LEDState[index-1])
                  GPIO_WriteBit(GPIOx,GPIO_Pin ,Bit_RESET);  /* Puesta 1, HW logica negada */
                else
                  GPIO_WriteBit(GPIOx,GPIO_Pin ,Bit_SET);  /* Puesta 0, HW logica negada */      
      }
    /*************** (C) COPYRIGHT 2010 IKOR Technology centre *****END OF FILE****/
    

    STM32f10x_it.C

    /******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
    * File Name          : stm32f10x_it.c
    * Author             : MCD Application Team
    * Version            : V1.0
    * Date               : 10/08/2007
    * Description        : Main Interrupt Service Routines.
    ******************************************************************************** /
    /* Includes ------------------------------------------------------------------*/
    #include "stm32f10x_it.h"
    #include "TOOLS.h"
    /* Private variables ---------------------------------------------------------*/
    vu8 IT_ADC_tick;
    vu8 IT_TIM3_tick;
    vu16 ADC1ConvertedValue;
    /*******************************************************************************
    * Function Name  : ADC_IRQHandler
    * Description    : This function handles ADC global interrupt request.
    * Input          : None
    * Output         : None
    * Return         : None
    *******************************************************************************/
    [b]void ADC_IRQHandler(void)[/b]
    {  
        IT_ADC_tick=1;
        ADC1ConvertedValue = ADC1->DR;   /* Dato convertido */
        ADC_ClearITPendingBit(ADC1,ADC_IT_EOC);   
        Refresco_PWM(TIM1,ADC1ConvertedValue);
        Chequeo_frecuencia(GPIOA,GPIO_Pin_5,2);
    }
    
     
  • Giovanni Di Sirio

    I didn't do really much but I am glad you fixed it :-)

    Giovanni

     

Log in to post a comment.