Mohamed Othman

HCS12 ATD

Discussion created by Mohamed Othman on Jul 11, 2008
Latest reply on Jul 14, 2008 by Mohamed Othman
Hello guys,
I need your help in this issue.
 
I am using ATD0 and ATD1 to convert several analog channels. I am also using the OC (output compare) timer function to generate a PWM (low frequency range, 0.1Hz to 100Hz with 10 to 30ms PW).
The problem is that the digital values for the analog channels are stable as long as the OC is not functioning. Once I start generating the PWM signals (two signals), the ATD0 and ATD1 digital values start to fluctuate although the analog signals are very stable (DC Sensor Outputs).
The DC analog signals are not fast, so I don't care that much about the sampling rate of the ATD or conversion time.
 
Here is my code for ATD0 (reading up to 4 channels):
 
I appreciate your help, thanks
 
regards,
 
void   OPEN_ATD0 (char con ) // con is number of channels to convert
{
 ATD0DIEN.byte= 0x00; 
 ATD0CTL2.byte=0b11000000; // power up and fast clear
 delayby25us(1);
 switch (con)
  {
   case 1 :  ATD0CTL3.byte= 0b00001000; break;   // 1 conversion always starts from AN0
   case 2 :  ATD0CTL3.byte= 0b00010000; break;   // 2 conversion
   case 3 :  ATD0CTL3.byte= 0b00011000; break;   // 3 conversion
   case 4 :  ATD0CTL3.byte= 0b00100000; break;   // 4 conversion 
   case 5 :  ATD0CTL3.byte= 0b00101000; break;   // 5 conversion 
   case 6 :  ATD0CTL3.byte= 0b00110000; break;   // 6 conversion 
   case 7 :  ATD0CTL3.byte= 0b00111000; break;   // 7 conversion 
   default:  ATD0CTL3.byte= 0x00;     // 8 conversion  
   ATD0CTL4.byte = 0b00100011; ; // 10 bit resolution 4 period 3Khz
  } 
}
// Reading function:
void   analog1_read (char ch, unsigned int analog[]) // analog[] is an unsigned int array to hold the results.
{                                                                                  // ch is number of channels to read. (same as con).
 char i=0;
 ATD0CTL5.byte=0b10110000;
 while (!(ATD0STAT0.byte&0x80));
   for (i=0;i<=ch;i++)
  {
     analog[i]= (unsigned int)*(&ATD0DR0+i);
  }
}

Outcomes