# S12z 16 bit timer

Question asked by Shubhangi Mahajan on May 13, 2019
Latest reply on May 14, 2019 by Edward Karpicz

Hello all,

Currently I am exploring VLG-S12zvca evaluation board. Working on 16bit timer.

I have written a small code where I am toggling GPIO pin PP6 and varying its on and off timing by using 16 bit timer, I have set ECLK to 24 MHz. i have observed following observations and Also please find attached doc for reference.

Questions:-

1) if we increment timer counter to maximum value that is 65535 and set prescalar value to 0 , it generates 2.73msec of delay, observed at ppg, it matched with calculations as mentioned below -->

Delay time = Counter value/ Eclk/2^ prescalar value

= 65535/24/2^0 * 10^-6

= 65535/24 us

=2730.625 us

=2.73ms

I want to know that , how much minimum delay can be generated using minimum counter value ?

2) I have checked for counter value 1,2,3,4,5 it consider as 65535 and generates 2.73msec of delay it doesn't matches with calculations o, instead I have observed 1us of delay at counter value of 6, why is it?

 Sr.no. ON time Value Off time value Observed ON time Value Observed Off time Value Calculated on(us) Calculated off(us) 1 65535 65535 2.8ms 2.8ms 2730.625 2730.625 2 10000 65535 420us 2.76ms 416.6666667 2730.625 3 1 65535 2.76ms 2.76ms 0.041666667 2730.625 4 2 65535 2.76ms 2.76ms 0.083333333 2730.625 5 3 65535 2.76ms 2.76ms 0.125 2730.625 6 4 65535 2.76ms 2.76ms 0.166666667 2730.625 7 5 65535 2.76ms 2.76ms 0.208333333 2730.625 8 6 6 1us 1us 0.25 0.25

--> Does it mean that S12zvca internally takes 24cycles for its compiling, boot loading or any other tasks that's why it supports only 1us at counter value 6?

-->is it possible to generate a delay in nanosecond by using s12zvca ? if yes then how?

Also Find code below;-

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

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

void main(void) {

CPMUCLKS_PLLSEL = 1;

CPMUREFDIV_REFFRQ = 1;

CPMUREFDIV_REFDIV = 0x0;

CPMUSYNR_VCOFRQ = 0x1;

CPMUSYNR_SYNDIV = 0x5;

CPMUPOSTDIV_POSTDIV = 0x0;

CPMUOSC_OSCE = 1;

while(!CPMUIFLG_LOCK){}

CPMUIFLG = 0xFF;

ECLKCTL_NECLK=0;

//Use PP6 as output for LED

DDRP_DDRP6 = 1;

TIM0TSCR1 = 0x90;

TIM0TSCR2 = 0x10;

TIM0TIOS_IOS0=1;

for(;;){

PTP_PTP6=1;

TIM0TC0 = TIM0TCNT + 65535 ; /* start an OC0 operation_300ms */

while(!(TIM0TFLG1 & 0x01)); /* wait for PT0 to go high */

PTP_PTP6=0;

TIM0TC0 = TIM0TCNT + 65535 ; /* start an OC0 operation_300ms */

while(!(TIM0TFLG1 & 0x01)); /* wait for PT0 to go high */

}

}