1 2 3 Previous Next 41 Replies Latest reply on Nov 30, 2016 11:11 AM by vijayr.acns_1628096

    PSoC 5LP and PSFB

    vijayr.acns_1628096

      Hi All,

         

       

         

      I am using CY8CKIT-050 Development Board for my project purposes. I intend to generate a PSFB PWM signals from the PSFB block such that the phase shift is like a sine wave. To explain it in another way, I want my phase shift to gradually increase from 0 to maximum value and then reduce to 0 within 10 ms (half wave of a 50 Hz sine wave). It is similar to a sinusoidal PWM where the ON time of PWM increases from 0 to maximum and then reduces to 0 in 10 ms. The only difference here is that I need my phase shift to change the way a sinusoidal PWM changes.

         

      My PWM signal is 10 kHz i.e. 10^(-4)s. My phase shift to increase from 0 and then return back to zero in 10 ms. So there would be 100 PWM signals (.01s/.0001s). From this information I came up with the sine table as given below after having a look at this article 'http://microcontrollerslab.com/spwm-generation-using-pic16f877a-microcontroller/'.

         

      uint8 sine_table[101] = {255, 254, 253, 252, 251, 250, 248, 246, 244, 242, 239, 237, 233, 230,
                              227, 223, 219, 215, 210, 206, 201, 196, 191, 185, 180, 174, 168, 162,
                              156, 149, 143, 136, 129, 122, 115, 108, 101, 93, 86, 78, 71, 63, 55, 47,
                              39, 31, 23, 16, 8, 0, 0, 8, 16, 23, 31, 39, 47, 55, 63, 71, 78, 86, 93,
                              101, 108, 115, 122, 129, 136, 143, 149, 156, 162, 168, 174, 180, 185, 191,
                              196, 201, 206, 210, 215, 219, 223, 227, 230, 233, 237, 239, 242, 244, 246,
                              248, 250, 251, 252, 253, 254, 255};

         

      I have included my code along with this post. Please have a look at it and do point me in the right direction so that I can sort out this issue at the earliest.

         

      Thanks in advance.

        • 1. Re: PSoC 5LP and PSFB
          user_1377889

          The PSFB component is not included with your project.

             

          Your error is caused by running your infinite loop at max speed. I would suggest you to setup and start a 100Hz timer. At that interrupt you change the WriteCompare() value. Use 100 points for the sine table, not 101.

             

           

             

          Bob

          • 2. Re: PSoC 5LP and PSFB
            user_342122993
                    Phase update rate of 10kHz is rather high for CPU If there are other tasks present. If indeed you plan to drive a real bridge, use DMA to transfer sine table array to PFSB component.   
            • 3. Re: PSoC 5LP and PSFB
              vijayr.acns_1628096

              I had already added PSFB component in the dependency list of the project . I believe this is what you were trying to say when you said 'The PSFB component is not included with your project'.

                 

              Thanks to you now I understand what was going wrong. Like you said I should have included a timer which generates an interupt on overflow and then increment the counter of the lookup sine table. But I believe the timer should be a 10 kHz one right? Because I need to increment my phase after every 10 kHz. So I should be changing the WriteCompare() value on every 10 kHz interrupt. Isn't it so?

                 

              As you suggested I used 100 points for sine table.

                 

              I have updated the code and attached along with this post. Please have a look at it and do give me your valuable suggestions and feedbacks.

                 

              Thanks a lot for offering me a helping hand.

              • 4. Re: PSoC 5LP and PSFB
                vijayr.acns_1628096

                In this project I don't have any tasks running other than phase updating. I just need to update the phase shift every 10 kHz. For that, as Bob suggested, I introduced a Timer component which gives me an interrupt every 100 us i.e. 100 kHz and then I increment my counter for lookup sine table on every interrupt.

                   

                My knowledge on DMA is very limited. Could you please point me to the right sample project which employs DMA similar to my application?

                   

                Thanks for offering your advice.

                • 5. Re: PSoC 5LP and PSFB
                  vijayr.acns_1628096

                  Hi Bob,

                     

                  Please ignore the above attached bundle. I made a couple of changes from the above code and I have attached the latest bundle along with this post. I verified the waveforms in an oscilloscope. I found that the ON time for the PWM signals were only 4 us out of 100 us (approximating 106.4 us) which is considerably very small and I wouldn't receive much of an overlap. How do I increase the ON time to say 40 us?

                  • 6. Re: PSoC 5LP and PSFB
                    vijayr.acns_1628096

                    Hi Bob,

                       

                    Could you please have a look at the attached screenshot of my lookup table? In that it is shown that sine_table has data type uint8 while the elements have data type unsigned char. And along with the values in each location of the array there are other values displayed too. Such as '\377' for 355, '\375' for 253, '\374' for 252 and so on. This goes on for all the elements. This looks like ASCII characters. Is there something wring with my array initialization?

                       

                    • 7. Re: PSoC 5LP and PSFB
                      user_1377889

                      You need a full sine (100 points) within 20ms which comes to 5000Hz. This is manageable with a PSoC5. What is your output PWM frequency?

                         

                       

                         

                      Bob

                      • 8. Re: PSoC 5LP and PSFB
                        vijayr.acns_1628096
                                Hi Bob, The period of my desired sine wave is 20 ms i.e. 50 Hz. My PSFB PWM is 10 kHz. If I am not wrong I need to create sine table for just one half right? Because the same sine table can be used for the negative half too. So I need 100 PWMs of 100 kHz to generate the half cycle. I believe my calculations are correct. Please correct me if I am wrong.   
                        • 9. Re: PSoC 5LP and PSFB
                          user_1377889

                          So you want to have only two single pulses of the desired length for each of the 100 points, not a series of (for instance) 1000 pulses (@10MHz) for each of the 100 points.

                             

                          Yes, you even might use only 25 points for the sin table and calculate, using some addition, the index for the quadrant. But that will save you just 75 bytes in flash, not worth the effort.

                             

                           

                             

                          Bob

                          • 10. Re: PSoC 5LP and PSFB
                            vijayr.acns_1628096
                                    Yes Bob. I wish to have only single pulses for each of the 100 points. I thought of keeping it simple. Could you please have a look at my code and suggest where I have went wrong? One issue is that the on time of the pulse is only 4 us in a 100 us pulse. And the phase shift isn't changing even after varying the compare value of PSFB in the ISR.   
                            • 11. Re: PSoC 5LP and PSFB
                              user_1377889

                              Still I do not see the PSFB component in your project.

                                 

                              You did not clear Timer_1's interrupt cause. You need to call Timer_1_ReadStatusRegister() which will clear the sticky bits, see datasheet.

                                 

                               

                                 

                              Bob

                              • 12. Re: PSoC 5LP and PSFB
                                vijayr.acns_1628096
                                        Could you please send me the screenshot of the schematic that you are seeing? Because I have added the PSFB component in the project and I am generating the PSFB signals. I don't know why you are not able to see it. Could you tell me what I should do in the project so that you can see the PSFB component? I have already included the PSFB component in the dependency list. Oh no. This is so silly of me. I should have cleared the flag at the end of the ISR. Is that what you meant by clearing the sticky bit? Or are there other bits that need to be cleared?   
                                • 13. Re: PSoC 5LP and PSFB
                                  user_1377889

                                  "Or are there other bits that need to be cleared? " See datasheet.

                                     

                                  I do not need to see the (yet missing) component, obviously I can give some hints without it ;-))

                                     

                                   

                                     

                                  Bob

                                  • 14. Re: PSoC 5LP and PSFB
                                    vijayr.acns_1628096
                                            Keeping aside the clearing of required bits at the end of the ISR is there anything else remaining for me to do? Did you have a look at the attached screenshot of the lookup table while debugging? Is it the way it's supposed to be? I am doubtful because I can see each elements are classified as unsigned char and the numbers given in the table is taken as ASCII values.   
                                    1 2 3 Previous Next