ADC configuration in ATMEL ARM SAM E70 BOARD

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Below is the code for ADC IN SAM E70 BOARD. Can someone pls help me that what are the changes to be made in the code. The output I am getting is constant 1's and no conversion is happening. ITS URGENT....!!!!

 

#include "board.h"
#include <stdbool.h>
#include <stdio.h>
#include "afec.h"

#define IRQ_PRIOR_PIO 0
#define TEST_CHANNEL 5
#define AFE_CLK 10000000
#define CHANNEL_OFFSET 0X200

static void afe_initialization(void)
{
    AFEC_Initialize( AFEC0,ID_AFEC0 );
    
    /* AFEC MODE REGISTER CONFIGURATION */
    AFEC_SetModeReg(AFEC0,AFEC_MR_FREERUN_OFF|AFEC_MR_TRANSFER(1)|AFEC_MR_TRACKTIM(2)| AFEC_MR_ONE| AFEC_MR_STARTUP_SUT64);

    /* Set AFEC clock */
    AFEC_SetClock(AFEC0, AFE_CLK, BOARD_MCK);

    /* Select the channel */
    AFEC_EnableChannel(AFEC0, TEST_CHANNEL);

    /* Adjusting the channel level offset */
    AFEC_SetAnalogOffset(AFEC0,TEST_CHANNEL,CHANNEL_OFFSET);

    /* Enable the PGA0 and PGA 1 by tuning the AFE Bias Current Control */
    AFEC_SetAnalogControl(AFEC0, AFEC_ACR_IBCTL(1) | AFEC_ACR_PGA0_ON | AFEC_ACR_PGA1_ON);

    /* Configuring the Extended Mode Register */
    AFEC_SetExtModeReg(AFEC0,0| AFEC_EMR_RES(256)| AFEC_EMR_TAG | AFEC_EMR_STM );
}

extern int main( void )
{

    /* Disable watchdog */
    WDT_Disable(WDT);
    afe_initialization();
    AFEC_StartConversion(AFEC0);
    while (!(AFEC_GetStatus(AFEC0) & AFEC_ISR_EOC5));

    char ch =  (AFEC_GetLastConvertedData(AFEC0) & AFEC_LCDR_CHNB_Msk ) >> AFEC_LCDR_CHNB_Pos;
    float voltage = ((AFEC_GetLastConvertedData(AFEC0) & AFEC_LCDR_LDATA_Msk)) * 3254/ 4096;
    printf("%02u %04u\n\r" ,(unsigned int)ch,(unsigned int)voltage);
    
}
 

avantika

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Where is afec.h (and afec.c I guess) comming from?

/Lars