Timer 24

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi

   
    I developed a design for frequency measurement; this design was successfully completed using Timer16 that is clocked by external 10-MHz OCXO.    
   
        
   
    I'm trying to improve precision, I've tried to replace Timer16 by Timer24. I did the following changes:   
   
    1. I Changed this statement from   
   
    
      uiTimSta = Timer16_1_wReadTimer();    
    
     to    
    
      Timer24_1_ReadTimer(&uiTimSta)      ;    
    
     2. Updtaed the interrupt flag based on new UM position    
   
   

 

   
    
     ​However, the frequency output was incorrect. I've tried many options:    
    
     1. Replaced Timer24 by Counter24​    
    
     ​2. Created a new UM "tmp_timer24_1" and follow the changes that was introduced in this post:    
         
          
    
     None of mentioned options worked!     
    
          
    
     Do you have any suggestions? Could you please attach a project that include a working Timer24 with ReadTimer() function that I can build on it?    
    
          
    
     Thanks.    
   
0 Likes
16 Replies
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

Post your project and forum can take a look at it -

   

 

   

    

   

          

   

“File”                                                           Designer

   

“Archive Project”

   

Use Firefox or IE, not chrome to post.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

Here is an example project, attached.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

Some basic F cntr ref material, attached.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 Hi

   

Thank you for your comments

   

I tried to modify the program you attached:

   

1. I replaced the LCD with UART

   

2. Changed period for counter to 2,000,000

   

3. Changed clock for timers to 210kHz instead of 200kHz (reserved VC3 for UART)

   

 

   

I tested an external 32.768 kHz signal; the program works but results were incorrect "project is attached"

   

Also, I noticed that results changed when delay is added

   

Is there any way to increase precision of measurements? (i.e. 32786.324342 Hz)

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The forum thread you point to in your initial post is a (nearly) ten year old thread, when there have been issues with the timer or counter component so far they will have been corrected.

   

Increasing the precision of frequency measurement mainly needs a more precise clock. In the case of PSoC1 it means a quarz generating the needed main frequencies, so with your initial solution you are on the right track.

   

When you cannot get your 24-bit component to work (and I am very sure that it works correctly) you might have something gone amiss. use Designer -> File -> Archive Project and then attach the resulting file, so that we all can have a brief look at. DO NOT use chrome there is a bug with the forum software. Use internet explorer or firefox instead

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

The ref material I attached earlier discusses in depth errors and accuracy

   

in various freq cntr methods.

   

 

   

In short the accuracy of the measurement primarily dictated by gate accuracy.

   

If you are deriving gate from internal PSOC CPU clock then from datasheet its

   

accuracy shown below. If you want more accuracy then CPU clock/gate must

   

come from external precision oscillator. It then controls accuracy/drift.

   

 

   

What accuracy and rersolution and range of frequency measurement do you

   

want ?

   

 

   

0 Likes
Anonymous
Not applicable

My project is attached, I replaced the design of a Timer16 (perfectly working) with a Timer24, this program (after adding Timer24) returns random numbers!

   

*Commetned lines are previous implementation using Timer16

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your progect did not get attached. Use ms internet explorer to post, switch on compatibility mode.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable
0 Likes
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

The approach you take vs the one I supplied has the following issues -

   

 

   

1) To maximize freq measuring range you load 24 bit counter or timer with

   

its max 24 bit value, 16,777,215. Gate starts timer/counter counting down,

   

and when gate goes low timer/counter stopped. In case of cntr thats a direct

   

connection from gate to cntr enable. In case of timer thats a SW method.

   

When you grab timer/counter value, subtract that from 16,777,215 and that

   

is the number of counts/Hz (if gate high  = 1 sec).

   

 

   

2) The use of counter vs timer yields a +/- 1 count error in measurement, whereas

   

use of a timer has more SW slop in it, affected by ISRs, etc..

   

 

   

3) Period of gate unimportent, its high time when counter/timer allowed to count

   

that matters. So if high time = 1 sec, then count value from counter reads out in

   

Hz.

   

 

   

In short I think cntr based solution more precise because of its enable pin being

   

tied directly to gate.

   

 

   

Because the gate is derived from internal PSOC clock that has several % inaccuracy,

   

so your readings will reflect this.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Thank you for your comments

   

 

   

The design (example you posted) works now, but I have some questions:

   

1. Is it possible, in this design, to clock the counter24 directly by external oscillator without setting it up as external main oscillator?

   

2. Is there any chance to get more accurate results? (more digits 32768.42342 Hz instead of 32768 Hz)

   

 

   

Thanks

0 Likes
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

1. Is it possible, in this design, to clock the counter24 directly by external oscillator without setting it up as external main oscillator?

   

 

   

Not sure what you mean by this. The counter input is external unknown frequency to measure.

   

So not sure what you are asking.

   

 

   

2. Is there any chance to get more accurate results? (more digits 32768.42342 Hz instead of 32768 Hz)

   

 

   

What you are asking is to measure .00001 part in 32768 which equals .0003 ppm which is better than

   

most atomic clocks. That would have to be the resolution of the gate signal, which would have to come

   

from an external source. The reference material I supplied allows you to make these calculations.

   

 

   

Regards, Dana.

   

 

0 Likes
Anonymous
Not applicable

 I mean that I want to measure unknown frequency using external oscillator source to get higher precision 

0 Likes
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

What you are asking is to measure .00001 part in 32768 which equals .0003 ppm which is better than

   

most atomic clocks.

   

 

   

Then simply make the calculations for error, temp, etc.. and look at cost consequences.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 Tnank you very much.

0 Likes
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

One possibility to investigate, low cost, is GPS derived gate for the counter.

   

 

   

    

   

          http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&ved=0CCoQFjAD&url=http%3A%2F%2Fwww.si...

   

 

   

Regards, Dana.

0 Likes