- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Operating environment:
Win10
ModusToolBox Version: 2.4.0
Eclipse Build ID: 2460
Evk: CY8CKIT-062-WIFI-BT
mtb-hal-cat1 release-v2.0.1
When I use cyhal_pwm_set_duty_cycle to set the duty equal to 0% or 100%, it seems the output is not correct!
result = cyhal_pwm_set_duty_cycle(&pwm_obj, 0.0f, 10000); ==> Then PWM output is 100%(keep high level output)
result = cyhal_pwm_set_duty_cycle(&pwm_obj, 100.0f, 10000); ==> Then PWM output is 99.98%
I wonder does there is any bugs in the function library cyhal_pwm_set_duty_cycle() & cyhal_pwm_set_period_and_compare().
Below is my sample code:
#include "cy_pdl.h"
#include "cyhal.h"
#include "cybsp.h"
float fCompareValue = 0.0f;
int main(void)
{
cy_rslt_t result;
cyhal_pwm_t pwm_obj;
/* Initialize the device and board peripherals */
result = cybsp_init() ;
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
__enable_irq();
cyhal_gpio_init(CYBSP_LED9, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_OFF);
// Initialize PWM on the supplied pin and assign a new clock
result = cyhal_pwm_init(&pwm_obj, CYBSP_LED8, NULL);
// Set a duty cycle of 100% and frequency of 10KHz
result = cyhal_pwm_set_duty_cycle(&pwm_obj, fCompareValue, 10000);
// Start the PWM output
result = cyhal_pwm_start(&pwm_obj);
for (;;)
{
if(fCompareValue <= 100.0f)
{
result = cyhal_pwm_set_duty_cycle(&pwm_obj, fCompareValue, 10000);
cyhal_gpio_toggle(CYBSP_LED9);
Cy_SysLib_Delay(250);
fCompareValue += 10.0f;
}
}
}
Actually output waveform:
Solved! Go to Solution.
- Labels:
-
ModusToolbox PSoC 6 SDK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I modify part of the code in cyhal_pwm.c, as shown on the right side of the figure below:
Re-build & Program, the output waveform is fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I modify part of the code in cyhal_pwm.c, as shown on the right side of the figure below:
Re-build & Program, the output waveform is fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @rsiigod
Sorry for the delay in replying to this thread. This thread was missed.
The code for PWM is correct.
The CY8CKIT-062-WIFI-BT contains CY8C6247BZI-D54 device. If you see the device datasheet for this you will observe that the IMO (Internal Main Oscillator) which has an accuracy of +/-2 percent. This is also mentioned in the device datasheet.
This is why you are observing a slight deviation in the PWM expected output.
Best Regards
Ekta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Ekta_N
Good day~
There should still be problems with the underlying code, independent of oscillator accuracy.
Because 0% of the output is wrong, not just inaccurate.
You can view the following figure, when the output is set to 0%, but the actual output is about 100%....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @rsiigod
Thanks for pointing to this. I have discussed this issue with our internal team and will create an internal ticket to get this fixed.
Thanks
Ekta