1 2 Previous Next 20 Replies Latest reply on Jul 4, 2014 6:23 AM by user_364022632

    How to control endless loop's cycle duration in PSOC 5LP ?

    user_364022632

       Please help me to find some solution.

         
          I have this loop:     
         
           for(;;)   
         
              {                 
         
              
         
                  HM_step();   
         
                  val=HM_Y.ECG;        
         
              
         
                  uint8 val2;        
         
           val2=(int)(val)*1+35;   
         
              
         
           while(USBUART_1_CDCIsReady() == 0u);   
         
                                  USBUART_1_PutData(&val2,1);        
         
              
         
              }    
         
          and it works with 1 kHrz frquency (cycle duration is 1miliSec. ). Can I decrease this cycle duration until 10 microSec. ?    
         
          If yes how?   
         
              
         
          Thanks for help.   
        • 1. Re: How to control endless loop's cycle duration in PSOC 5LP ?
          user_1377889

          To shorten the time you spend you'll have to analyze every statement.

             

          I do not know what hides behind your function HM_step() nor what the declaration of val looks like.

             

          Most of the time will be spent in the while waiting for the USBUART getting ready for a new transmit. This is a serial device, and even when sending one byte only that will take a remarkable time span to accomplish that.

             

          So you'll have to think over your communication part to speed up the main-loop.

             

           

             

          Bob

          • 2. Re: How to control endless loop's cycle duration in PSOC 5LP ?
            user_14586677

            One approach might be to move the USBUART handling outside the loop

               

            using DMA and a circular buffer. That way it takes care of itself.

               

             

               

            So one approach wirte data to circular buffer using pointer, inc pointer, generate

               

            DMA request with a status register,and leave the rest to the DMA process. Or use

               

            a combination of verlilog and DMA to automate the serial comm channel using

               

            Verilog to generate the DMA request.

               

             

               

                

               

                      

               

            http://www.cypress.com/?rID=37793     AN52705

               

             

               

            http://www.cypress.com/?docID=44514     AN84810

               

             

               

             

               

            Regards, Dana.

            • 3. Re: How to control endless loop's cycle duration in PSOC 5LP ?
              user_364022632

               Yes exactly, I have some counting functions inside HM_Step() function, but duration for all of them less than 0.0001 sec, so I will delete communication part (USBUART) and I will organize it by another way.  And also please which possibilities are for decreasing counting step duration?  ( is it possible with PWM ?)

                 

              Regards,

                 

              Hakob

              • 4. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                user_364022632

                 Thanks for DMA, it is very cool tool but it is not suitable for my case (I have only one function generated by another program and I need to use it).

                   

                Regards,

                   

                Hakob

                • 5. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                  user_14586677

                  Yes, you can always count with HW to speed things up. In fact

                     

                  you can use the DFB Assembler and the DFB to create a very

                     

                  fast math solution. Take a look at -

                     

                   

                     

                      

                     

                            http://www.cypress.com/?rID=60720

                     

                   

                     
                              uint8 val2;        
                     
                       val2=(int)(val)*1+35;   
                     
                          
                     

                  What is the 2ond statement doing other than assigning a constant to val2, or am I misreading

                     

                  the typing ?

                     

                   

                     

                  Regards, Dana.

                  • 6. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                    chris.barnes

                    I think another important point that you should think about is the fact that you are using a USB_UART device, so though it runs through USB (which has speeds faster than the internal PSoC clock) it is using a UART protocol to send data, which has a lot more limitations on its speed/baud rate.  Be wary of the fact that as you load more and more data into the transmit buffer of the USB_UART, that data may not be able to be sent as quickly as your computations are completing.  The fastest data rate possible will be your baud rate divided by 10, assuming 1 start bit 8 data bits and 1 stop bit, since baud rate is rated by 'bit' not by 'byte'.

                       

                     

                       

                    Perspective: According to the datasheet the default baud rate of the USB_UART_CDC is 115200 baud, which after doing the math will allow you to transfer your data about every 87 microseconds.  This means you can only have the USB_UART transfer data every 87 microseconds if you don't want to overrun your buffer.  To put this in perspective, assuming you are using the default clock of 24MHz on the PSoC, 24MHz = 24000000 cycles/second 115200 baud = 115200 cycles/second (here I use cycles just for convenience of comparison).  24000000/115200 = 208, which means your PSoC has completed 208 cycles before the UART has completed 1, this is why you get the buffer overflow.  I hope I didn't bore you haha.

                    • 7. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                      user_364022632

                       Dear Danna in this case val is double for sending it by USB Uart I transform it to integer so val2 is transformed val and then again I retransform val2 to double in PC.

                         

                      For DFB I understand it is alternative functions and can be programmed very easy right?.

                         

                       

                         

                      regards,

                         

                      Hakob 

                      • 8. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                        user_364022632

                         Dear barney3113 anyway I will delete USB UART from my project. Does the For(;;) cycle's speed depend from steps number inside too or only from clock value?

                           

                         

                           

                        regards,

                           

                        Hakob

                        • 9. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                          user_1377889

                          The time spent inside the main-loop depends on

                             

                          1st. The CPU usage. Number of instructions executed within the loop, not counted in C-lines but in assembly instructions (which can take different number of clock cycles to complete)

                             

                          2nd. The main clock frequency: this is adjustable in the clocks tab of the cydwr-file and usually ranges between 24 .. to 66MHz, some devices up to 80MHz.

                             

                          What is your intention to ask for the main-loop speed? Can you tell us a bit more about your project?

                             

                           

                             

                          Bob

                          • 10. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                            user_364022632

                             Dear Bob I think your answers enough for me to continue my work.

                               

                            I want to develop some human heart model for testing pacemakers.

                               

                            The problem is I am a new in this area also in C programming. I have possibility to make my model in Simulink Stateflow and then generate C code for ARM Cortex processors so I need real time model in PSOC 5 LP  but with this generated code.

                               

                            Generated code has number of counting process and variables changing by situation.

                               

                            I can call from mine loop only one function in this case HM_Step() and get outputs I need.

                               

                            So I think if I will have this function with 0.000001 step and also my loop will have the same step I can put CyDelay( x ) deleay and by changing x variables value calibrate my loop duration untill 0.0001. In this way my loop duration generaly will depeand from x.

                               

                             I hope I can have 0.01 ACCURACY. 

                               

                            With USB UART comunication I couldn't have 0.000001 step (it was only 0.001).

                               

                             

                               

                            regards,

                               

                            Hakob

                            • 11. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                              user_1377889

                              A PSoC is a bit more than just an ARM processor. Since a lot of the required signal processing can be done with the built-in hardware-components that a PSoC5 contains, it might be possible to have a slow main-loop that runs at a constant frequency of, say, 100Hz. Your project will consist of analog processing parts, digital signal processing, communication with (some) different devices and (probably) a human interface. Many of this tasks can be burdened to the hardware, so it does not need any main-loop time. Even the "creation" of new hardware by programming in HDL (Hardware-Description Language) is a choice. Additionally there are 24 "DataPath" objects which contain a small programmable ALU (Arithmetic and Logical Unit) which all run independ from the CPU and from each other.Transfer of data may be done with DMA which does not use the CPU, too.

                                 

                               

                                 

                              But all this will not get created by any code-generating system.

                                 

                               

                                 

                              So you ought to start "Thinking PSoC" by understanding the availlable resources that are already packed into your PSoC5

                                 

                               

                                 

                              Bob

                              • 12. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                                user_364022632

                                 Step by step  )))))))))

                                   
                                        
                                   
                                    regards,   
                                   
                                    Hakob   
                                • 13. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                                  user_14586677

                                  You could also think in terms of using an RTOS -

                                     

                                   

                                     

                                      

                                     

                                            

                                     

                                  http://www.cypress.com/?id=4&rID=57144

                                     

                                   http://en.wikipedia.org/wiki/Real-time_operating_system

                                     

                                   

                                     

                                   

                                     

                                  In so far as using delays, just a suggestion, minimize them as they throw away CPU

                                     

                                  horsepower. Consider instead using interrupt driven demand, that way you maximize

                                     

                                  CPU resources.

                                     

                                   

                                     

                                  Regards, Dana.

                                  • 14. Re: How to control endless loop's cycle duration in PSOC 5LP ?
                                    user_364022632

                                     Dear Dana, yes I will try to minimize my delays as possible.

                                       

                                    Regards,

                                       

                                    Hakob

                                    1 2 Previous Next