1 2 3 Previous Next 31 Replies Latest reply on Nov 1, 2017 12:08 PM by christian.liebhardt_1922061

    Fix Function Timer Component help

    user_352784942

      Hello,

         

      I have been struggling to have the fixed function timer component to do what I need.   I need a timer that starts when needed and then programmatically check the status of the timer to determine if the timer has expired.   For the life of me I cannot achieve this with the FF Timer component.  This is to be accomplished through software,  no hardware connections or interrupts needed.

         

      What am I doing wrong? 

         

      Please take a look at the attached project.  It is a  very basic test project.  The idea is to start a timer,  check for timer expiration and if so turn an LED on, if not turn the LED off.  The timer is configured for "one shot" and I would have thought that once the timer expired the timer would not be reset.  But it appears the simple act of reading the status register is resetting the timer and causing it to start.   The bottom line is that in the supplied project the LED blinks continuously which not what I am attempting to achieve.   

         

      Thanks,
      Ron

        • 1. Re: Fix Function Timer Component help
          user_1377889

          I changed your device to an PSoC5LP (I don't have another PSoC active in ma lab) compiled, setting breakpoints at lines 80 and 82 in main()where you write to the LEDs and I get only one stop, not more.

             

           

             

          Bob

          • 2. Re: Fix Function Timer Component help
            user_352784942

            Hi Bob,

               

            Yep, I see the same results.  After the firmware is uploaded to the PSoC 3,  the led blinks which means the comparison test at line 77 is alternately testing true then false (at the timer component value of 2 seconds).  But, if I put the firmware into debug mode the test is only successful once and then fails on every iteration there after.  If I reinstate line 85 the firmware works as expected,  whether in debug or not. 

               

            I think I found yet another bug in either PSoC Creator 3.1 or the component. 

               

            BTW:  compiler optimization has no effect on this issue.  I have tested this test program at all available optimization levels.

               

            Thanks,

               

            Ron 

            • 3. Re: Fix Function Timer Component help
              user_1377889

              When reaching a breakpoint the CPU stops, but all internal hardware keeps running. This sometimes leads to strange behave.

                 

              Under Creator -> Tools -> Options -> Program/Debug you find an option mamed "Disable Clear-On-Read". I was told that this may have influence in situations like yours.

                 

               

                 

              Bob

              • 4. Re: Fix Function Timer Component help
                user_352784942

                Hi Bob,

                   

                Thanks for the info.  I will give that a shot in a day or two.  In the mean time I have created a case on the issue. 

                   

                While I have been dealing with this issue for over a week, during that period of time I  created my own timer based on a clock component and a counter variable.  It is serving the purpose for now but it is not as accurate (I'm sure) as using a timer component.  I will be the first one to admit that I may be doing something wrong, but at this point I can't determine what it may be. 

                   

                Thanks for being here and offering your invaluable advice and help,

                   

                Ron

                • 5. Re: Fix Function Timer Component help
                  user_14586677

                  Why not add a 1 bit status register tied to the Tc pin of the timer,

                     

                  and set it as sticky ? Then just poll that status register.

                     

                   

                     

                  Regards, Dana.

                     

                   

                     

                  • 6. Re: Fix Function Timer Component help
                    user_352784942

                    Hi Dana,

                       

                    Yes, I could do that and it would solve part of the problem of when the timer has expired.  However the issue I am experiencing is that the timer resets itself and starts again.   I need to start the timer when a certain event occurs elsewhere in the program.   But if the problem as I mentioned previously is that reading the status register is resetting the timer, then your solution just may do the trick.  I will give it more thought and give it a go.

                    • 7. Re: Fix Function Timer Component help
                      user_1377889

                      I cannot reproduce that reading the status of a one-shot-timer resets it or restarts it for a PSoC5LP.

                         

                      I will create a test-program for the CY9CKIT-050 and post it here.

                         

                       

                         

                      Bob

                      • 8. Re: Fix Function Timer Component help
                        user_14586677

                        If you set the timer to one shot mode it stops at count = 0,and does not

                           

                        start back up. So you can get the timeout event with the status register and

                           

                        with an API at a time of your choosing reset and restart the timer. Or

                           

                        use a control reg on reset pin, either way.

                           

                         

                           

                        Regards, Dana.

                        • 9. Re: Fix Function Timer Component help
                          user_1377889

                          Probably the reset is the problem. The datasheet tells only about the hardware reset and a software-reset via API is not provided.

                             

                          So you need to stop() and Start() the one-shoot when it has couted down.

                             

                          See attached project.

                             

                           

                             

                          Bob

                          • 10. Re: Fix Function Timer Component help
                            user_14586677

                            The reset is as Bob stated not available from an API, per se. The Start()

                               

                            seems to handle that.

                               

                             

                               

                            If you use a control reg and reset input the following apply -

                               

                             

                               

                             

                               

                             

                               

                            Regards, Dana.

                            • 11. Re: Fix Function Timer Component help
                              user_1377889

                              Afaik the Start() API allone does not work as a reset, you have to Stop() the timer before.

                                 

                               

                                 

                              Bob

                              • 12. Re: Fix Function Timer Component help
                                user_352784942

                                Hello,

                                   

                                Thanks to both of you for the information.  I will continue to give this a go and come back here with the results.  This a bit more complex than I had originally thought.  It appears the software API is not what I was hoping for.  The API for the timer component is more complex than it needs to be.  A basic timer really only needs:

                                   

                                Start timer, reset timer, stop timer and timer status.  (From my understanding, the API Timer_Start() does more than simply start the timer.  It powers up the component and then starts the timer and is basically the same for Timer_Stop() which stops the timer and powers down the component.  The powering up and down is not necessary. 

                                   

                                Thanks,

                                   

                                Ron

                                • 13. Re: Fix Function Timer Component help
                                  user_1377889

                                  Yes, you are quite right, many of the components could be less complex, to serve as many users as possible Cypress has built some jack of all trades devices (hopefully my translator didn't guide me wrong) and so there might be a lack of simplicity.

                                     

                                  But

                                     

                                  Nobody hinders you to build your very own timer component that exactly reflects the properties you just mentioned. You may even copy the existing files for the timer, rename the component-name and strip down the component to the barest. There is a Component Author Guide installed in your cypress directory that might help you with the design.

                                     

                                  This takes some time, I did it and later with this knowledge I was able to solve some other projects for my customers.

                                     

                                   

                                     

                                  Bob

                                  • 14. Re: Fix Function Timer Component help
                                    yfs

                                    This one had me scratching my head for a while but I think this is what you need.

                                       

                                    The _Start API does start the timer running. In the following I use the TC output to control a flip-flop. After the 1s timer period my LED comes on forever. The only C code is Timer_Start();

                                       

                                       

                                    In your project you are using SW to detect the TC. I did that with the following:

                                       

                                       

                                     

                                       

                                    In C I wrote this...

                                       

                                        LED_Write( 0 );     // LED Off
                                       
                                        Timer_Start();  
                                       
                                        for(;;)
                                        {
                                            status_reg = Timer_ReadStatusRegister();

                                            if( status_reg & 0x80 )
                                            {
                                                LED_Write( 1 ); 
                                                CyDelay( 250 );     // Allow time for my old eyes to see the LED
                                            }
                                            else
                                            {
                                                LED_Write( 0 );  
                                            }
                                        }

                                       

                                     

                                       

                                    Note that the timer does not restart in this case but the TC bit I am reading does get cleared. I think that is because it is only asserted for one cycle. The datasheet is a little misleading on this matter. it says "The tc output is available to monitor the
                                    current value of the counter register; it is high while the counter is zero." and "The TC signal is always a single clock cycle pulse". The former implies that it remains high for a long while but, actually, the counter is reloaded on terminal count but the timer is stopped. As a result the TC is asserted for just one clock pulse. The word "while" in the first sentence is what threw me off.

                                       

                                    Hope this helps...

                                       

                                    -- Mark

                                    1 2 3 Previous Next