PWM Fixed Function

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

cross mob
lock attach
Attachments are accessible only for community members.
shil_1288831
Level 3
Level 3
25 sign-ins 25 replies posted 10 sign-ins

Hi,

Due to lack of UDB resources, I am trying to use the fixed function implementation of PWM.
I am using 16bit resolution.
Period of 1ms (9) and CMP value of 5.
The CMP type is "less" and the dead band is disabled.
The kill value is 1 and the reset value is 0.

As mentioned in the datasheet, the PWM output is 0.
I connected scope to the TC output and I saw duty cycle of 100us and period of 1ms (attached pic).
If I am changing the period value in the Top Design, The period in the output is changed but I can't control the duty cycle.
I also tried to use the function PWM_setValue() but it didn't change anything.
What am I doing wrong? How can I control the duty cycle of FF PWM?
(If I am using UDB implementation it works).

Thanks!

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,
I tried with CY8CKIT-059.
With the attached sample, when you start the program
program name and a prompt "> " will be shown in a serial terminal program.

001-TeraTerm.JPG

Since the default duty (or compare) is set to 127, about 50% duty wave is generated.

PWM_DUTY_127.JPG

When I entered "30" at the prompt

PWM_DUTY_30.JPG

And whan I entered 200 at the prompt

PWM_DUTY_200.JPG

Schematic

002-schematic.JPG

Pins

003-Pins.JPG

main.c

#include "project.h"
#include "stdio.h"
#include "tty_utils.h"

void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    tty_init() ;
    
    splash("Fixed PWM duty test") ;
    
    PWM_Start() ;
}

void set_pwm_duty(int duty)
{
    PWM_Stop() ;
    PWM_WriteCompare(duty) ;
    PWM_Start() ;
}

int main(void)
{
    int duty = 0 ;
    
    init_hardware() ;
    
    prompt("> ") ;

    for(;;)
    {
        if (get_line()) {
            sscanf(str, "%d", &duty) ;
            set_pwm_duty(duty) ;
            prompt("> ") ;
        }
    }
}

/* [] END OF FILE */

moto

View solution in original post

0 Likes
1 Reply
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,
I tried with CY8CKIT-059.
With the attached sample, when you start the program
program name and a prompt "> " will be shown in a serial terminal program.

001-TeraTerm.JPG

Since the default duty (or compare) is set to 127, about 50% duty wave is generated.

PWM_DUTY_127.JPG

When I entered "30" at the prompt

PWM_DUTY_30.JPG

And whan I entered 200 at the prompt

PWM_DUTY_200.JPG

Schematic

002-schematic.JPG

Pins

003-Pins.JPG

main.c

#include "project.h"
#include "stdio.h"
#include "tty_utils.h"

void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    tty_init() ;
    
    splash("Fixed PWM duty test") ;
    
    PWM_Start() ;
}

void set_pwm_duty(int duty)
{
    PWM_Stop() ;
    PWM_WriteCompare(duty) ;
    PWM_Start() ;
}

int main(void)
{
    int duty = 0 ;
    
    init_hardware() ;
    
    prompt("> ") ;

    for(;;)
    {
        if (get_line()) {
            sscanf(str, "%d", &duty) ;
            set_pwm_duty(duty) ;
            prompt("> ") ;
        }
    }
}

/* [] END OF FILE */

moto

0 Likes