4 Replies Latest reply on Nov 17, 2014 5:19 AM by user_14586677

    reading counter register

    ukasz.nawrotek

      I try to read counter register. I'm sure thatTimer_24 works.

         

      in main loop

         

             Timer24_ReadTimerSaveCV(&readTimer);   
              LCD_Position(1,1); 
              LCD_PrHexInt(readTimer);

         

      but LCD shows me only 0000, I couldyn't find why.

        • 1. Re: reading counter register
          ukasz.nawrotek

          I found out that Capture must be set to low, but I don't know why

          • 2. Re: reading counter register
            user_14586677

            The f() you use does not have any parameters, but it returns what

               

            you want.

               

             

               

            Timer16_wReadTimerSaveCV

               

             

               

             

               
                
                 Description:    
                
                 Reads the current Timer16 Count register value, while preserving the Compare registers. This performs a software-solicited, hardware-synchronous counter capture operation. This function should only be used if the contents of the Compare register must be preserved. If the Compare register contents do not need to be preserved, then using the wReadTimer() function is preferred. Note that this API routine used to be called wReadCounter.    
                
                 C Prototype:    
                
                 
            WORD  Timer16_wReadTimerSaveCV(void);   
                
                
                 Assembly:    
                
                 
            lcall  Timer16_wReadTimerSaveCV 
                 
            mov   [wCount], X           ; MSB returned in X
                 
            mov   [wCount+1], A         ; LSB returned in A
                
                
                 Parameters:    
                
                 None    
                
                 Return Value:    
                
                 wCount: Count register contents. MSB is passed in the X register and LSB is passed in the Accumulator.    
               
               

             

               

             

               

             

               

            So you should have something like -

               

             

               

            readTimer = Timer24_ReadTimerSaveCV( );  

               

             

               

            Regards, Dana.

            • 3. Re: reading counter register
              ukasz.nawrotek

              it's  right for 16bit timers, but for 24bits timers datasheet says

                 

              Timer24_ReadTimerSaveCV

                 
                  
                   Description:    
                  
                   Reads the current Timer24 Count register value, while preserving the Compare registers. This performs a software-solicited, hardware-synchronous counter capture operation. This function should only be used if the contents of the Compare register must be preserved. If the Compare register contents do not need to be preserved, then using the ReadTimer() function is preferred. Note that this API routine used to be called ReadCounter.    
                  
                   C Prototype:    
                  
                   
              void Timer24_ReadTimerSaveCV(DWORD * pdwCount);   
                  
                  
                   Assembly:    
                  
                   
              mov   A,[pdwCount]
                   
              mov   X,[pdwCount+1]
                   
              lcall _Timer24_ReadTimerSaveCV
                  
                 
              • 4. Re: reading counter register
                user_14586677

                There is a note in datasheet that alludes to an issue with Capture,

                   

                but is not "complete" in its warning, or so I think -

                   

                 

                   
                    
                     Capture    
                    
                     

                This parameter is selected from one of the available sources. A rising edge on this input causes the Count register to be transferred to the Compare register. The software capture mechanism will not operate correctly if this parameter is set to a value of one or is held high externally.

                     

                 

                    
                   
                   

                Regards, Dana.