not able to toggle a paticlar pin on the MC90S08DN16

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

not able to toggle a paticlar pin on the MC90S08DN16

Jump to solution
984 Views
vikassubramani
Contributor II

hi i am just toggoling a paticular pin in port a i am not able to get expected result. i have included the code below please take a look

 

 

#include <hidef.h>

 

#include "derivative.h"

void delay(void);

 

 

void main(void)

 

{

EnableInterrupts;

        PTADD_PTADD0 = 1;

PTDPE_PTDPE0 = 0;

 

         while (1)

 

{

PTAD_PTAD0 = 1;

delay();

PTAD_PTAD0 = 0;

delay();

PTAD_PTAD0 = 1;

delay();

PTAD_PTAD0 = 0;

delay();

                __Reset_Watchdog;

          }

}

 

 

void delay(void)

 

{

int i, j;

for (i=0; i<200; i++)

for(j=0; j<200; j++);

}

 

 

The problem that i am facing is that when i run in debug mode setp by setp execution the program counter in not going according to the written program it is getting currupted and the other thing that i noticed is that when last four lines of the code in while loop, except for" __resetwatch dog" is taken out  then the code and the debugger works ablsolutely fine but as soon as i include another toggle in the code the problem starts.

 

 

 

Thanks

Labels (1)
0 Kudos
1 Solution
748 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

hello Vikas,

the problem is due to optimization. the simple way to avoid optimization is to add "asm nop;"

   while (1)

{

PTAD_PTAD0 = 1;

asm nop;

delay();

PTAD_PTAD0 = 0;

asm nop;

delay();

PTAD_PTAD0 = 1;

asm nop;

delay();

PTAD_PTAD0 = 0;

asm nop;

delay();

                __Reset_Watchdog;

}

==============================================

this answer is for you. if it helps, please click on "correct answer" button. thanks!

Best Regards,

Zhang Jun

View solution in original post

0 Kudos
6 Replies
748 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

hi vikas,

you mentioned "program it is getting currupted ".  can you please send me a screenshot of it?

Best Regards,

Zhang Jun

0 Kudos
748 Views
vikassubramani
Contributor II

image1.png

0 Kudos
748 Views
vikassubramani
Contributor II

image2.png

0 Kudos
748 Views
vikassubramani
Contributor II

image3.png

0 Kudos
749 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

hello Vikas,

the problem is due to optimization. the simple way to avoid optimization is to add "asm nop;"

   while (1)

{

PTAD_PTAD0 = 1;

asm nop;

delay();

PTAD_PTAD0 = 0;

asm nop;

delay();

PTAD_PTAD0 = 1;

asm nop;

delay();

PTAD_PTAD0 = 0;

asm nop;

delay();

                __Reset_Watchdog;

}

==============================================

this answer is for you. if it helps, please click on "correct answer" button. thanks!

Best Regards,

Zhang Jun

0 Kudos
748 Views
vikassubramani
Contributor II

Hi Jennie,

               Thanks a lot for the reply it did work by inserting above line.

0 Kudos