1 2 Previous Next 14 Replies Latest reply on Apr 17, 2015 8:42 AM by user_14586677

    Problem PWM signal

    jrme.laporte

       Hello everybody,

         

      I would like to create a PWM signal ( so with the PWM function in PSoC Designer) with a potentiometer at the entrance (to modify the duty cycle of this signal). Everything works fine but I have a little problem: I would like a minimum value for the duty cycle. And when i see the signal at the exit, it's very strange ! It's not smooth. You can see it on the picture.

         

       <a href="http://www.casimages.com/i/150417102525799789.png.html" title="Problem PSoC">Lien vers mon image</a>

         

      Can you help me please ? I send you the code too.

         

       <a href="http://www.casimages.com/i/150417102706438332.png.html" title="code">Lien vers mon image</a>

         

       

         

      Thank you.

        • 1. Re: Problem PWM signal
          jrme.laporte

           Sorry, there is a little mistake with my first post.

             

          http://www.casimages.com/i/150417102706438332.png.html

          • 2. Re: Problem PWM signal
            user_1377889

            Welcome in the forum, Jerome!

               

            To see what is going wrong we need some more information: Can you post your complete project, so that we all can have a look at all of your settings? To do so, use for PSoC 3,4 and 5
            Creator->File->Create Workspace Bundle (minimal)
            and attach the resulting file.
             

               

            for PSoC1 use the function "Archive Project"

               

            What target are you referring to? PSoC1, 3, 4 or 5? What board do you use custom pcb? Kit? Which one??

               



            Bob
             

            • 3. Re: Problem PWM signal
              jrme.laporte

               Thank you for your answer. 

                 

              I send you my project. I don't know what kind of card is it because this is a card which has been modified by the school. 

                 

              But i think that the problem is not very complicated !

                 

              http://www.casimages.com/i/150417111745467683.jpg.html

              • 4. Re: Problem PWM signal
                user_1377889

                The attached .zip file has an error, please re-try to create and post. (Verify you can open the zip with windows explorer)

                   

                 

                   

                Bob

                • 5. Re: Problem PWM signal
                  user_1377889

                  So some of the questions are already answered:

                     

                  It is a PSoC1, custom board made by telecom.

                     

                   

                     

                  Bob

                  • 6. Re: Problem PWM signal
                    jrme.laporte

                     Strange because i can open it !

                    • 7. Re: Problem PWM signal
                      user_1377889

                      Are you monitoring Port0_0 or Port0_6?

                         

                      You write the pulsewidth first in line 29, then later you change it. That will produce a lot of glitches. Consider to have the result of the ADC as unsigned.

                         

                      Read in datasheet the side-effects for changing the compare-value while counter is running.

                         

                      A very proof concept would be to wait for counter overflow (using an interrupt), Stop the PWM, write new compare-value and restart PWM again. Interrupts in PSoC1 are not quite easy to handle, so if you are really controlling a drone you might need it.

                         

                       

                         

                      Bob

                      • 8. Re: Problem PWM signal
                        user_1377889

                        Strange, I could open your file using 7zip, but your Designer should have used the windows zip...

                           

                        Bob

                        • 9. Re: Problem PWM signal
                          jrme.laporte

                            I don't really use port0_0 and port0_6, you're right. I think it doesn't matter.

                             
                              In line 29, I write the pulsewidth because it changes every time (with the potentiometer). And if the duty cycle is too low, I want to put a minimum value. But I understand what you said.   
                             
                                  
                             
                              I start the counter at the beginning of my project with " PWM8_1_Start(); " but I didn't stop it , especially with " PWM8_1_Stop();  ".   
                             
                                  
                             
                              And I think this is the problem. I don't really see how can i put it in my code. I'm a little bit confused about this timer.   
                          • 10. Re: Problem PWM signal
                            user_1377889

                            You write multiple times in one cycle to the pulsewidth. This you should avoid!!!

                               

                            You write in line 29         PWM8_1_WritePulseWidth(value);
                            and in lines 33 and 37. a corrected value

                               

                            It would be better to first calculate the new value you want to write and write that to your pulsewidth. When you remember the last value written you may only write changes. Much room for "Thinking PSoC"

                               

                            Try to set up a interrupt handler (see #pragma and modify the file Boot.tpl) fetching the terminal count of the PWM. There you may update the pulsewidth with a pre-calculated value. Do not read the ADC in the interrupt handler, that will take too long. Instead set a flag which you poll in your main-loop, When set, read ADC, calculate the new value to set and  reset that flag.

                               

                             

                               

                            Happy coding

                               

                            Bob

                            • 11. Re: Problem PWM signal
                              jrme.laporte

                               Ok ! Thank you so much.

                                 

                              I will try to resolve it. I find something interesting in my school's documents. What you said before, is it something like that ?

                              • 12. Re: Problem PWM signal
                                user_1377889

                                I just see that you have configuration warnings for the ADC: Set both clocks (for analog and digital parts of ADC) to VC2 (or whatever you like to have..

                                   

                                Your document shows a timer capture interrupt and you will use a PWM terminal count interrupt, principially these have the same approach.

                                   

                                 

                                   

                                Bob

                                • 13. Re: Problem PWM signal
                                  user_14586677

                                  If you set up an interrupt handler you can route your PWM Tc to a buffer and set

                                     

                                  the buffer to ISR on rising edge of buffer 1.

                                     

                                   

                                     

                                   

                                     

                                   

                                     

                                  Make sure in build settings you have interrupt generation checked -

                                     

                                   

                                     

                                   

                                     

                                   

                                     

                                  Regards, Dana.

                                  • 14. Re: Problem PWM signal
                                    user_14586677

                                    The PGA prevents yopu from having rail to rail measurement capability with the

                                       

                                    A/D.

                                       

                                     

                                       

                                    So delete PGA if you need R-R and set its + input to Port_2_1.

                                       

                                     

                                       

                                    In either case set your global properties to

                                       

                                     

                                       

                                       

                                     

                                       

                                    Specifically Op-Amp bias and A-Buff_Power to high, these also effect CMR.

                                       

                                     

                                       

                                    Regards, Dana.

                                    1 2 Previous Next