Problem PWM signal

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 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.

0 Likes
15 Replies
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

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

   

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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
 

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

 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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

 

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

So some of the questions are already answered:

   

It is a PSoC1, custom board made by telecom.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

 Strange because i can open it !

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

Bob

0 Likes
Anonymous
Not applicable

  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.   
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

 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 ?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

If you do an ISR don't forget to declare any variables used as volatile -

   

 

   

    

   

          

   

http://www.barrgroup.com/Embedded-Systems/How-To/C-Volatile-Keyword    Volatile

   

   

 

   

Regards, Dana.

0 Likes