ATD in HCS08GB60

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

ATD in HCS08GB60

1,527 Views
yu
Contributor I
Hi, i am using MC13213 which the MCU is HCS08GB .I  want to input the sensor's analog signal and convert it to digital signal with ATD module. And I configure the registers as follows:  
 
void ADC_INI(void)
 {
    ATD1C=0xE2;     //not interrupt (polling),8-bit conversion
    ATD1SC=0x25;   //select the channel five
    ATD1PE=0x20;   //the fifth pin is set as ATD input    
 }
 
 
 
And my program is :
 /*********************define the variable and function****************************/
unsigned int DATA=0;
void ADC_INI(void);
 
 /*****************main function*****************************************/
void main(void)
 {
      //EnableInterrupts; /* enable interrupts */
   
   ADC_INI();

    for(;:smileywink:
    {
     __RESET_WATCHDOG(); /* feeds the dog */

        //  ATD1C=0xE2;
              
        while(!ATD1SC_CCF)
       
        __RESET_WATCHDOG();           /***********************the program  always stop here
    
        DATA=ATD1RH;
    
     } /* loop forever */
  /* please make sure that you never leave main */
}
/*****************initialization*****************************************/
void ADC_INI(void)
 {
    ATD1C=0xE2;
    ATD1SC=0x25; 
    ATD1PE=0x20;     
 }
 
But now i can get the result of conversion and ATD1SC_CCF is always 0.
I don't know why and hope you help!
Labels (1)
0 Kudos
3 Replies

291 Views
seb332
Contributor I
There are 2 bugs in your program.
You didn't set the registers in the right order.
ATD1PE must be the first not in the last position in ADC_INI fonction.
2° error  : if possible, put ATD1SC_ATDIE and ATD1SC_ATDCO at 1 not at 0.
0 Kudos

291 Views
peg
Senior Contributor IV
Hello,

While the order of register setting may not be the best I don't believe it will stop anything from working here.
The suggestion to enable interrupts goes against the code comments that say that the OP wants polling mode.
The main problem with the original setup is that the ATDSC register needs to be written after each read to cause a further conversion to occur. No need for continuous conversion here.

0 Kudos

291 Views
peg
Senior Contributor IV
Hi yu,

Is your ATD clock in range?
It must lie between 500k and 2M.
So your BUSCLK must be between 3 and 12 MHz.

0 Kudos