Raady Here
Full Member level 5
- Joined
- Jun 8, 2013
- Messages
- 242
- Helped
- 26
- Reputation
- 52
- Reaction score
- 26
- Trophy points
- 28
- Location
- India
- Activity points
- 1,571
16 bit Sigma Delta ADC
P24Fj128GC006
MPLAB 8.88
Hi,
I am trying to measure DC Voltage using 16 bit ADC,
1.
in p24fj128gc006 header file given by microchip I dont have VOSCAL defined in its SD1CON1bits structure
so I get - error: 'SD1CON1BITS' has no member named 'VOSCAL'
Had my file got corrupted or else its the same for all. If I need to correct it how does I do it ?
2.
In block diagram I understood as input to SD ADC is through CH0+/- and CH1+/-.
should the analog channel be connected to CH1, if I use SD1CON3bits.SDCH = 1; // Channel 1 is used for this demo code
There are many ADC channels when you look at the pin diagram if I want to connect through other pins, is it possible to measure the analog signal.
if I am using all the four channels for measurement how can I differ those 4 values using a single register which reads the value.
SD1RESH/L( in 12 bit adc dspic, if i measure 4 chanels the values will be filled ADCbuf0 - ADCbuf3 respectively)
3.
when these two can be used
SDCH<2:0>: S/D Analog Channel Input Select bits (positive input/negative input)
011 = Measures the reference selected by SDREFP/SDREFN (used for gain error measurements)
010 = CH1SE/SVSS (single-ended measurement of CH1SE)
then where can I input my adc channel.
In my previous adc measurements, to calculate DC Voltage, I used "ADCBUFval/4095*operating voltage" (in case of 12 bit).
do I need to do the same way with SD1RESH as ADCBUF ?
but the voltage I am giving input to the controller is 3.0 V
as I configured OSR to 1024 should I use this = SD1RESH/1024 *operating voltage ?
sample code
P24Fj128GC006
MPLAB 8.88
Hi,
I am trying to measure DC Voltage using 16 bit ADC,
1.
in p24fj128gc006 header file given by microchip I dont have VOSCAL defined in its SD1CON1bits structure
so I get - error: 'SD1CON1BITS' has no member named 'VOSCAL'
Had my file got corrupted or else its the same for all. If I need to correct it how does I do it ?
2.
In block diagram I understood as input to SD ADC is through CH0+/- and CH1+/-.
should the analog channel be connected to CH1, if I use SD1CON3bits.SDCH = 1; // Channel 1 is used for this demo code
There are many ADC channels when you look at the pin diagram if I want to connect through other pins, is it possible to measure the analog signal.
if I am using all the four channels for measurement how can I differ those 4 values using a single register which reads the value.
SD1RESH/L( in 12 bit adc dspic, if i measure 4 chanels the values will be filled ADCbuf0 - ADCbuf3 respectively)
3.
when these two can be used
SDCH<2:0>: S/D Analog Channel Input Select bits (positive input/negative input)
011 = Measures the reference selected by SDREFP/SDREFN (used for gain error measurements)
010 = CH1SE/SVSS (single-ended measurement of CH1SE)
then where can I input my adc channel.
In my previous adc measurements, to calculate DC Voltage, I used "ADCBUFval/4095*operating voltage" (in case of 12 bit).
do I need to do the same way with SD1RESH as ADCBUF ?
but the voltage I am giving input to the controller is 3.0 V
as I configured OSR to 1024 should I use this = SD1RESH/1024 *operating voltage ?
sample code
Code:
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, because using SVDD as reference
SD1CON1bits.VOSCAL = 1; // Internal Offset Measurement Enable
SD1CON1bits.SDREFP = 0; // Positive Voltage Reference is SVDD
SD1CON1bits.SDREFN = 0; // Negative Voltage Reference is SVSS
SD1CON1bits.PWRLVL = 1; // High power mode
SD1CON2bits.CHOP = 3; // Chopping should be enabled always
SD1CON2bits.SDINT = 3; // Interrupt on every data output
SD1CON2bits.SDWM = 1; // SDxRESH/SDxRESL updated on every Interrupt
SD1CON2bits.RNDRES = 2; // Round result to 16-bit
SD1CON3bits.SDDIV = 1; // Input Clock Divider is 2 (SD ADC clock is 4MHz)
SD1CON3bits.SDOSR = 0; // Oversampling Ratio (OSR) is 1024 (best quality)
SD1CON3bits.SDCS = 1; // Clock Source is 8MHz FRC
SD1CON3bits.SDCH = 1; // Channel 1 is used for this demo code
SD1CON1bits.SDON = 1; // Enable the ADC module now that it is configured
for (i = 0; i<6; i++) // (value must be >= 5)
{
IFS6bits.SDA1IF = 0; //Clear interrupt flag
while(IFS6bits.SDA1IF == 0); //Wait until hardware says we have a result ready.
IFS6bits.SDA1IF = 0; //Clear interrupt flag
}
while(IFS6bits.SDA1IF == 0);//Wait until hardware says we have a result ready.
IFS6bits.SDA1IF = 0; //Clear interrupt flag
offset = (signed short int)SD1RESH; // cast to accommodate the sign bit extend
// Switch off offset measurement mode, now that we have the value
SD1CON1bits.SDON = 0;
SD1CON1bits.VOSCAL = 0;
SD1CON3bits.SDCH = 1; // point to the input voltage
SD1CON1bits.SDON = 1; // SD_ADC back on to make next measurement
// Wait for a minimum of five interrupts to be generated.
for(count=0; count<6; count++)
{
// Clear interrupt flag.
IFS6bits.SDA1IF = 0;
// Wait for the result ready.
while(IFS6bits.SDA1IF == 0);
}
// Save the maximum value to calculate the gain.
maxValue = (signed short int) SD1RESH; // must cast as signed as is declared unsigned in header
// Calculate gain.
SD_gain = EXPECTED_MAX_VALUE/((double)((signed long int)maxValue-offset));
Last edited: