16bit Sigma Delta ADC problem

16bit Sigma Delta ADC problem

Postby raadyhere » Wed Sep 24, 2014 12:13 pm

PIC24FJ128GC006
MPLAB V8.8
Hi,

while using 16 bit sigma delta ADC, the register bits given in the manual and that are found in header file provided with complier C30v3.31 are different.

SD1CON1bits.VOSCAL is not present in header but defined in manual.
SD1CON1bits.FILTDIS is present in header but no information is given in SD1CON1 register.
SD1CON2bits.CHOPSEL, represented in header instead of SD1CON2bits.CHOP given in manual
SD1CON2bits.SDRESRDY, represented in header instead of SD1CON2bits.SDRDY given manual.

Registers provided in header file (P24FJ128GC006.h) seems to be different w.r.t reference manual DS30009312B

VOSCAL bit is not defined in P24Fj128GC006 header file , so when I complied i received an error as mentioned below
error: 'SD1CON1BITS' has no member named 'VOSCAL'
I have edited SD1CON1 structure as below
Code: Select all

extern volatile unsigned int  SD1CON1 __attribute__((__sfr__));
__extension__ typedef struct tagSD1CON1BITS {
  union {
    struct {
      unsigned PWRLVL:1;
      unsigned SDREFP:1;
      unsigned SDREFN:1;
      unsigned VOSCAL:1;             //  added by me instead of //unsigned :1
      unsigned SDOFFCAL:1;
      unsigned :1;
      unsigned DITHER:2;
      unsigned SDGAIN:3;
      unsigned FILTDIS:1;
      unsigned SDRST:1;
      unsigned SDSIDL:1;
      unsigned :1;
      unsigned SDON:1;
    };
    struct {
      unsigned :6;
      unsigned DITHER0:1;
      unsigned DITHER1:1;
      unsigned SDGAIN0:1;
      unsigned SDGAIN1:1;
      unsigned SDGAIN2:1;
    };
  };
} SD1CON1BITS;


After modifying header file I was able to compile.

My hardware was as mentioned below
AVdd and SVdd are connected to Vdd(DC 3.0 V).
AVss and SVss are connected to Vss(ground)
CH0+ (pin22) is connected to Variable potentiometer 0 to Vdd. (for testing we have connected Variable Potentio meter)
CH0- (pin 23) is connected to Vss
do we need to do any thing with CH1+ and CH1-

my other peripherals are working fine(I2C, UART...).

When I am reading SD1RESH it shows a value -1158 and doesn't vary anything if I vary the potentiometer.
where had my setting gone wrong ?

Code I used
Code: Select all
void INIT_ADC(void)
{
   SD1CON1            = 0;
   SD1CON2            = 0;
   SD1CON3            = 0;   // Reset Adc.

   SD1CON1bits.SDRST   = 0;   // Release from Reset
   SD1CON1bits.SDGAIN   = 5;   // Gain is 32:1 for offset measurement and application
   SD1CON1bits.DITHER   = 1;   // Low Dither, Vref+ = SVDD
   SD1CON1bits.VOSCAL   = 0;   // No Offset Measurement
//   SD1CON1bits.FILTDIS   = 0;
   SD1CON1bits.SDREFP    = 0;   // Vref+ = SVDD
   SD1CON1bits.SDREFN    = 0;   // Vref- = SVSS
   SD1CON1bits.PWRLVL   = 1;   // low power mode

   SD1CON2bits.CHOPSEL   = 3;   // Chopping should be enabled always
   SD1CON2bits.SDINT   = 2;   // Interrupt on every 5 data output
   SD1CON2bits.SDWM   = 0;   // SDxRESH/SDxRESL updated on every Interrupt
   SD1CON2bits.RNDRES   = 2;   // Round result to 16-bit

   SD1CON3bits.SDDIV   = 0;   // Input Clock Divider is 1 (SD ADC clock is 8MHz)
   SD1CON3bits.SDOSR   = 0;   // Oversampling Ratio (OSR) is 1024
   SD1CON3bits.SDCS   = 1;   // Clock Source is 8MHz FRC
   SD1CON3bits.SDCH   = 0;   // Channel 0 is used for this

   IFS6bits.SDA1IF      = 0;
   IEC6bits.SDA1IE      = 1;
   IPC26bits.SDA1IP   = 7;   // Highest Priority .

   SD1CON1bits.SDON    = 1;   // Enable the ADC module now that it is configured
}

void __attribute__((__interrupt__,auto_psv)) _SDA1Interrupt(void)
{
//   if(SD1CON2bits.SDRESRDY)
   {
      SD1CON2bits.SDRESRDY = 0;
      printf("adc H %x, adc L %x\n", SD1RESH, SD1RESL);
   }
   IFS6bits.SDA1IF = 0; //Clear interrupt flag
}
raadyhere
 
Posts: 2
Joined: Wed Sep 17, 2014 12:52 pm
Location: Stockholm, Sweden
PIC experience: Professional 2-5 years with MCHP products

Return to ADC & Comparators

Who is online

Users browsing this forum: No registered users and 6 guests

cron