ATD- Multy Channel

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ATD- Multy Channel

2,173 Views
Idontunderstand
Contributor I

Hello;

I am using CSMB12 microcontroller; and connect it to two sensor; so i want to see the result of this two sensor seperatly on the LCD. I used the ADC; and conncet one of the sensor to AN0(pin 18) and AN1(pin 20). When I get the result on the lcd; although my sensor is stable but the value on the LCD is changed frequently! and seems that change in the value of one of the sensor affect to another one.

At fisrt I use single channel for each of them; and it worked properly. but seem when I combine them; some part of my code doesn't work.

I appreciate any help.

If more information or my code necessary; please let me know.

 

Cheers;

Sb

Labels (1)
0 Kudos
Reply
5 Replies

1,195 Views
Idontunderstand
Contributor I

Thanks for your information.

My input resistivity is unstable from 12k to 50 kadn I read the voltage of one of the terminals.

I also; before tried to wait for SCF only once per loop.

 

 

0 Kudos
Reply

1,195 Views
kef
Specialist I

Have you seen this AN:

 

AN2429 Interfacing to the HCS12 ATD Module

 

 

Other S12C ANs can be found here

0 Kudos
Reply

1,195 Views
Idontunderstand
Contributor I

it is CSMB12C128; And 4MHz clock oscillator. the following link in the case; is the datasheet of microcontroller:

http://www.axman.com/files/CSMB12UG.pdf

 

following code may useful to help me;thank you.

 

 .

 .

.
//define variables

void ATD_Init(void)
{
    ATDCTL2 = 0xE0;
        // 1 - ATD power down
        // 1 - ATD fast flag clear
        // 1 - ATD power down in wait mode
        // 0 - External trigger level/edge control
        // 0 - External trigger polarity
        // 0 - External trigger mode enable
        // 0 - ATD sequence complete interrupt enable
        // 0 - ATD sequence complete interrupt flag
       
    ATDCTL3 = 0x12;
        // 0 - reserved
        // 0010 - Conversion sequence length = 2 (we are looking for two channel)
        // 0 - Result register FIFO mode
        // 10 - Background Debug Freeze Enable       
       
    ATDCTL4 = 0xC7;
        // 1 - A/D resolution select - 8bit
        // 10 - Sample time select - 8 A/D conversion clock periods
        // 00111 - ATD clock prescaler
                    // bus clock 8MHz, PRS = 7           
                    // ATD clock = BusClk/(PRS + 1)*0.5 = 500kHz   
                   
    ATDCTL5 = 0xB0; //start of continuous conversion
        // 1 - Result register data justification - right justified - bits 0-7
        // 0 - Result register data signed or unsigned - unsigned
        // 1 - Continuous conversion sequence mode - continuous mode
        // 1 - Multi-channel sample mode - Multi channel
        // 000 - Analog input channel select mode - channel AN0 - PAD00 -> start of conversion                       
}

void main (void)
{
 
  MCU_init();       // call Device Initialization
  ATD_Init();
  // Initialize the SCI
 .

.

.                                   
  
 for (;:smileywink:
 {
    while(ATDSTAT0_SCF == 0);     //wait for the end of conversion
    atd_value = ATDDR0L;        //the result of first sensor
    atd_value1 =   (atd_value/53.18);          // Compare the real voltage and debugger and come up with this division
   tetha1 = (float)(-16.46 *atd_value1* atd_value1* atd_value1+
          135.5 * atd_value1* atd_value1-403.9* atd_value1+503.7); // Use curve fittinge to find the function of angle(theta1) based on changing of voltage
   for(x=0;x<60000;x++) asm nop;
   data[6] =((char)(((int)tetha1/100)))+'0';         //to show the value on the LCD
   data[7] =((char)(((int)tetha1%100)/10))+'0';
   data[8] =((char)(((int)tetha1%10)))+'0';
 
   ATDSTAT0_SCF = 0;
   for(x=0;x<60000;x++) asm nop;
   while(ATDSTAT0_SCF == 0);
   atdvalue = ATDDR1L;         // The result of second sensor
   for(x=0;x<60000;x++) asm nop;                     //for the second flexsensor
   atdvalue1 =   (atdvalue/51);
   atdvalue2 =  5-(atdvalue/51);
   tetha2 = (float)(-92.06 *atdvalue1* atdvalue1* atdvalue1+
          1012 * atdvalue1* atdvalue1-3814* atdvalue1+4960);
   for(x=0;x<60000;x++) asm nop;

   data[18] =((char)(((int)tetha2/100)))+'0';
   data[19] =((char)(((int)tetha2%100)/10))+'0';
   data[20] =((char)(((int)tetha2%10)))+'0';
   tetha3= (tetha1+tetha2)/2;
  
  
   data[23] =((char)(((int)tetha3/100)))+'0';
   data[24] =((char)(((int)tetha3%100)/10))+'0';
   data[25] =((char)(((int)tetha3%10)))+'0';
  
  
   sendDataToSCI(data,32);
 }
}
                                   
 void sendDataToSCI (char* array, int length)
{
  .


.

.

}   
   
   
   
   
   
   
   
   
   
   
   
    Cheers;
    Sb   
   
   
   
   


  

     


   

0 Kudos
Reply

1,195 Views
kef
Specialist I

I don't see something in the code, that could make your readings noisy.

 

Are you sure source impedances aren't too high?

 

 

 

Few notes regarding how are you using SCF flag:

1) Since you are using AFFC=1 mode, you shouldn't try to clear SCF flag writing something to SCF. You should read any ATD data register to clear it in AFFC=1 mode.

2) Writing 0 to SCF doesn't make any sense. Doing it this way

 

  ATDSTAT0_SCF =0;

 

is potentially harmful. In AFFC=0 mode it wouldn't clear SCF, but would clear EROTF and FIFOR flags. Proper code to clear SCF in AFFC=0 mode is this

 

  ATDSTAT0 = ATDSTAT_SCF_MASK;

 

3) Since you have SCAN=1 and MULT=1, you should wait for SCF only once per loop. After SCF becomes 1, you can read both channels data registers.

0 Kudos
Reply

1,195 Views
kef
Specialist I

First of all what microcontroller is installed in your CSMB12 module?

 

How big are source impedances?

 

What's A/D clock rate?

 

What's sampling time?

 

 

Piece of relevant code could help identify problems, if any.

 

0 Kudos
Reply