Hi all,
I have a piece of code and dont know why it does not run. Clock is as default
(1Mhz)
void SD16Setup (void)
{
SD16CTL = SD16REFON + SD16SSEL_0; // 1.2V ref, MCLK
SD16INCTL0 = SD16GAIN_32 + SD16INCH_4 + SD16INTDLY_0; // x gain, channel
A4+/-
SD16AE = SD16AE1 + SD16AE2; //Enable analog input A4+, A4-
SD16CCTL0 = SD16IE + SD16DF;// Continuous conv, interrupt and bipolar,OSR%6
}
void Zero_Calib(void)
{
SD16CCTL0 |= SD16SC; // Start conversion
while(!(SD16CCTL0 & SD16IFG))
P1OUT = Zero_Calib_LED; //start LED at P1.4
CalMin = Result;
}
#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
{
CurrentADC = (int)SD16MEM0; //store the conversion
SumSD16 += CurrentADC; //Sum up results
if (++SD16Count >%6)
{
MeanSD16 = SumSD16>>8; //Divide 256
SD16CCTL0 &= ~SD16SC; //Disable conversion
SD16Count=0;
SumSD16=0;
Result = (long)(MeanSD16*LSB*SD16Gain);
}
}
The Zero_Calib function is called by P1 ISR, basically, when the button is
pressed the Zero_Calib is called and do the SD16 conversion. Inside the SD16ISR,
sum of 256 conversion are calculated then the mean value is calculated after
that and store to Result.
I think I do not let the ADC enough time to do the whole conversion. If I just
call the SD16 ISR from the main and do nothing else, the result is perfect. Is
there any way to fix this problem?
Regards,
Anh