1 2 Previous Next 22 Replies Latest reply on Nov 23, 2020 3:02 PM by IsBe_4812011

    PSoC5LP Digital Multiplexer control without using digital pins?

    IsBe_4812011

      I am trying to use the PSoC5LP to measure 12 flowmeter signals, which are essentially pulse frequency modulated signals. To do this, I initially tried to use a UDB counter for each signal using the setup shown in CE95350 [EDITED: https://www.cypress.com/file/144696/download ]. However, I found that I was unable to pack the digital design into the 24 UDBs (12 counters + 1 shared PWM), so instead I am splitting the signals into 3 groups and using digital multiplexers to sample them. My question is: how can I control the multiplexer without exposing pins? My current hack is to define a width=2 set of pins and then controlling them using Pin_Write(). I think this comes down to not understanding how to use bus signals from other PSoC components, but I just want to set it up so the multiplexers cycle through the signals at some frequency.

       

      Thanks

        • 1. Re: PSoC5LP Digital Multiplexer control without using digital pins?
          LePo_1062026

          IsBe,

           

          I've attached a project based on CE95350 that has 12 Pulse Counting Circuit and one 16-bit PWM with NO muxs.  It fits in a PSoC5LP used on the Cy8CKIT-059..

           

          Is this what you are looking for?

           

          Len

          • 2. Re: PSoC5LP Digital Multiplexer control without using digital pins?
            IsBe_4812011

            Hi LePo,

             

            Sorry, I realize I copied the wrong code example code. I want to implement a 12-channel version of this frequency counter example: https://www.cypress.com/file/144696/download

             

            Thank you for the response!

            • 3. Re: PSoC5LP Digital Multiplexer control without using digital pins?
              LePo_1062026

              IsBe,

               

              OK.  Different project.

               

              Before I try to explore options for you can you supply the following information?

              • Maximum Frequency to be counted.
              • minimum resolution of the resolved frequency measured.

               

              The example you linked uses a 32bit Counter.   This is one of the reasons a 12 input frequency counter is going to consume ALL the UDBs and then some.

               

              If you don't need a high resolution to can get the Counter Reference Frequency (the >clk input) closer to input frequency to be measured.  Therefore you can use a 16bit counter or even better a 8bit.

               

              The example you cited claims to be able to measure from 20Hz to 8MHz.  The measurement window is 50ms.  With a 32bit Counter at 24MHz clocking, A 8MHz input will count 1-3 pulses.   This is fairly low resolution.  The result is either considered as 12MHz, 8MHz or 4MHz.  A resolution of +/- 50%

              A 32bit Counter at 24MHz clocking, A 20Hz input will count be 599,999 to 600,001 pulses.   This is extremely high resolution of 3ppm (0.003%)

               

              If you don't need that wide of a range, you can make good compromises that might allow you to measure 12 inputs without a mux.

               

              A decent rule of thumb is to use a Reference clock that is 20 times the input to sample.  The resolution would be +/- 10%.   If you need more, make the clock 20 times higher.  Resolution = +/- 1%.

               

              Len

              • 4. Re: PSoC5LP Digital Multiplexer control without using digital pins?
                IsBe_4812011

                Hi LePo,

                 

                Yes, sorry about that. And absolutely: These signals are relatively low frequency, and the nominal max frequency on the transducer datasheet is 235Hz. In my own project, I reduced the resolution of each counter to only 8 bits (because of what you mentioned, the 32 bit counter is overkill), and captured them with a period of ~100ms. However, this setup still gave me that UDB consumption error.

                 

                Thanks again for your help

                • 5. Re: PSoC5LP Digital Multiplexer control without using digital pins?
                  LePo_1062026

                  IsBe,

                   

                  Nominal is 235Hz.   What is the minimum and maximum value yo need to measure?  What is the frequency resolution you need?  +/- 1Hz?

                   

                  Len

                  • 7. Re: PSoC5LP Digital Multiplexer control without using digital pins?
                    RodolfoG_11

                    Just to give some food for thought.

                     

                    Another way to solve this problem is to have two UDBs datapath:

                    1) Counter datapath.

                    - It can be 16 or 32 bits.

                    - It has a capture input. It captures on any rising edge of any of the inputs.

                    - It runs continuously.

                     

                    2) Mask datapath

                    - Each input has one bit

                    - Datapath is configured as PI (Parallel input)

                    - It has a capture input. It captures on any rising edge of any of the inputs.

                    - Each input bit is linked to a rising edge detection for the given input.

                     

                    In the firmware side, it triggers an interrupt on capture. It reads the Mask FIFO to find out which inputs has a rising edge. It reads the counter FIFO and update an array containing the latest count values for each of the inputs masked. You can measure the period of two consecutive rising edges of every input.

                    • 8. Re: PSoC5LP Digital Multiplexer control without using digital pins?
                      LePo_1062026

                      IsBe,

                       

                      Here's another project with a 12 input frequency counter that doesn't use a mux. It uses about 62% of the UDBs for the PSoC5.

                       

                      The clock frequency measurement is from 4 Hz to 996 Hz.  The frequency resolution is +/- 2Hz.

                       

                      This project is only HW in the TopDesign.  The SW has not been created.

                       

                      You need to create 12 ISRs.  One ISR for each rising edge of the sync'd input.  In the ISR you need to read the Status Register for that input and substract it from the previously read value.  The count diff(erence) is compared to a frequency chart I list in the page "Counter_Diff_Chart".

                      Since the 7-bit (plus Toggle FF) is continuously running, if the subtraction comes up negative you need to account for the 8-bit counter wrap-around effect.

                       

                      Len

                      • 9. Re: PSoC5LP Digital Multiplexer control without using digital pins?
                        IsBe_4812011

                        Hi LePo, this looks great, thanks for all your help!

                        • 10. Re: PSoC5LP Digital Multiplexer control without using digital pins?
                          LePo_1062026

                          Rodolfo,

                           

                          Thank you for your suggestions.

                           

                          Your recommendations do increase the frequency resolution by using 16, 24 or 32 bits for the counter.  However they potentially both have issues when considering that any of the 12 inputs can occur at any time and can occur virtually at the SAME time.

                           

                          I've attached a new project based on much of your ideas.  It uses a 32bit Timer with capture input.  This should increase the frequency resolution and minimize count wrap-around compensation (It still needs to be compensated).  I also configured for 16 inputs.  I also set the clock to the USB IMO setting 24MHz +/- 0.25% for increased measurement accuracy

                           

                          The TopDesign has two sheets (only one is needed).

                           

                          One is "Combined_ISRs" that use only two ISRs.  It requires the app developer to determine which of the 12 inputs have caused the rising edge to generate the ISR.  One ISR is attached to one GPIO port and the other to another GPIO port.

                           

                          The other sheet is "Individual_ISRs" that use an ISR for each input.  Since each ISR is individualized, it makes it simpler and smaller code.

                           

                          In either of the sheets, the capture input is used to 'increase' the frequency accuracy.  However it is not clear in the datasheet if the Capture FIFO reads the same Capture value if more than one capture occurs and the FIFO is 'empty'.

                           

                          If the FIFO provides an invalid value on multiple _ReadCapture() calls, then the app developer needs to abandon the capture FIFO and read the Counter value directly via _ReadCounter().  This method suffers from a little less accuracy since the counter value is constantly updated and depends on how fast the CPU can process the ISR.

                           

                          Len

                          1 of 1 people found this helpful
                          • 11. Re: PSoC5LP Digital Multiplexer control without using digital pins?
                            RodolfoG_11

                            Hi Len,

                             

                            The idea is to have a single interrupt. There is no need to have individual ISRs, because as you stated, if all rising edges occur at the same time, you would get an accuracy issue.

                             

                            If we have a single interrupt, it is actually a good thing to have all rising edges at the same time on the method I have in mind. You would only have one element in the FIFO to sort it out.

                             

                            The method I proposed would have an issue if all the inputs have a slightly different rising edge, enough of one cycle of the counter clock. In this scenario, you would see an overflow in the buffer. This wouldn't affect the accuracy, but you might miss some measurements.

                             

                            To solve this, you could use a DMA to quickly save the FIFO values to the SRAM in a circular buffer, and then later on have the CPU to sort it out.

                             

                            Going back to your project, you can substitute the array of ISRs with a 16-bit datapath configured with PI (parallel input). A0 should be loaded to FIFO on the same capture signal as the one connected to the Timer_Count.

                             

                            You can add an single interrupt on the Timer_Count interrupt terminal. Or you can have your 16-bit datapath to generate an interrupt on level.

                             

                            I'm not sure if you can use the "irq" signal from the pins. You need to clear that interrupt in firmware. Ideally you want to use the rising edge detection handle totally in hardware. You can use a DFF + NAND for each of the inputs.

                            • 12. Re: PSoC5LP Digital Multiplexer control without using digital pins?
                              LePo_1062026

                              Rodolpho,

                               

                              I've created two working projects.  One with a version of your concepts (Port isr with a  16bit Timer capture) and the other with my concept (individual ISRs and 16bit SRs).

                               

                              I found that your concept definitely uses much less PSoC resources even when allocating 16 pins for inputs.  However BUS_CLK running at 24MHz and having 8 input stimuli the frequency counts measured vary significantly.  I believe this is because the CPU processing is creating delays in reading all the pins on the port if the Port isr is triggered.  This delay is reading the 'live' count of the timer when the Timer FIFO is empty.  I'm also creating conditions with simultaneous rising edges as a "worst-case".

                              It is even more degraded when one of the inputs is at 100KHz (ILO).  Update:  Using the PLL set to 76MHz and the BUS_CLK=PLL helps to improve the results.

                               

                              My concept which uses a pair of Status Registers for each pin input can only allocate 12 pins (24 SRs).  At  BUS_CLK=24MHz, the frequency count is much more stable.  This is because the SRs are preserved on the input (rising edge) change and each input uses a separate SR pair.

                               

                              I've attached the two projects for your review.    Each project dumps to a terminal program @ 115.2K 8N1. Both were written for the CY8CKIT-059.

                              Note:  Your concept [Freq_Measure_16in_ISRs.cyprj] uses the UART through the KitProg.

                              My concept [Freq_Measure_12inputs_SRs.cyprj] uses my Term component in USBUART mode.  Terminal Support Component Library

                              This is because all 12 inputs need 24 SRs.  The UART needs at least 3 SRs.  Therefore using the USBUART does not require any SRs.

                               

                              Len

                               

                              Update:  I updated the Freq_Measure_12inputs_SRs.cyprj.   Tis project is current set with the schematic page "internal_inputs".   It allows the stimuli to be directly routed to the inputs.  It's a simpler means of unit testing.   If you disable the "internal_inputs" sheet and then enable the "external_inputs" page.   It will disconnect the direct stimuli and you must externally route the stimuli to the input pins.   One more note:  I had to change the pins from "Hi-Z digital" to "Resistive pull-down".  In "HiZ" unconnected inputs could see transitions from neighboring pins being stimulated.

                              • 13. Re: PSoC5LP Digital Multiplexer control without using digital pins?
                                IsBe_4812011

                                Hi LePo, your updated project has been really helpful. I had a question about reducing the amount of SRs in the project. I was wondering if instead of using two SRs for each input, we use a single DMA on each channel in the following way:

                                 

                                For each input: (-> means hardware connection)

                                pin input -> DMA drq pin; DMA writes timer count to a memory location on input rising edge; DMA nrq pin -> ISR that does the difference calculation

                                 

                                I'm still quite new to this, so apologies if the reason for not doing it in this manner is trivial.

                                 

                                Thanks again for all your help!

                                • 14. Re: PSoC5LP Digital Multiplexer control without using digital pins?
                                  LePo_1062026

                                  IsBe,

                                   

                                  ... I was wondering if instead of using two SRs for each input, we use a single DMA on each channel ...

                                  Yes.

                                   

                                  The DMA method for each channel will improve your count accuracy.  This is because the DMA channel method can read the BasicCounter value through a single "transparent" (this mode is important) Status Register set within a few BUS_CLK counts when the input transitions occur.   This method will significantly lower your PSoC resources used.

                                   

                                  Note: Increasing the BasicCounter and Status Register set to 24- or 32-bit will not increase the count resolution.  To increase the count resolution, you need to increase the Clk_Cnt input frequency into the BasicCounter as well as increase the Status Register to read more than 16 bits.

                                   

                                  Len

                                  1 of 1 people found this helpful
                                  1 2 Previous Next