S08 Capture Mode and Timer Queries.

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

S08 Capture Mode and Timer Queries.

480 Views
pawankumar
Contributor III

Hi Friends,

 

Am using the MC9S08DZ60 eval board. I would like to do the following.

 

Capture a Rising edge-->Start a Timer of 32ms--> On Overflow, run a couple of statements in an ISR.

 

This is similar to the Pulse Accumulator in HC11 controllers.

 

My Assumption :

 

Timer and Capture mode are not related. Reason :

Wrote a program with capture mode disabled. Timer automatically starts and goes on as soon as it is initialized. Is this correct?

 

My Query :

 

I decided to initialize the Timer inside the ISR of Rising Edge Capture. So, baby step,  wrote a simple program to Capture only Rising Edges, but the ISR is being called in both Rising and falling Edges. Here's the code. (Your Advice on this approach also is required)

 

void inittimer(void)

{

TPM1MODL = 0x40;

TPM1MODH = 0x1F;

TPM1C1SC = 0x40;

TPM1C1SC_ELS1A=1; //Rising Edge capture

TPM1C1SC_ELS1B=0;

TPM1SC=0x08;

TPM1SC_TOIE=0;

}

 

interrupt  VectorNumber_Vtpm1ch1 void timeredge(void)

{

  char temp1;

  DisableInterrupts;

  sendstr("Rising Edge \r\n");

  counter++;

  printf("%d \r\n",counter);

  temp1=TPM1C1SC;

  TPM1C1SC_CH1F=0;

  ping4=~ping4; //Toggle a GPIO to monitor with a scope.

  led2=~led2; //Toggle LED

  EnableInterrupts;

}

 

volatile static int counter; //Defined before main().

 

I am sure there's no debouncing. I am Observing the TPM1Channel1 Pin on scope, which I have pulled up to 5V through a 2.5K resistor. I use a wire from ground to bring the pin low when required. I get beautiful square waves with no noise.

 

Please guide me on any of the 2 ways, so that I can Proceed further.

Labels (1)
Tags (1)
0 Kudos
1 Reply

346 Views
Leojunin
Contributor III

Hi pawan

What I would do is:

The first error I see is that you must write the module TPM1MOD in order TPM1MODH then TPM1MODL or load the 16-bit value and upload TPM1MOD.

TPM1MOD = 0x1F40;

Write entire TPM1C1SC register once to avoid any error.

TPM1C1SC = 0x44;

To save code, removes "DisableInterrupts" and "EnableInterrupts" if the interruption of sets the I bit in the CCR and disables subsequent interruptions and enables on the exit of IRQ.

Another thing I would check is that the generating source for the rising edge, has no debounce. May not have these two very close measuring rising edges.

0 Kudos