1 2 Previous Next 16 Replies Latest reply on Aug 3, 2014 8:50 PM by user_14586677

    Timer 24

    anas.hashmi

      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.    
         
        • 1. Re: Timer 24
          user_14586677

          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.

          • 2. Re: Timer 24
            user_14586677

            Here is an example project, attached.

               

             

               

            Regards, Dana.

            • 3. Re: Timer 24
              user_14586677

              Some basic F cntr ref material, attached.

                 

               

                 

              Regards, Dana.

              • 4. Re: Timer 24
                anas.hashmi

                 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)

                • 5. Re: Timer 24
                  user_1377889

                  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

                  • 6. Re: Timer 24
                    user_14586677

                    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 ?

                       

                     

                       

                     

                    • 7. Re: Timer 24
                      anas.hashmi

                      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

                      • 8. Re: Timer 24
                        user_1377889

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

                           

                         

                           

                        Bob

                        • 10. Re: Timer 24
                          user_14586677

                          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.

                          • 11. Re: Timer 24
                            anas.hashmi

                            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

                            • 12. Re: Timer 24
                              user_14586677

                              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.

                                 

                               

                              • 13. Re: Timer 24
                                anas.hashmi

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

                                • 14. Re: Timer 24
                                  user_14586677

                                  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.

                                  1 2 Previous Next