Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/23/07 16:15
Read: times


 
#139668 - Problem with Event Logger
Hello everyone
I am currently working on an event logger.The logger consists of P89V51RD2 in 6 clock mode with a 18.432 crystal.
This logger is designed to log events with time difference more than 80uSec

I am using the PCA counter of the micro controller to count the tick.The PCA counter is set for capture mode on negative edge on Pin P1.3.The clock to the PCA counter is provided by Timer0 in auto-reload mode generating a clock of 125Khz or 8uSec.I am keeping a separate 16 bit register which is incremented after every overflow of the PCA counter in effect creating a 32 bit counter.The user can specify the system to log a specified number of events through the PC.After the required number of events are logged the data is send to the PC .


To give a simple idea of its working.X1 event has occurred and the 32 bit register(16 bit register +PCA capture register) is saved into the RAM .After some time X2 event has occurred again the 32bit register is saved to the RAM.
Calculation to find the time difference

(32 register count when X2 happened - 32 bit register count when X1 happened)*Clock period of PCA counter =Time between the events
<pre>
//This PCA is set for capture mode on negative transition(Capture0 is used)
//Timer0 in auto-reload mode provides the clock to PCA counter with a frequency of 125Khz
//Counter_125Khz.word is the 16 bit upper register of 32 bit counter where the PCA capture register is the lower 16 bit //register.
void PCA_counter_overflow() interrupt 6 using 2
{
if(CCF0) //An event has occurred
{
if(CF &&(CCAP0H==0)&&(CCAP0L==0)) //Has the overflow occurred before the event
{
Counter_125Khz.word=Counter_125Khz.word+1; //This is th e
CF=0;
}
//Save into the RAM where count_data is pointing to the RAM location while data_ptr points to location to store data
count_data[data_ptr++]=Counter_125Khz.byte[0];
count_data[data_ptr++]=Counter_125Khz.byte[1];
count_data[data_ptr++]=CCAP0H;
count_data[data_ptr++]=CCAP0L;

//This variable is use to count the number of events.In the idle loop this variable is checked with the user set //events and stops when it is equal
count.word++;
//I am using a 512Kb RAm to store the data P1.0-P1.2 are used as page selects of the RAM
if(data_ptr==0)
{
page++;
if(page<8)
{
P1 &=0x08; //Masking to
P1 |=page;
}
else
page=0;
}
CCF0=0;//Clear the capture flag
}
if(CF) //If overflow has happened
{
Counter_125Khz.word=Counter_125Khz.word+1;//Increment the upper 16 bit register
CF=0; //Clear the overflow flag
}

}
<\pre>

Log generated
<pre>
(upper 16 bit (lower 16 bit (Counter_1<<16)
counter) PCA Capture +Counter_2
register) =
Counter_1 Counter_2 Total Difference(Event2-Event1)
0 0 0 0
0 8 8 8
0 16 16 8
0 25 25 9
0 34 34 9
0 42 42 8
0 51 51 9
0 60 60 9
0 69 69 9
0 77 77 8
0 86 86 9
0 95 95 9
0 104 104 9
0 112 112 8
0 121 121 9
0 130 130 9

<\pre>

As use see above this is the log file created from the logged data from it we find the time difference between two events is
8*8.1uSec=64uSec

Now coming to the problem
Now i am testing out the logger giving events at various known intervals of time.The problem is time difference logged between the events is not at all accurate.I generated events with different time period using another 8051 and verified with the scope the time period of the waveform .This events were given to my logger for capturing.But there is lots of difference between the logged time and the observed time between events.Also the difference between logged time by the logger and observed time using scope is different for different events.

Test I did to the system.
1)First to confirm whether the Timer0 was giving a 125Khz period i used PCA in the Toggle mode and generated square waveform
and checked with the scope the frequency and calculated back to find the frequency .It was near to 8.1uSec(123.xxKhz)which is acceptable
I used the revised value of 8.1uSec in my calculation but still the accuracy of my reading is poor.

2)To check whether logger was missing events I used a microcontroller to generate specified number of pulses and i set the logger for that number of events.It was able to detect all the events without fail.


Now i am totally out of ideas to debug the system so can anybody give me suggestion or ideas on how to debug this particular problem.

Regards
Gopalakrishnan.N










List of 6 messages in thread
TopicAuthorDate
Problem with Event Logger            01/01/70 00:00      
   the pre tags usage...            01/01/70 00:00      
      Sorry for the goof up            01/01/70 00:00      
         is this consistent?            01/01/70 00:00      
            Yes it is            01/01/70 00:00      
               some more blind shots            01/01/70 00:00      

Back to Subject List