You are here

PSoC 5LP and PSFB | Cypress Semiconductor

PSoC 5LP and PSFB

Summary: 41 Replies, Latest post by odissey1 on 30 Nov 2016 09:50 PM PST
Verified Answers: 3
Last post
Log in to post new comments.
vijayr.acns_1628096's picture
User
30 posts

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-microcon....

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.

user_1377889's picture
User
9583 posts

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

vijayr.acns_1628096's picture
User
30 posts

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.

vijayr.acns_1628096's picture
User
30 posts

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?

vijayr.acns_1628096's picture
User
30 posts

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?

user_342122993's picture
User
579 posts

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.

vijayr.acns_1628096's picture
User
30 posts

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.

user_1377889's picture
User
9583 posts

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

vijayr.acns_1628096's picture
User
30 posts

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.

user_1377889's picture
User
9583 posts

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

vijayr.acns_1628096's picture
User
30 posts

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.

Log in to post new comments.