PWM GENERATION with varraying frequency and varraying duty cycle

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

cross mob
clinton
Level 2
Level 2
First solution authored 5 questions asked 25 sign-ins

Hello  @AliAsgar  I want to generate a pwm wave form with varrying frequency and varrying duty cyclei made nesseccary changes for that can you please let me know what silly mistake i making  
while i am varrying brightness control the frequency is varrying in oscliscope but when i change contrast control its not changing why its happen like that

I taken period =2016000 for 100hz and multiplying that
I also have bit confusion one how to take apropirate value in period for correct frequency and what value we have to take for the correct duty cycle thank you

0 Likes
1 Solution
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi,

I am not clear with your issue in the first paragraph. Could you share your firmware with me, and along with explain in your issue in complete detail?

Calculating frequency and duty cycle for complex GPIOs (considering GpioComplexApp firmware example as reference):

Check the timerMode of the complex configuration structure, CY_U3P_GPIO_TIMER_HIGH_FREQ in the case of the firmware. TIMER_HIGH_FREQ corresponds to GPIO fast clock. From GpioClock configuration structure, it can be seen that Fast GPIO clock = SYS_CLK / 2 = 403 / 2 = 201.5MHz.
Time period of clock of frequency 201.5MHz is 4.96ns.

Consider frequency to be set as 1KHz, no. of fast gpio clock time periods needed to get a time period for 1KHz clock = 1ms/4.96ns = 201500.

Hence for frequency of 1KHz, the period to be set in the complex configuration structure is 201500-1.
For the required duty cycle, the threshold in the complex configuration structure should be set as [(DC%/100)*201500]-1. For 50% DC, threshold will be : 100750.

Note: Check the SYS_CLK for your application and firmware settings.

Best Regards,
AliAsgar

View solution in original post

0 Likes
11 Replies
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi,

I am not clear with your issue in the first paragraph. Could you share your firmware with me, and along with explain in your issue in complete detail?

Calculating frequency and duty cycle for complex GPIOs (considering GpioComplexApp firmware example as reference):

Check the timerMode of the complex configuration structure, CY_U3P_GPIO_TIMER_HIGH_FREQ in the case of the firmware. TIMER_HIGH_FREQ corresponds to GPIO fast clock. From GpioClock configuration structure, it can be seen that Fast GPIO clock = SYS_CLK / 2 = 403 / 2 = 201.5MHz.
Time period of clock of frequency 201.5MHz is 4.96ns.

Consider frequency to be set as 1KHz, no. of fast gpio clock time periods needed to get a time period for 1KHz clock = 1ms/4.96ns = 201500.

Hence for frequency of 1KHz, the period to be set in the complex configuration structure is 201500-1.
For the required duty cycle, the threshold in the complex configuration structure should be set as [(DC%/100)*201500]-1. For 50% DC, threshold will be : 100750.

Note: Check the SYS_CLK for your application and firmware settings.

Best Regards,
AliAsgar

0 Likes
lock attach
Attachments are accessible only for community members.
clinton
Level 2
Level 2
First solution authored 5 questions asked 25 sign-ins

HI @AliAsgar  

i want to generae pwm wave with variable frequency and duty cycle.  with help of proccessing unit controls so i taken two controls for brightness and contrast for that so while using brightness control frequency is varrying but when it comes with contrast control the duty cycle not varraying can u guide me if i making any calculations mistaskes i have to varry frequency from 100 - 1000hz and duty cycle 1 - 100 % can u get my question  i think so

check main file in appthread api i am updating every time if i remove appthread and add it to the setuCB it wil work 

 

Best regards

clinton

0 Likes

Hi @AliAsgar  

I decleared both as global variable threshold and frequency eventhough when i changing the threshold debug prints showing zero on both

 

0 Likes
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi,

It is not recommended to use debugPrints or blocking API calls in the a callback function.

Please get the value of brightness/contrast change in a global variable and modify the ComplexConfig structure in the Thread Super loop (for (;;)). Enable debugPrints in the for loop. Print the brightness and contrast changed value if they are changing because of control requests. Print the period and threshold whenever there is a change. 

Get the return status of the ComplexUpdate API and print the status if the return status is not success.

Please share the debugPrints with us.

Best Regards,
AliAsgar

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

I Am assuming you gone through the main file 
Or else see that file and get me back @AliAsgar  i am not creating any thread so no need infinite loop for that means supper loop

Best Regards

clinton

0 Likes
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi Clinton,

Please confirm the value of gl16SetControl under CX3_USB_UVC_SET_CUR_REQ for (wIndex == 0x200) && (wValue == 0x300).

I see that as you explained period is varying properly, however, threshold is not.

From you firmware, I see that threshold = (period) * (gldutycycle/100). Hence, the only way threshold can be zero is if gldutycycle is zero. Please investigate on this variable.

Best Regards,
AliAsgar

I Found out the issue @AliAsgar  Thanks for the reply 
The problem is with gldutycycle varaible is 1 byte . its multiplying with 4 byte variable so  i changed that varaible to 4 byte know its perfectly varraying however one doubt on it 
when i Suddenly move the brightness control form 1 to 3 or 4 or 5 ... in dso the pwm wave is wiping out can i know the reason is there any latency behind this  after i probe again its showiing 


Best Regards 
clinton

 

0 Likes
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi Clinton,

I was unable to understand the issue you mentioned in the last line of the paragraph ("the pwm wave is wiping out"). Could you please explain this, maybe with the help of DSO snippets.

Best Regards,
AliAsgar

0 Likes

Hi @AliAsgar  

i didnt taken the dso snippets 
the issue is when we incerease the  brightness control frquency going blank its jumping from 100hz to 12khz like that 

CyU3PGpioComplexUpdate(); is there any method to update the new value othre than using this api

Best Regards

clinton

0 Likes
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi Clinton,

We do not have any other better alternatives to GpioComplexUpdate API. It is a simple API for updating duty cycle and frequency.

I tried changing frequency using ComplexUpdate and it worked without any issues.

We can support you better if you could explain your issue using a timing diagram.

Best Regards,
AliAsgar

0 Likes