1 2 3 Previous Next 35 Replies Latest reply on Nov 20, 2018 10:59 AM by jorgesilva

    HELP, with example of frequency measurement Error

    grantorax_3720031

      Hi.

      I have a problem with CY8CKIT-059 I'm testing the example https://community.cypress.com/docs/DOC-10228 that everyone refers to when it comes to measuring frequency of a signal, but when I run the example the only thing I get are very different frequency data we are talking about very exaggerated deviations as you can see in the capture,

      I find it very strange and so I ask the community to have if I can reasonably measure frequencies <1Khz +-1Hz of precision square signal.

      before testing the psoc 5LP I have worked with the Psoc 4 cy8ckit-147 and I have successfully performed the frequency meter with a reasonable accuracy, but with the 5LP

      I am not able. I've read practically all the post related to the subject, I've downloaded several examples but I didn't get any clarity about it.

      Thank you.

      Psoc5lp.JPG

        • 1. Re: HELP, with example of frequency measurement Error
          user_342122993

          grantorax,

          In the example provided the period was calculated incorrectly.

           

           

          Replace

          PWM_windowPeriod = PWM_windowPeriod / PWM_FREQ;

          with

          PWM_windowPeriod = (PWM_windowPeriod+1) / PWM_FREQ;

           

          /odissey1

          • 2. Re: HELP, with example of frequency measurement Error
            grantorax_3720031

            Hello, User_342122993, thanks you.

             

            that change you suggest I already have done and the result is the same, the problem is that the measures for a stable signal is very disparate, for a frequency of 500Hz the result by the uart of the 5LP goes from 410Hz to 550Hz what really is very bad, what I do not know if it is a code problem or is a problem of the PsoC 5LP not understand how something so simple can give so many problems, I am rethinking to continue using Psoc ...   because something I've already done with ARDUINO in a super simple and fast way here is costing me a life, and user-engineers are not to waste time solving things that the manufacturer should have left solved before taking the product to the general market.

            • 3. Re: HELP, with example of frequency measurement Error
              user_342122993

              grantorax,

              try the attached project (tested on KIT-059), works OK here. Re: Arduino - it is friendly for tinkering at home due to the huge library codebase, but I can't imagine having it  on professional equipment.

              /odissey1

              Frequency meter_01b.png.png

              Frequency meter_01a.png

              • 4. Re: HELP, with example of frequency measurement Error
                user_49271930

                The difference is visible, but not obvious.

                Where is the mistake?F2.jpg

                • 5. Re: HELP, with example of frequency measurement Error
                  user_342122993

                  Evgeniy,

                  I started with original code provided by <grantorax> and moved ISR from PWM to the Counter and added double-sync to the frequency input pin. Also replaced PWM_WindowPeriod to PWM_WindowPeriod+1 in code as shown in the previous post to make correct timing interval.

                   

                  I don't understand where freq:504 comes from on the second window. It should be 500 (as in my previous post). Do you use external 500Hz generator or internal clock divider?

                  /odissey1

                  • 6. Re: HELP, with example of frequency measurement Error
                    user_49271930

                    Yes, this is an external 504 Hz signal.

                    I do not understand why the variant from <grantorax> is unstable.

                    • 7. Re: HELP, with example of frequency measurement Error
                      grantorax_3720031

                      many thanks to both odissey1 and Evgeniy Pavlov

                      The first thing: the modifications have been substantial since the first project that I publish cypress and I can conclude that this project in the 5LP does not work as they say, which makes me doubt their interest to help the community to use the psoc correctly, leaving this the following is that I have tested the project that you have modified and if it works but as you can see in the image for the frequencies: 100, 200, 400, 500, 800 1000, 1500, 2000Hz show differences of 2,4,6,8,10,14 hz respectively that acomulative error to which it is due? I in the Psoc41xx had achieved resolution of 0.5Hz to 1Khz, it is not possible with the 5LP to get more accuracy or resolution in measurement? I suppose that the FreqDiv_1 block has been used as a test mode, or performs some function within the program?

                       

                      now for curiosity I have measured the frequency on pin 15.5 and the frequency I measure is 496Hz about 4Hz less than the calculated frequency, these inaccuracies are typical of Psoc?

                       

                       

                      P.D.: arduino mega, Due or Zero are just as good as psoc for more professional things the big difference as you say is that they have a great community, personally I think Psoc is a powerful microcontroller and very versatile, but poorly powered by cypress, which is a shame.

                       

                       

                      I send my thanks to all of you.

                      5LP_1.JPG

                      • 8. Re: HELP, with example of frequency measurement Error
                        user_342122993

                        grantorax,

                        Do you provide test frequency from the external function generator or from the PSoC?

                         

                        If frequency generator is external, then there will be deviation from the "true" frequency due to PSoC IMO clock accuracy (~3%). The KIT-095 is a budget board, which has no reference XTAL, as a result, the actual MASTER_CLK frequency deviates from the value reported on the screen, and measured frequency will differ from the one provided by the external generator. It is possible to to lock the master frequency of the PSoC by soldering 24MHz XTAL to the board between P15_0 and P15_1 (check manual).

                         

                        To avoid this hassle, I provided test frequency from the same board using Clock_Test and a Divider. In that case, both generator clock and frequency meter clock are referenced to the same MASTER_CLK, so the frequency reading must be exact. The lowest frequency the Clock_Test can provide is 24MHz / 65535 = 366.2 Hz. To go lower, a frequency Divider (or PWM) can be used. It is better to use explicit divider (e.g. MASTER_CLK/24000) instead of letting PSoC to find closest divider for your frequency.

                         

                        Another way to improve reference clock accuracy is to use USBUART component instead of UART. Then PSoC cab be configured to use the 48MHz clock from USB bus, so that MASTER_CLK accuracy will be 0.25%. This approach is useful if KIT-059 is being used as an external dongle for PC.

                         

                        /odissey1

                        P.S. What board did you use with PSoC4 frequency counter?

                        • 9. Re: HELP, with example of frequency measurement Error
                          grantorax_3720031

                          Hello odessy1

                           

                          Yes, I'm measuring an external frequency of a signal generator, because the utility I want to give is to measure a square signal from 10Hz to 1Khz with a resolution of at least 0.5Hz, something I have already done in an arduino mega with a resolution of 0.1Hz and a psoc 4100PS with a resolution of 0.5Hz I imagined that with the 5LP would gain in resolution and ease of design but I see that not.

                          I understand what you say about the precision of the internal oscillator of the psoc, although in the Psoc creator itself says to be of a "+-1% accuracy", even so I do not understand how with the CY8CKIT-147 which is a 4100PS which I think has no external oscillator, I can get much more precision in frequency measurements, with a more basic hardware configuration and a code a little more elaborate as you can see I'm even doing two measurements "simultaneously" without much trouble,  I have tried to move the project from 4100 to 5LP but we have the problem that the blocks and code are incompatible with 5LP, and with the resolution I have now in this project is not enough and I get angry to think that if with 4100Ps I could do it because with the 5LP that supposed mind is better we are not able, with this one thinks that instead of improving it seems that cypress is worse in its developments making increasingly difficult something that before was done more simply. If any of the Great Engineers of cypress can give solution to this problem.

                           

                          41_codigo.JPG41_codigo1.JPG

                          4100ps.JPGpsoc_relog.JPG

                          • 10. Re: HELP, with example of frequency measurement Error
                            user_78878863

                            First of all: resolution != accuracy. Its perfectly possible to measure a frequency to 0.1 of even 0.01Hz resolution / precision. Precision just tells you how many digits your result has. But accuracy means how exact to reality your result is. And when your reference frequency is only accurate to 1%, a frequency of 1000Hz has only three guaranteed correct digits - no matter how your resolution is, its +-10Hz.

                            Which means if you measure 1000Hz, with a reference clock accurate to 1%, expect to have the result change from 990 up to 1010Hz. This would be perfectly OK. IN the case of your PSoC4100 you probably were just lucky that the internal clock was accurate enough.

                            Your resolution, OTOH, depends only on the gate time. With the example above, the gate time is 1s, so the resolution is 1Hz. Increase the gate time to 10s, the resolution will be 0.1Hz.

                            Since your measurement range involves only low frequencies, it would be better to use the 'period measurement' technique. Use the input signal as gate, and count your reference frequency. That way, you can easily get 0.1Hz resolution for a 1kHz signal, using a 10MHz reference clock (since you can count to 10000 in one period of the input signal).

                            • 11. Re: HELP, with example of frequency measurement Error
                              grantorax_3720031

                              Hola, user_78878863, thank you for your comment.

                              I agree with you that is not the same resolution that precision that I already have clear, I need is resolution of 0.1Hz, Accuracy "is an indication of the correctness of a measurement" better than 0.5Hz.

                              The other issue is that saying "I've been lucky" with the accuaracy 4100 is little to say because what you can think is cypress manufactures its microchips in an unprofessional way leaving margins of error higher than those specified in their product sheets. that "you've been lucky" does not seem to me a good slogan for a company like cypress.

                              Won't it be a question of the code or the optimization of the block rather than luck?

                              I find interesting the solution you propose "'period measurement technique", could you give me some example that works and I can try in my 5LP?

                              Thank you very much for your help.

                              • 12. Re: HELP, with example of frequency measurement Error
                                user_78878863

                                I'm not a Cypress employee (basically none of the users here is). Even if I would be, please be polite.

                                Cypress specifies the accuracy of their internal oscillator. Usually this is then a gaussian distribution with guaranteed limits - most of the chips will be quite accurate, but some (sometimes many) can be at the 1% range. Its just random where a specific chips is in this distribution - hence my reference to 'luck' when you said your PSoC4100 was more accurate than the 5LP.

                                You can, btw., test this by yourself - just route the internal clock to a pin an measure it. If its outside of the spec, you can accuse Cypress of delivering out-of-spec chips.

                                Until then, when your frequency measurement is more off than it should be (according to the accuracy of the internal clock), you should assume that you have a bug in your project (having build more than one frequency counter with PSoC, I know how easy it is to do something wrong).

                                When you need a resolution of 0.1Hz, you need to have a gate time of 10s (using a gated timer).

                                For the period measurement: the circuit is basically the same, but you use the input signal as gate (which was the PWM before), and use a reference clock as input signal to the counter. The rest is just math.

                                • 13. Re: HELP, with example of frequency measurement Error
                                  user_342122993

                                  grantorax,

                                  It is my understanding that the PSoC5 board you used has no XTAL. There are two options: 1. it is possible to trim IMO clock frequency to bring it to e.g. exactly 3MHz (and MASTER_CLK to 24MHz). Please check PSoC5 TRM for details. 2. I suggest simple approach: bring BUS_CLOCK frequency to some digital output pin and measure it (say, result is 23.821 MHz). Now, when calculating output frequency, adjust it by coefficient ( 23.821 / 24.0 ). Best solution: buy PSoC5 FreeSoc2 board (Sparkfun), which has XTAL already installed.

                                  /odissey1

                                  • 14. Re: HELP, with example of frequency measurement Error
                                    user_342122993

                                    grantorax,

                                    also you can easily stabilize IMO frequency on KIT-059 to within 0.07% (see e.g. Digikey 490-17946-1-ND ) by using external ceramic resonator, attached to P15_0 and P15_1 (see pics below) - no capacitors required. The ceramic resonators available at 0.07% accuracy with pitch 0.05", which can be directly soldered between pins on the KIT-059 board. I happened to have 4.18MHz ceramic resonator of radial form-factor ($0.2 @ Digikey), works fine, see settings below.

                                    /odissey1

                                    ceramic_4.19MHz_KIT-059_1a.png 

                                    ceramic_4.19_clocks_1a.png

                                    ceramic_4.19MHz_1a.png

                                    1 2 3 Previous Next