timing issues on HCS08

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

timing issues on HCS08

1,434 Views
timothy
Contributor I

Hello,

 I am using an HCS08 MC9S08QG8 and I am having some issues that appear to be timing issues. 

I have written the following code: it is just designed to wait for the push of an external switch (attached to PTAD3), and then toggle an LED and increment a counter.

 

It works fine when I single step through the code, but when I just run it normally, the counter does not increment (when I am watching it in the true time simulator), although the LED toggles off and on.  I set breakpoints inside the endless loop but I never hit them.  Also, I get a message “Frequency change to ~xxxxxxx”.

 

Do I need to initialize the clock frequency somehow?  Can you let me know what’s wrong with my timing?

 

 

Thanks,

Tim

 

 

 

#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

#include <MC9S08QG8.h>

int counter1=0;

int x=0;

 

void main(void) {

 // Set Port A Pin 3 (external Pin 11, connected to pushbutton SW) to input

 PTADD_PTADD3 = 0;

 // Set Port B Pin 6 (connected to LED1) to output

 PTBDD_PTBDD6 = 1;

  

 for(;:smileywink: {

   // Spin until a high signal is detected

   while (PTAD_PTAD3 == 0){};

   // Then increment counter...       

 

   counter1 = counter1 + 1;   

   // And toggle LED1 

   if (PTBD_PTBD6 == 1){

     PTBD_PTBD6 = 0;

   }

   else {

     PTBD_PTBD6 = 1;     

   }

   // Spin until while signal is high

 

   while (PTAD_PTAD3 == 1){};   

 }

 

}

 

 

 

 

Labels (1)
0 Kudos
2 Replies

284 Views
peg
Senior Contributor IV
Hi Tim,
 
You are not handling the COP watchdog.
Either disable it or reset it.
Clear COPE bit in SOPT1 to disable it,
Or periodically write any value to SRS in your loop.
See section 5.4 of QG8 manual.
 
Regards
Peg
 
0 Kudos

284 Views
UcTechnoGeek
Contributor II
One thing I've notice using the real-time simulator.
 
Data doesn't always update when running. 
 
Go to the data window -> right click -> select mode  -> periodical -> set the update rate (default is automatic and usually waits until you have stopped running, so it doesn't steal cycles).
 
You should now see your counter update (although not real time).
 
uCTechnoGeek
0 Kudos