How does GetTimeCounterP work?

nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

How does GetTimeCounterP work?

 · 
Posted: 21.04.2012 - 09:19  ·  #1
In another thread, I'm trying to decode a X10 Rf signal, basically a serial protocol.
When I came across GetTimeCounterP, I thought my dreams had come true.

But... I'm having trouble making it work.
It would appear that GetTimeCounterP starts counting on a High to Low transition. So it gets the Loigc 0 period first and then the Logic 1 period.

How do I get GetTimeCounterP to start on a Positive ie Low to High transition?
So that it gets the Loigc 1 period first and then the Logic 0 period.

There are long levels of Logic 0 between messages. This is the Idle state.
And I don't want to have to add an inverter. The PCB already exists.

The format is -
Header = 9mS at Logic 1, then 4.5mS at Logic 0
A received 0 (Zero) bit is indicated by 0.55mS at Logic 1, then 0.55mS at Logic 0
A received 1 (One) bit is indicated by 0.55mS at Logic 1, then 1.6mS at Logic 0

My code looks something like
Code

Device = mega8, VCC=5;
Import FreqCount;

Define
  ProcClock      = 16000000;       {Hertz}
  SysTick        = 10;             {msec}
  FreqTimer      = Timer1;

Var
  CntHigh,CntLow     : word;
  CntOverFlow : Boolean ;
Begin
   SetFreqCountMode(TPulseBase100ms);

Loop
    CntOverFlow:= GetTimeCounterP(CntHigh,CntLow);
    If (CntHigh > 800) AND (CntHigh < 1100) {AND (CntLow > 350) AND (CntLow < 500)} then  WriteLn(SerOut, 'HEADER='+IntToStr(CntHigh:6:2)+'ms '+IntToStr(CntLow:6:2)+'ms ');  Endif;
        If (CntHigh > 30) AND (CntHigh < 60) AND (CntLow > 30) AND (CntLow < 60) then ST:=ST+'0'; Endif;
        If (CntHigh > 30) AND (CntHigh < 60) AND (CntLow > 150) AND (CntLow < 170) then ST:=ST+'1'; Endif;
      if GetFreqCountOvrFlow <> 0 then
        WriteLn(SerOut, ST);
        St := '';
      endif;




Neil.
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1408
Registered: 03 / 2005
Subject:

Re: How does GetTimeCounterP work?

 · 
Posted: 21.04.2012 - 16:44  ·  #2
Hi Neil.

Well I suppose the obvious answer is use

GetTimeCounterP( CntLow, CntHigh);

This effectively inverts the states.

Regards

Merlin.
nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

Re: How does GetTimeCounterP work?

 · 
Posted: 22.04.2012 - 05:22  ·  #3
Hi Merlin
The issue is that it starts on a negative edge not a positive edge.

The manual/help file, seems to suggest that it reads the length of the Logic 1 period first and then the length og the Logic 0. But it also contradicts itself in the last statement, implying that it returns Count Total :(

From the help file
Quote
Function GetTimeCounterP (var Count1, Count2: word) : boolean;
Returns the counter values of the last pulse time measure cycle.
Count1: high, Count2: low. False at overflow.


From the manual
Quote

GetTimeCounterP, GetTimeCounterP2
The function GetTimeCounterP returns the result (16bit value) the plain counter content of the last pulse
time measure cycle. The values Count1 and Count2 contain the timer value counted in the “high“ and “low” time of the cycle. So for example it is possible to get the on/off relation of a PWM cycle. If an overflow
occurred a false is returned. The FreqCountMode must be set to PulseMode.
A call to this function also clears the semaphore.
Function GetTimeCounterP(var CountP, CountTot : word): boolean;



Neil
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1408
Registered: 03 / 2005
Subject:

Re: How does GetTimeCounterP work?

 · 
Posted: 22.04.2012 - 11:40  ·  #4
Hi Neil.

Yes I see. I was thinking that because you are in a loop it doesn't matter, but of course the return to the function is not timely.

Sorry.
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   79   93 · Page-Gen-Time: 0.020413s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI