Tim Carr

timing issues on HCS08

Discussion created by Tim Carr on Dec 7, 2006
Latest reply on Dec 8, 2006 by Bob Smith

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){};   

 }

 

}

 

 

 

 

Outcomes