How to count clock ticks on a MC131213 SRB or on a NCB

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

How to count clock ticks on a MC131213 SRB or on a NCB

2,494 Views
Topoestivo
Contributor I
Hi,
I'm a newbie about MC13213...

I've a question for you:

how can I read the value of HCS08 mcu clock ticks since it started?

I thought it was possible tu use the clock() function in time.h library, but it returns a value of 0...

I'm writing C code on CodeWarrior, is it possible to use this function clock() or some one other?

Bye Bye, Andrea.

P.S. sorry for my poor english.


Message Edited by J2MEJediMaster on 2007-06-22 10:36 AM
Labels (1)
Tags (1)
0 Kudos
4 Replies

568 Views
fgs_chuck
Contributor I
Topoestivo,

Neither clock() nor time() appear to be implemented for the HCS08 platform. If your time span is small, you could read the Timestamp reg in the radio modem - SPI registers 25 & 26. The SMAC function PLMEGetTimeRequest() does this to return the current time. Unfortunately, this is only a 24-bit value. So, it rolls over about every 61 seconds with the default modem frequency of 250 KHz.


Regards,
Chuck
0 Kudos

568 Views
Topoestivo
Contributor I
So...

clock() or time() seems to be useless for my goal.

I'm trying to implement a differente way... I hope it works, and I wait your suggests:

I would check the value of clock ticks every 25 ms, exploiting TPM registers and control bit, through an ISR on TPM1OF register, according to a 4MHz frequency of mcu clock.... (isn't it?)
TPM1OF changes to $0000 after reaching the modulo value programmed in the TPM counter modulo registers.
I thought this could be possible in this way, placing this code in vectortable.c :

Code:
#define TIMER_CNT 0x9E58; //Setting the granularity of a tick every 25mstypedef void(*tIsrFunc)(void);extern unsigned long timer0_tick; //this variable will be count the ticksextern interrupt void IRQIsr(void);//extern interrupt void KBD_ISR();extern interrupt void Vscirx();extern interrupt void Timer0_ISR(){ //Start of my ISR                                 unsigned long long i;     TPM1SC_TOIE=0;     i = TIMER_CNT + TPM1CNTL+(TPM1CNTH<<8);     TPM1CNTL= i;     TPM1CNTH= (i>>8);     TPM1SC_TOIE=1;     timer0_tick ++;     };

 [..... some other code lines after]

Timer0_ISR      ,       /* vector 08: TPM1OF */
       

Could it works good?
Will timer0_tick contain the value of time ticks after mcu started?
Can I use in this way timer0_tick in main.c and send it to another device?




Message Edited by Topoestivo on 2007-06-26 06:58 PM

Message Edited by Topoestivo on 2007-06-26 06:59 PM
0 Kudos

568 Views
JanellA
Contributor I
Did this method work? I'm in need of a timestamp of some sort on the MC1321x.
0 Kudos

568 Views
CrasyCat
Specialist III
Hello
 
According to {Install}\Help\PDF\Compiler_HC08.pdf, Chapter "ANSI-C Library Reference" the function clock is marked as "Hardware Specific". That means implementation from this function is hardware specific, so no implementation is delivered as part of the libraries.
 
If you want to be able to use it, you need to implement it yourself.Make sure to place the source file with your implementation of clock function prior to the ANSI library in the Link Order view, otherwise the linker will take the implementation from the library(which is always returning 0).
 
CrasyCat
0 Kudos