cancel
Showing results for 
Search instead for 
Did you mean: 

ADC CONTINUOUS conversion Problem.

sunilkasar7
Associate II
Posted on February 25, 2016 at 13:10

I below code, I am reading ADC counts and sending it over CAN. ADC is working properly for _SINGLE conversion mode.... But it is not working for CONTINUOUS Conversion mode mode.

2 REPLIES 2
sunilkasar7
Associate II
Posted on February 26, 2016 at 06:11

/* Includes ------------------------------------------------------------------*/ #include ''stm8s.h'' #include ''adc.h'' /* External variables --------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /* Private defines -----------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ uint16_t Conversion_Value = 0; /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** * @brief < Add here the function description > * @note < OPTIONAL: add here global note > * @param None * @retval None */ void ADC_Config(void) { /* Init GPIO for ADC2 */ GPIO_Init(GPIOB, GPIO_PIN_1, GPIO_MODE_IN_FL_NO_IT); /* De-Init ADC peripheral*/ ADC2_DeInit(); /* Init ADC2 peripheral */ ADC2_Init(ADC2_CONVERSIONMODE_SINGLE, ADC2_CHANNEL_1, ADC2_PRESSEL_FCPU_D2,ADC2_EXTTRIG_TIM, DISABLE, ADC2_ALIGN_RIGHT, ADC2_SCHMITTTRIG_CHANNEL1,DISABLE); /* Enable EOC interrupt */ ADC2_ITConfig(ENABLE); /* Enable general interrupts */ enableInterrupts(); /*Start Conversion */ ADC2_StartConversion(); } /** * @brief < Add here the function description > * @note < OPTIONAL: add here global note > * @param Param1 < Add here the parameter description > * @note < OPTIONAL: add here specific note for this parameter > * @param Param2 < Add here the parameter description > * @note < OPTIONAL: add here specific note for this parameter > * @retval returntype < Add here the description of the returned value > */ uint16_t GetADCData(void) { return ADC2_GetConversionValue(); }

sunilkasar7
Associate II
Posted on February 26, 2016 at 06:12

/* Includes ------------------------------------------------------------------*/ #include ''main.h'' #include ''stm8s.h'' #include ''L99PM62drv.h'' /* External variables --------------------------------------------------------*/ extern bool TransmissionEnable; extern bool CANMaster; extern bool LINSlave; extern bool StartupCompleted; /* External functions --------------------------------------------------------*/ /* lin.c */ extern void LIN_Task (void); extern void LIN_MasterConfig(void); extern void LIN_SlaveConfig(void); extern void InitScheduleTable(void); /* appli.c */ extern void Appli(void); /* can.c */ extern void CAN_Task(uint16_t adc_cnts_u16); extern void CAN_Config(void); /* adc.c */ extern void ADC_Config(void); extern uint16_t GetADCData(void); /* Private typedef -----------------------------------------------------------*/ /* Private defines -----------------------------------------------------------*/ #define TIM4_PERIOD 124 #define L99PM62WdgTriggerRefreshValue10 10 /* Private macros ------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ static __IO uint32_t TimingDelay = 0; static uint32_t WdgTrigger = 0; static uint32_t WdgTriggerReload = 0; bool ReceptionEnable=FALSE; /* Private function prototypes -----------------------------------------------*/ static void TIM4_Config(void); static void Delay(u32 nTime); void TimingDelay_Decrement(void); static void L99PM62drv_WdgAutoTrigger(u32 WdgAutoTriggerValue); static void CLK_Config(void); static void GPIO_Config(void); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program. * @param None * @retval None */ uint16_t adc_cnts_u16; void main(void) { L99PM62drv_RegType reg; /* GPIO Configuration ---------------------------------------*/ GPIO_Config(); /* ADC configuration -------------------------------------------*/ //ADC_Config(); CANMaster=TRUE; //LINSlave=TRUE; /* User Button 1 + trimmer turned clockwised: enter CAN test mode */ //if ((GPIOE->IDR & GPIO_PIN_2) == 0x0) //{ // TransmissionEnable=TRUE; // CANMaster=TRUE; // } /* User Button 2 : enter LIN slave test mode */ // else if ((GPIOE->IDR & GPIO_PIN_1) == 0x0) // { // LINSlave=TRUE; // } /* Clock configuration --------------------------------------*/ CLK_Config(); // SPI Init (enable communication with L99PM62) SPI_DeInit(); SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_64, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_LOW, SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT,(uint8_t)0x07); /* ADC configuration -------------------------------------------*/ ADC_Config(); //ADC2_ITConfig(ENABLE); /* TIM4 configuration -----------------------------------------*/ TIM4_Config(); /* Enable SPI */ SPI_Cmd(ENABLE); /* Enable TIM4 */ TIM4_Cmd(ENABLE); /* LIN configuration ----------------------------------------*/ /* LIN slave test mode */ //if (LINSlave==TRUE) { // LIN_SlaveConfig(); } /* LIN master mode (demo and test mode */ //else { // LIN_MasterConfig(); // InitScheduleTable(); } /* CAN configuration ----------------------------------------*/ CAN_Config(); /* Enable Interrupts*/ enableInterrupts(); // Set 40ms delay before starting communication during L99PM62 long open window Delay(40); /* Initialization of L99PM62 CAN/LIN transceiver */ L99PM62drv_Init(); // Set Auto Trigger by TIM4 timer tRefresh=10ms L99PM62drv_WdgAutoTrigger(L99PM62WdgTriggerRefreshValue10); //ADC2_StartConversion(); /* Infinite loop*/ while(1) { adc_cnts_u16 = GetADCData(); //Appli(); //Delay(100); StartupCompleted=1; if (StartupCompleted==TRUE) /* To allow leds display at startup */ { /* CAN test mode */ if ((CANMaster==TRUE)||(ReceptionEnable==TRUE)) { CAN_Task(adc_cnts_u16); } /* LIN demo or test mode */ //else if (ReceptionEnable==FALSE) { //LIN_Task(); } } } } /** * @brief < Add here the function description > * @note < OPTIONAL: add here global note > * @param None * @retval None */ void CLK_Config(void) { ErrorStatus status = ERROR; /* Initialization of the clock */ /* Clock divider to HSI/1 */ CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); /* Enable HSE to run on XTAL... */ /* ...except in LIN slave test mode if LINUART automatic resynchro is enabled */ if (LINSlave==TRUE) { #ifndef AUTOMATIC_RESYNCHRO status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE); #endif } else { status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE); } } /** * @brief < Add here the function description > * @note < OPTIONAL: add here global note > * @param None * @retval None */ void GPIO_Config(void) { #ifdef DEBUG GPIO_Init(GPIOB, (GPIO_Pin_TypeDef)GPIO_PIN_ALL, GPIO_MODE_OUT_PP_LOW_FAST); #endif /* CAN */ GPIO_Init(GPIOG, (GPIO_Pin_TypeDef)GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST); GPIO_Init(GPIOG, (GPIO_Pin_TypeDef)GPIO_PIN_1, GPIO_MODE_IN_PU_NO_IT); /* Init SPI peripheral pins */ GPIO_Init(GPIOC, (GPIO_Pin_TypeDef)(GPIO_PIN_5|GPIO_PIN_6), GPIO_MODE_OUT_PP_LOW_FAST); /* MOSI + CLK */ GPIO_Init(GPIOC, (GPIO_Pin_TypeDef)GPIO_PIN_7, GPIO_MODE_IN_PU_NO_IT); /* MISO */ GPIO_Init(GPIOE, (GPIO_Pin_TypeDef)(GPIO_PIN_5), GPIO_MODE_OUT_PP_HIGH_FAST); /* CSN */ /* Initialize LEDs I/Os in Output Mode */ GPIO_Init(GPIOA, (GPIO_Pin_TypeDef)GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST); GPIO_Init(GPIOD, (GPIO_Pin_TypeDef)GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST); GPIO_Init(GPIOD, (GPIO_Pin_TypeDef)GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST); GPIO_Init(GPIOE, (GPIO_Pin_TypeDef)GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST); GPIO_Init(GPIOC, (GPIO_Pin_TypeDef)GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST); /* USER1 button init: GPIO set in input interrupt active mode */ GPIO_Init( GPIOE, GPIO_PIN_2, GPIO_MODE_IN_FL_IT); /* USER2 button init: GPIO set in input interrupt active mode */ GPIO_Init( GPIOE, GPIO_PIN_1, GPIO_MODE_IN_FL_IT); //User Button 1 & 2 EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOE, EXTI_SENSITIVITY_FALL_ONLY); }