I have some problems in using XET256,About AD and debug

cancel
Showing results for 
Search instead for 
Did you mean: 

I have some problems in using XET256,About AD and debug

Jump to solution
534 Views
hongjianzhang
Contributor III

1. Sometimes the AD Module stop while the MCU is still running, and I can't find where the problem is, but I can make sure that in debug mode ,when I open the Mcuregester the Ad will surely stop and can't back to normal. I don't test in non debug mode.

 

2. The MCU may stop sometimes,  When it is in debug Mode ,the MCU stop unexpectly, then  I click the stop button stop the mcu, and then chlik the run button to run it ,and it will run normally.

 

 

 

 

(My english is bad for I am a chinese, If you have anything that I don't describe very well ,and I'll try to speak clearly

)

Labels (1)
1 Solution
343 Views
RadekS
NXP Employee
NXP Employee

Hi hongjian,

I see problem in use AFFC bit - ATD Fast Flag Clear All. The read access to the result register will cause the associated CCF[n] flag and SCF flag to clear automatically.

So, if you open register window, debugger will automatically read register values, include result registers. That way debugger could also clear conversion complete flag and result of your branch “if ((ATD0STAT0_SCF == 0) || (ATD1STAT0_SCF == 0))” will be always true.

I would like to recommend do not use combination of AFFC feature with result register reading by debugger and Single conversion sequence.

I do not see any reading of result register in your code.

Please modify your code by any of these ways:

1. Disable AFFC bit and add commands for clearing SCF flags.

For example: ATD0STAT0 = ATD0STAT0_SCF_MASK;

2. Use program for reading ATD registers instead of debugger (you could use debugger for periodic reading of result variables).

For example: result0 = ATD0DR0;…

3. Use Continuous conversion sequences (scan mode) instead of Single conversion sequence. That will ensure that you will not enter into dead loop.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

6 Replies
343 Views
hongjianzhang
Contributor III

The AD part code example is shortted as blow:

#include <hidef.h>      /* common defines and macros */

#include "derivative.h"      /* derivative-specific definitions */

void  AutoEle_InitPLL (void)

{

  CLKSEL &= ~(0x80); //Select OSCCLK as MCU clock

  REFDV = 0xC0; //FREF = Fosc / (REFDIV +1), FEFFRQ=11, REFDIV=0

  SYNR = 0xC2; //FVCO = 2 * Fref * (SYNR + 1)

  POSTDIV = 0; //FPLL = FVCO / (2 * POSTDIV)

  while (!CRGFLG_LOCK) ; // Wait unitl PLL locked

  CLKSEL |= 0x80; //Select PLLCLK as MCU clock

}

void AutoEle_EP100_ADInit(void)

{

  /* AD0   AN0-AN15 */

  ATD0CTL0 = 15; //回环通道

  ATD0CTL1 = 0x2F; //外部触发源,10位分辨率

  ATD0CTL2 = 0x40;   //CCF位快速清除,及中断使能配置

  ATD0CTL3 = 0x80 | (0 << 3); //右对齐,转换序列长度为3,非FIFO模式

  ATD0CTL4 = 0x57;        //采样时间8AD时钟周期,总线时钟分频 Fad= Fbus/(2*(Prs[4~0] + 1)) 1M ,

  ATD0CMPE = 0x0; //比较功能关闭  2bytes

  ATD0DIEN = 0x0; //Disable digital input buffer to ANx pin 2bytes

  ATD0CTL5 = 0x10;

  /* AD1 AN16-AN23 */

  ATD1CTL0 = 7; //回环通道

  ATD1CTL1 = 0x2F; //外部触发源,10位分辨率

  ATD1CTL2 = 0x40;

  ATD1CTL3 = 0x80 | (8 << 3); //右对齐,转换序列长度为3,非FIFO模式

  ATD1CTL4 = 0x57;         //采样时间8AD时钟周期,总线时钟分频 Fad= Fbus/(2*(Prs[4~0] + 1)) 1M ,

  ATD1CMPE = 0x0; //比较功能关闭  2bytes

  ATD1DIEN = 0x18; //Disable digital input buffer to ANx pin 2bytes

  ATD1CTL5 = 0x10;

}

void main(void)

{

  /* put your own code here */

    AutoEle_EP100_ADInit();

    AutoEle_EP100_ADInit();

  

  

    EnableInterrupts;

    for(;;)

    {

        if ((ATD0STAT0_SCF == 0) || (ATD1STAT0_SCF == 0))

    {

 

    }

    else

    {

       ATD0CTL5 = 0x10; //启动转换

        ATD1CTL5 = 0x10; //启动转换

    }

      

        _FEED_COP(); /* feeds the dog */

    } /* loop forever */

    /* please make sure that you never leave main */

} !

0 Kudos
344 Views
RadekS
NXP Employee
NXP Employee

Hi hongjian,

I see problem in use AFFC bit - ATD Fast Flag Clear All. The read access to the result register will cause the associated CCF[n] flag and SCF flag to clear automatically.

So, if you open register window, debugger will automatically read register values, include result registers. That way debugger could also clear conversion complete flag and result of your branch “if ((ATD0STAT0_SCF == 0) || (ATD1STAT0_SCF == 0))” will be always true.

I would like to recommend do not use combination of AFFC feature with result register reading by debugger and Single conversion sequence.

I do not see any reading of result register in your code.

Please modify your code by any of these ways:

1. Disable AFFC bit and add commands for clearing SCF flags.

For example: ATD0STAT0 = ATD0STAT0_SCF_MASK;

2. Use program for reading ATD registers instead of debugger (you could use debugger for periodic reading of result variables).

For example: result0 = ATD0DR0;…

3. Use Continuous conversion sequences (scan mode) instead of Single conversion sequence. That will ensure that you will not enter into dead loop.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

343 Views
hongjianzhang
Contributor III

Hi Radek Sestak:

       about "3. Use Continuous conversion sequences (scan mode) instead of Single conversion sequence. That will ensure that you will not enter into dead loop."

       We can't use Continuous conversion, because we have multi outside  channel  of  per AD channel, we need first select channel an then began to convert

0 Kudos
343 Views
RadekS
NXP Employee
NXP Employee

Hi hongjian,

thank you for note.

I understood that you have analog multiplexor/switch at AD input pin(s) and you don’t need high sample rate for measuring analog values. In that case single conversion is probably right solution.

I forget note one (maybe too obvious) point in my last reply. We have to avoid of combining of enabled AFFC bit and manual clearing conversion complete flags! It could lead to unpredictable behavior.

I am glad that it works now.

Best Regards

RadekS

343 Views
hongjianzhang
Contributor III

Hi Radek Sestak:

    

Thank you

I didn't really notice the AFFC bit, and lately after when I post this question I also found that our mechanism is not so stable ,it will stop and not back to normal once got a fault.

My code don't read the result register because our project have a lot of codes, and I copy a part of it to test AD.

Anyway, Thank you all !

0 Kudos
343 Views
kef2
Senior Contributor IV

AFFC=1 is not compatible with comment at write to ATD0CTL5 //启动转换

Start of conversion is different when AFFC=1.

0 Kudos